/usr/share/pyshared/wikitable/scalar.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 | 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 SQLScalar(WikiMacroBase):
"""Output a number from a scalar (1x1) SQL query.
Examples:
{{{
{{{
#!SQLScalar
SELECT count(id) as 'Number of Tickets'
FROM ticket
}}}
}}}
"""
# Render macro
def render_macro(self, req, name, content):
db = self.env.get_db_cnx()
cursor = db.cursor()
cursor.execute(content)
value = "Unknown"
for row in cursor:
value = unicode(row[0])
break
out = StringIO()
print >>out, u"<span class='wikiscalar'>%s</span>" % value
add_stylesheet(req, 'wikitable/css/wikitable.css')
return Markup(out.getvalue())
|