From: W. Trevor King Date: Mon, 3 Sep 2012 20:37:17 +0000 (-0400) Subject: command:html: add --strip-email option. X-Git-Tag: 1.1.0~82 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=d4abd0e2cdf0dc5dead4adb863edd3adce48f1d7;p=be.git command:html: add --strip-email option. --- diff --git a/libbe/command/html.py b/libbe/command/html.py index 5325183..5bfa411 100644 --- a/libbe/command/html.py +++ b/libbe/command/html.py @@ -19,6 +19,7 @@ # Bugs Everywhere. If not, see . import codecs +import email.utils import htmlentitydefs import itertools import os @@ -52,7 +53,7 @@ class ServerApp (libbe.util.wsgi.WSGI_AppObject, def __init__(self, bugdirs={}, template_dir=None, title='Site Title', header='Header', index_file='', min_id_length=-1, - generation_time=None, **kwargs): + strip_email=False, generation_time=None, **kwargs): super(ServerApp, self).__init__( urls=[ (r'^{}$'.format(index_file), self.index), @@ -65,6 +66,7 @@ class ServerApp (libbe.util.wsgi.WSGI_AppObject, self.header = header self._index_file = index_file self.min_id_length = min_id_length + self.strip_email = strip_email self.generation_time = generation_time self._refresh = 0 self.http_user_error = 418 @@ -164,6 +166,7 @@ class ServerApp (libbe.util.wsgi.WSGI_AppObject, 'comment_dir': self._truncated_comment_id, 'format_body': self._format_comment_body, 'div_close': _DivCloser(), + 'strip_email': self._strip_email, 'generation_time': self._generation_time(), } template = self.template.get_template('bug.html') @@ -310,6 +313,14 @@ class ServerApp (libbe.util.wsgi.WSGI_AppObject, return '' return xml.sax.saxutils.escape(string) + def _strip_email(self, string): + if self.strip_email: + name,address = email.utils.parseaddr(string) + if name: + return name + return address + return string + def _load_templates(self, template_dir=None): if template_dir is not None: template_dir = os.path.abspath(os.path.expanduser(template_dir)) @@ -659,11 +670,11 @@ div.root.comment { Severity : {{ bug.severity|e }} Assigned : - {{ (bug.assigned or '')|e }} + {{ strip_email(bug.assigned or '')|e }} Reporter : - {{ (bug.reporter or '')|e }} + {{ strip_email(bug.reporter or '')|e }} Creator : - {{ (bug.creator or '')|e }} + {{ strip_email(bug.creator or '')|e }} Created : {{ (bug.time_string or '')|e }} Summary : @@ -682,7 +693,8 @@ div.root.comment { {% endif %} {{ comment_entry.render({ 'depth':depth, 'bug': bug, 'comment':comment, 'comment_dir':comment_dir, - 'format_body': format_body, 'div_close': div_close}) }} + 'format_body': format_body, 'div_close': div_close, + 'strip_email': strip_email}) }} {{ div_close(depth) }} {% endfor %} {% if comments[-1][0] > 0 %} @@ -709,7 +721,7 @@ div.root.comment { --------- Comment ---------
ID: {{ comment.uuid }}
Short name: {{ comment.id.user() }}
- From: {{ (comment.author or '')|e }}
+ From: {{ strip_email(comment.author or '')|e }}
Date: {{ (comment.date or '')|e }}

{{ format_body(bug, comment) }} @@ -799,6 +811,8 @@ class HTML (libbe.util.wsgi.ServerCommand): arg=libbe.command.Argument( name='min-id-length', metavar='INT', default=-1, type='int')), + libbe.command.Option(name='strip-email', + help='Strip email addresses from person fields.'), libbe.command.Option(name='export-html', short_name='e', help='Export all HTML pages and exit.'), libbe.command.Option(name='output', short_name='o', @@ -843,6 +857,7 @@ class HTML (libbe.util.wsgi.ServerCommand): header=kwargs['index-header'], index_file=index_file, min_id_length=kwargs['min-id-length'], + strip_email=kwargs['strip-email'], generation_time=generation_time) def _long_help(self):