/usr/share/pyshared/wikitable/table.py is in trac-wikitablemacro 0.7785-1.1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | from pkg_resources import resource_filename
from StringIO import StringIO
from trac.core import implements
from trac.web.chrome import ITemplateProvider, add_stylesheet
from trac.wiki.macros import WikiMacroBase
from trac.util.html import Markup
class SQLTable(WikiMacroBase):
"""Draw a table from a SQL query in a wiki page.
Examples:
{{{
{{{
#!SQLTable
SELECT count(id) as 'Number of Tickets'
FROM ticket
}}}
}}}
"""
implements(ITemplateProvider)
# ITemplateProvider methods
def get_templates_dirs(self):
return []
def get_htdocs_dirs(self):
return [('wikitable', resource_filename(__name__, 'htdocs'))]
# Render macro
def render_macro(self, req, name, content):
db = self.env.get_db_cnx()
cursor = db.cursor()
cursor.execute(content)
out = StringIO()
print >>out, "<table class='listing wikitable'>"
print >>out, " <thead>"
print >>out, " <tr>"
for desc in cursor.description:
print >>out, "<th>%s</th>" % desc[0]
print >>out, " </tr>"
print >>out, " </thead>"
print >>out, " <tbody>"
for idx, row in enumerate(cursor):
css_class = (idx % 2 == 0) and 'odd' or 'even'
print >>out, " <tr class='%s'>" % css_class
for col in row:
print >>out, "<td>%s</td>" % col
print >>out, " </tr>"
print >>out, " </tbody>"
print >>out, "</table>"
add_stylesheet(req, 'wikitable/css/wikitable.css')
return Markup(out.getvalue())
|