Mercurial > sqlpython
changeset 149:3b1e25cc0e38
html output now valid xhtml 1.0 strict
author | catherine@dellzilla |
---|---|
date | Fri, 26 Sep 2008 10:33:37 -0400 |
parents | fcb19853cd94 |
children | b00a020b81c6 |
files | mysqlpy.py output_templates.py setup.py sqlpyPlus.py sqlpython.py |
diffstat | 5 files changed, 61 insertions(+), 59 deletions(-) [+] |
line wrap: on
line diff
--- a/mysqlpy.py Thu Sep 25 16:37:16 2008 -0400 +++ b/mysqlpy.py Fri Sep 26 10:33:37 2008 -0400 @@ -1,5 +1,5 @@ #!/usr/bin/python -# MySqlPy V1.4.8 +# MySqlPy V1.4.9 # Author: Luca.Canali@cern.ch # # @@ -13,9 +13,9 @@ class mysqlpy(sqlpyPlus): ''' -MySqlPy V1.4.8 - 'sqlplus in python' +MySqlPy V1.4.9 - 'sqlplus in python' Author: Luca.Canali@cern.ch -Rev: 1.4.8, 04-Sep-08 +Rev: 1.4.9, 26-Sep-08 Companion of SqlPython, a python module that reproduces Oracle's command line within python and sqlpyPlus. Major contributions by Catherine Devlin, http://catherinedevlin.blogspot.com
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/output_templates.py Fri Sep 26 10:33:37 2008 -0400 @@ -0,0 +1,47 @@ +import genshi.template + +xml_template = genshi.template.NewTextTemplate(""" +<xml> + <${tblname}_resultset>{% for row in rows %} + <$tblname>{% for (colname, itm) in zip(colnames, row) %} + <${colname.lower()}>$itm</${colname.lower()}>{% end %} + </$tblname>{% end %} + </${tblname}_resultset> +</xml>""") + +html_template = genshi.template.MarkupTemplate(""" +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns:py="http://genshi.edgewall.org/" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> + <head> + <title py:content="tblname">Table Name</title> + <meta http-equiv="content-type" content="text/html;charset=utf-8" /> + </head> + <body> + <table py:attrs="{'id':tblname, + 'summary':'Result set from query on table ' + tblname}"> + <tr> + <th py:for="colname in colnames" + py:attrs="{'id':'header_' + colname.lower()}"> + <span py:replace="colname.lower()">Column Name</span> + </th> + </tr> + <tr py:for="(colname, row) in zip(colnames, rows)"> + <td py:for="itm in row" py:attrs="{'headers':'header_' + colname.lower()}"> + <span py:replace="str(itm)">Value</span> + </td> + </tr> + </table> + </body> +</html>""") + +list_template = genshi.template.NewTextTemplate(""" +{% for (rowNum, row) in enumerate(rows) %} +**** Row: ${rowNum + 1} +{% for (colname, itm) in zip(colnames, row) %}$colname: $itm +{% end %}{% end %}""") + +aligned_list_template = genshi.template.NewTextTemplate(""" +{% for (rowNum, row) in enumerate(rows) %} +**** Row: ${rowNum + 1} +{% for (colname, itm) in zip(colnames, row) %}${colname.ljust(colnamelen)}: $itm +{% end %}{% end %}""")
--- a/setup.py Thu Sep 25 16:37:16 2008 -0400 +++ b/setup.py Fri Sep 26 10:33:37 2008 -0400 @@ -9,14 +9,14 @@ Operating System :: OS Independent""".splitlines() setup(name="sqlpython", - version="1.4.8", + version="1.4.9", description="Command-line interface to Oracle", long_description="Customizable alternative to Oracle's SQL*PLUS command-line interface", author="Luca Canali", author_email="luca.canali@cern.ch", url="https://twiki.cern.ch/twiki/bin/view/PSSGroup/SqlPython", packages=find_packages(), - py_modules = ['mysqlpy','completion','sqlpyPlus','sqlpython','pexpecter'], + py_modules = ['mysqlpy','completion','sqlpyPlus','sqlpython','pexpecter','output_templates'], include_package_data=True, install_requires=['pyparsing','cmd2>=0.3.6','cx_Oracle','genshi'], keywords = 'client oracle database',
--- a/sqlpyPlus.py Thu Sep 25 16:37:16 2008 -0400 +++ b/sqlpyPlus.py Fri Sep 26 10:33:37 2008 -0400 @@ -23,7 +23,9 @@ - catherinedevlin.blogspot.com May 31, 2006 """ -# note in cmd.cmd about supporting emacs commands? +import sys, os, re, sqlpython, cx_Oracle, pyparsing, re, completion +from cmd2 import Cmd, make_option, options, Statekeeper +from output_templates import * descQueries = { 'TABLE': (""" @@ -186,9 +188,6 @@ """ } -import sys, os, re, sqlpython, cx_Oracle, pyparsing, re, completion, genshi -from cmd2 import Cmd, make_option, options, Statekeeper - if float(sys.version[:3]) < 2.3: def enumerate(lst): return zip(range(len(lst)), lst) @@ -407,50 +406,6 @@ (self.tblname, ','.join(self.colnames), formatRow(row)) for row in self.rows] return '\n'.join(result) - - xml_template = genshi.template.NewTextTemplate(""" -<xml> - <${tblname}_resultset>{% for row in rows %} - <$tblname>{% for (colname, itm) in zip(colnames, row) %} - <${colname.lower()}>$itm</${colname.lower()}>{% end %} - </$tblname>{% end %} - </${tblname}_resultset> -</xml>""") - - html_template = genshi.template.MarkupTemplate(""" -<html xmlns:py="http://genshi.edgewall.org/"> - <head> - <title py:content="tblname">Table Name</title> - </head> - <body> - <table py:attrs="{'id':tblname, - 'summary':'Result set from query on table ' + tblname}"> - <tr> - <th py:for="colname in colnames" - py:attrs="{'id':'header_' + colname.lower()}"> - <span py:replace="colname.lower()">Column Name</span> - </th> - </tr> - <tr py:for="(colname, row) in zip(colnames, rows)"> - <td py:for="itm in row" py:attrs="{'headers':'header_' + colname.lower()}"> - <span py:replace="str(itm)">Value</span> - </td> - </tr> - </table> - </body> -</html>""") - - list_template = genshi.template.NewTextTemplate(""" -{% for (rowNum, row) in enumerate(rows) %} -**** Row: ${rowNum + 1} -{% for (colname, itm) in zip(colnames, row) %}$colname: $itm -{% end %}{% end %}""") - - aligned_list_template = genshi.template.NewTextTemplate(""" -{% for (rowNum, row) in enumerate(rows) %} -**** Row: ${rowNum + 1} -{% for (colname, itm) in zip(colnames, row) %}${colname.ljust(colnamelen)}: $itm -{% end %}{% end %}""") tableNameFinder = re.compile(r'from\s+([\w$#_"]+)', re.IGNORECASE | re.MULTILINE | re.DOTALL) def output(self, outformat, rowlimit): @@ -459,12 +414,12 @@ if outformat == '\\i': result = self.output_as_insert_statements() elif outformat == '\\x': - result = self.xml_template.generate(**self.__dict__) + result = xml_template.generate(**self.__dict__) elif outformat == '\\g': - result = self.list_template.generate(**self.__dict__) + result = list_template.generate(**self.__dict__) elif outformat == '\\G': self.colnamelen = max(len(colname) for colname in self.colnames) - result = self.aligned_list_template.generate(**self.__dict__) + result = aligned_list_template.generate(**self.__dict__) elif outformat in ('\\s', '\\S', '\\c', '\\C'): #csv result = [] if outformat in ('\\s', '\\c'): @@ -473,7 +428,7 @@ result.append(','.join('"%s"' % self.str_or_empty(itm) for itm in row)) result = '\n'.join(result) elif outformat == '\\h': - result = self.html_template.generate(**self.__dict__) + result = html_template.generate(**self.__dict__) elif outformat == '\\t': # transposed rows = [self.colnames] rows.extend(list(self.rows)) @@ -959,7 +914,7 @@ def do_cat(self, arg): '''cat TABLENAME --> SELECT * FROM equivalent''' - targets = arg.split() + targets = arg.strip().split() for target in targets: self.do_select('* from %s' % target)