# HG changeset patch # User catherine@Elli.myhome.westell.com # Date 1222371620 14400 # Node ID d5917f02ae838dd0b1f0f828a0dd34c3a711c9e2 # Parent 7e5105efa15de8d1611226ce71a6d63678529f66 html output switched to genshi diff -r 7e5105efa15d -r d5917f02ae83 setup.py --- a/setup.py Tue Sep 23 07:43:11 2008 -0400 +++ b/setup.py Thu Sep 25 15:40:20 2008 -0400 @@ -18,7 +18,7 @@ packages=find_packages(), py_modules = ['mysqlpy','completion','sqlpyPlus','sqlpython','pexpecter'], include_package_data=True, - install_requires=['pyparsing','cmd2>=0.3.6','cx_Oracle'], + install_requires=['pyparsing','cmd2>=0.3.6','cx_Oracle','genshi'], keywords = 'client oracle database', license = 'MIT', platforms = ['any'], diff -r 7e5105efa15d -r d5917f02ae83 sqlpyPlus.py --- a/sqlpyPlus.py Tue Sep 23 07:43:11 2008 -0400 +++ b/sqlpyPlus.py Thu Sep 25 15:40:20 2008 -0400 @@ -186,7 +186,7 @@ """ } -import sys, os, re, sqlpython, cx_Oracle, pyparsing, re, completion +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: @@ -408,55 +408,64 @@ for row in self.rows] return '\n'.join(result) + xml_template = genshi.template.MarkupTemplate(''' + ''') def output_row_as_xml(self, row): result = [' <%s>\n %s\n ' % (colname.lower(), self.str_or_empty(itm), colname.lower()) for (itm, colname) in zip(row, self.colnames)] return '\n'.join(result) + ''' + xml_template = genshi.template.MarkupTemplate(""" + + + + Column Name + + + + + Value + + + + +""") +''' def output_as_xml(self): + return self.xml_template(**self.__dict__) result = ['<%s>\n%s\n' % (self.tblname, self.output_row_as_xml(row), self.tblname) for row in self.rows] return '\n'.join(result) - - html_template = """ + + html_template = genshi.template.MarkupTemplate(""" + Table Name - +
+ Value +
- Column Name + Column Name
- Value -
-""" - def output_as_html_table(self): - result = ''.join('%s' % c for c in self.colnames) - result = [' \n %s\n ' % result] - for row in self.rows: - result.append(' \n %s\n ' % - (''.join('%s' % - self.str_or_empty(itm) - for itm in row))) - result = ''' -%s -
''' % (self.tblname, '\n'.join(result)) - return result - - #TODO: use serious templating to make these user-tweakable - - def output_as_markup(self, genshi_template): - return None - #self.tblname, self.colnames, self.rows - +""") + def output_as_list(self, align): result = [] colnamelen = max(len(colname) for colname in self.colnames) + 1 @@ -488,7 +497,7 @@ result.append(','.join('"%s"' % self.str_or_empty(itm) for itm in row)) result = '\n'.join(result) elif outformat == '\\h': - result = self.output_as_html_table() + result = self.html_template.generate(**self.__dict__) elif outformat == '\\t': rows = [self.colnames] rows.extend(list(self.rows)) @@ -559,8 +568,8 @@ ^ pyparsing.Literal('\n/') ^ \ (pyparsing.Literal('\nEOF') + pyparsing.stringEnd)) \ ('terminator') + \ - pyparsing.Optional(rowlimitPattern) + \ - pyparsing.FollowedBy(pyparsing.LineEnd()) + pyparsing.Optional(rowlimitPattern) #+ \ + #pyparsing.FollowedBy(pyparsing.LineEnd()) def do_select(self, arg, bindVarsIn=None, override_terminator=None): """Fetch rows from a table.