Skip to content

Commit

Permalink
Adding a CSV option for output.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrjbq7 committed Jun 1, 2010
1 parent d25036f commit 9e7a293
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
8 changes: 8 additions & 0 deletions tracsql/templates/sql.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ <h1>Query</h1>
<input type="checkbox" name="raw" />Raw Output
</py:otherwise>
</py:choose>
<py:choose test="csv">
<py:when>
<input type="checkbox" name="csv" checked="checked" />CSV
</py:when>
<py:otherwise>
<input type="checkbox" name="csv" />CSV
</py:otherwise>
</py:choose>
</td><td align="right">
<py:if test="not error">
<b>${len(rows)}</b> results (<b>${took}</b> seconds)
Expand Down
20 changes: 19 additions & 1 deletion tracsql/web_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ def _process(self, req, cursor, data):

sql = req.args.get('query', '')
raw = req.args.get('raw', '')
csv = req.args.get('csv', '')

cols = rows = []
took = 0
Expand All @@ -125,13 +126,30 @@ def _process(self, req, cursor, data):
except BaseException, e:
error = e.message

if csv:
text = []
for col in cols:
text.append('%s,' % col)
text.append('\n')
for row in rows:
for cell in row:
text.append("%s," % cell)
text.append('\n')
text = str(''.join(text))
req.send_response(200)
req.send_header('Content-Type', 'text/csv')
req.send_header('Content-Length', str(len(text)))
req.end_headers()
req.write(text)
return

if not raw:

format = {
'path' : lambda x: html.A(x, href=req.href.browser(x)),
'rev' : lambda x: html.A(x, href=req.href.changeset(x)),
'ticket' : lambda x: html.A(x, href=req.href.ticket(x)),
'query' : lambda x: html.FONT(x, face="monospace"),
'query' : lambda x: html.PRE(x, style="padding: 0; margin: 0;"),
'time' : lambda x: fmt_timestamp(x),
}

Expand Down

0 comments on commit 9e7a293

Please sign in to comment.