189
|
1 import genshi.template
|
|
2
|
|
3 # To make more output formats available to sqlpython, just edit this
|
|
4 # file, or place a copy in your local directory and edit that.
|
|
5
|
|
6 output_templates = {
|
|
7
|
|
8 '\\x': genshi.template.NewTextTemplate("""
|
|
9 <xml>
|
|
10 <${tblname}_resultset>{% for row in rows %}
|
|
11 <$tblname>{% for (colname, itm) in zip(colnames, row) %}
|
|
12 <${colname.lower()}>$itm</${colname.lower()}>{% end %}
|
|
13 </$tblname>{% end %}
|
|
14 </${tblname}_resultset>
|
|
15 </xml>"""),
|
|
16
|
266
|
17 '\\j': genshi.template.NewTextTemplate("""
|
|
18 {"${tblname}_resultset: [{% for row in rows %}
|
|
19 "${tblname}": {{% for (colname, itm) in zip(colnames, row) %}
|
|
20 "${colname.lower()}": "${itm}",{% end %} },
|
|
21 {% end %}]
|
|
22 }"""),
|
|
23
|
189
|
24 '\\h': genshi.template.MarkupTemplate("""
|
|
25 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
|
26 <html xmlns:py="http://genshi.edgewall.org/" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
|
27 <head>
|
|
28 <title py:content="tblname">Table Name</title>
|
|
29 <meta http-equiv="content-type" content="text/html;charset=utf-8" />
|
|
30 </head>
|
|
31 <body>
|
|
32 <table py:attrs="{'id':tblname,
|
|
33 'summary':'Result set from query on table ' + tblname}">
|
|
34 <tr>
|
|
35 <th py:for="colname in colnames"
|
|
36 py:attrs="{'id':'header_' + colname.lower()}">
|
|
37 <span py:replace="colname.lower()">Column Name</span>
|
|
38 </th>
|
|
39 </tr>
|
|
40 <tr py:for="row in rows">
|
|
41 <td py:for="(colname, itm) in zip(colnames, row)" py:attrs="{'headers':'header_' + colname.lower()}">
|
|
42 <span py:replace="str(itm)">Value</span>
|
|
43 </td>
|
|
44 </tr>
|
|
45 </table>
|
|
46 </body>
|
|
47 </html>"""),
|
|
48
|
|
49 '\\g': genshi.template.NewTextTemplate("""
|
|
50 {% for (rowNum, row) in enumerate(rows) %}
|
|
51 **** Row: ${rowNum + 1}
|
|
52 {% for (colname, itm) in zip(colnames, row) %}$colname: $itm
|
|
53 {% end %}{% end %}"""),
|
|
54
|
|
55 '\\G': genshi.template.NewTextTemplate("""
|
|
56 {% for (rowNum, row) in enumerate(rows) %}
|
|
57 **** Row: ${rowNum + 1}
|
|
58 {% for (colname, itm) in zip(colnames, row) %}${colname.ljust(colnamelen)}: $itm
|
|
59 {% end %}{% end %}"""),
|
|
60
|
|
61 '\\i': genshi.template.NewTextTemplate("""{% for (rowNum, row) in enumerate(rows) %}
|
|
62 INSERT INTO $tblname (${', '.join(colnames)}) VALUES (${', '.join(f % r for (r,f) in zip(row, formatters))});{% end %}"""),
|
|
63
|
|
64 '\\c': genshi.template.NewTextTemplate("""
|
|
65 ${','.join(colnames)}{% for row in rows %}
|
|
66 ${','.join('"%s"' % val for val in row)}{% end %}"""),
|
|
67
|
|
68 '\\C': genshi.template.NewTextTemplate("""
|
|
69 {% for row in rows %}${','.join('"%s"' % val for val in row)}{% end %}""")
|
|
70
|
|
71 }
|
|
72
|
|
73 output_templates['\\s'] = output_templates['\\c']
|
|
74 output_templates['\\S'] = output_templates['\\C']
|