Commit cb48e15e authored by Adam D. Barratt's avatar Adam D. Barratt

point-release-mail: use debrelease.jinja for Jinja templating

Signed-off-by: 's avatarAdam D. Barratt <adam@adam-barratt.org.uk>
parent 8fb3a485
......@@ -40,14 +40,13 @@ from time import gmtime, strftime
from textwrap import fill, wrap
from six import PY2
from six.moves.configparser import ConfigParser
from jinja2 import Environment
from jinja2.filters import environmentfilter
sys.path.append(os.path.dirname(__file__) + '/../lib/')
from debrelease.projectb import ProjectB
from debrelease.proposed import QueueParser
from debrelease.security import DSAFactory
from debrelease.jinja import jinja
replacements = {
r'(?i)^SQL(.*?) ' : r'SQL\1 ',
......@@ -97,45 +96,9 @@ def process_template(template, engine):
else:
return function(template)
def capfirst(s):
if s:
return s[0].capitalize() + s[1:]
else:
return ''
def nesteddictsort(thedict, bykey, reverse=False):
return sorted(thedict.items(), key=lambda x: x[1][bykey], reverse=reverse)
@environmentfilter
def parawordwrap(environment, s, width=79, break_long_words=True, replace_whitespace=True,
wrapstring=None):
if not wrapstring:
wrapstring = environment.newline_sequence
return wrapstring.join(wrap(s, width=width, expand_tabs=False,
replace_whitespace=replace_whitespace,
break_long_words=break_long_words))
def lrjust(strings, width, pad_char=' '):
return '{}{}{}'.format(strings[0], pad_char * (width - len(strings[0]) - len(strings[1])), strings[1])
def jinja_render(template):
# Enable the use of the "do" statement in templates
env = Environment (
extensions=['jinja2.ext.do']
)
filters = {
'capfirst': capfirst,
'lrjust': lrjust,
'nesteddictsort': nesteddictsort,
'parawordwrap': parawordwrap,
'wmlescape': _escape_for_wml,
}
env.filters.update(filters)
# The template is a list of lines, but jinja expects a
# single string
t = env.from_string(''.join(template))
return t.render(tables=tables, vars=vars)
Jinja=jinja()
return Jinja.render_jinja_template(template, tables=tables, vars=vars)
def _process_template(template):
output = []
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment