Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding a CSV option for output.

  • Loading branch information...
commit 9e7a2935a1ba97f5f4120c865c1bf81adb5997fa 1 parent d25036f
@mrjbq7 authored
Showing with 27 additions and 1 deletion.
  1. +8 −0 tracsql/templates/sql.html
  2. +19 −1 tracsql/web_ui.py
View
8 tracsql/templates/sql.html
@@ -33,6 +33,14 @@
<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)
View
20 tracsql/web_ui.py
@@ -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
@@ -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),
}
Please sign in to comment.
Something went wrong with that request. Please try again.