From 4bdab70a66bf050ae72dc5960462adcb717b3f26 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Wed, 27 Jan 2010 12:06:53 -0500 Subject: [PATCH] `be html` links (') else: - comment_entries.append('
') + comment_entries.append( + '
' % comment.uuid) template_info = {'shortname': comment.id.user()} for attr in ['uuid', 'author', 'date', 'body']: value = getattr(comment, attr) if attr == 'body': + link_long_ids = False save_body = False if comment.content_type == 'text/html': - pass # no need to escape html... + link_long_ids = True elif comment.content_type.startswith('text/'): value = '
\n'+self._escape(value)+'\n
' + link_long_ids = True elif comment.content_type.startswith('image/'): save_body = True value = '' \ @@ -240,6 +244,8 @@ class HTMLGen (object): save_body = True value = '
Link to %s file.' \ % (bug.uuid, comment.uuid, comment.content_type) + if link_long_ids == True: + value = self._long_to_linked_user(value) if save_body == True: per_bug_dir = os.path.join(self.out_dir_bugs, bug.uuid) if not os.path.exists(per_bug_dir): @@ -249,9 +255,7 @@ class HTMLGen (object): '\n ForceType %s\n' \ % (comment.uuid, comment.content_type), [per_bug_dir, '.htaccess'], mode='a') - self._write_file( # TODO: long_to_linked_user() - libbe.util.id.long_to_short_text( - [self.bd], comment.body), + self._write_file(comment.body, [per_bug_dir, comment.uuid], mode='wb') else: value = self._escape(value) @@ -262,6 +266,31 @@ class HTMLGen (object): comment_entries.append('
\n') # close every remaining
%s' \ + % (p['bug'], short_id) + elif p['type'] == 'comment': + return '%s' \ + % (p['bug'], p['comment'], short_id) + raise Exception('Invalid id type %s for "%s"' + % (p['type'], long_id)) + def _write_index_file(self, bugs, title, index_header, bug_type='active'): if self.verbose: print >> self.stdout, 'Writing %s index file for %d bugs' % (bug_type, len(bugs)) diff --git a/libbe/util/id.py b/libbe/util/id.py index 4537c86..3c6c957 100644 --- a/libbe/util/id.py +++ b/libbe/util/id.py @@ -191,10 +191,14 @@ class ID (object): Related tools: * get uuids back out of the user ids: parse_user() - * scan text for user ids & convert to long user ids: + * convert a single short user id to a long user id: short_to_long_user() - * scan text for long user ids & convert to short user ids: + * convert a single long user id to a short user id: long_to_short_user() + * scan text for user ids & convert to long user ids: + short_to_long_text() + * scan text for long user ids & convert to short user ids: + long_to_short_text() Supported types: 'bugdir', 'bug', 'comment' """ @@ -277,16 +281,20 @@ def short_to_long_user(bugdirs, id): REGEXP = '#([-a-f0-9]*)(/[-a-g0-9]*)?(/[-a-g0-9]*)?#' class IDreplacer (object): - def __init__(self, bugdirs, replace_fn): + def __init__(self, bugdirs, replace_fn, wrap=True): self.bugdirs = bugdirs self.replace_fn = replace_fn + self.wrap = wrap def __call__(self, match): ids = [] for m in match.groups(): if m == None: m = '' ids.append(m) - return '#' + self.replace_fn(self.bugdirs, ''.join(ids)) + '#' + replacement = self.replace_fn(self.bugdirs, ''.join(ids)) + if self.wrap == True: + return '#%s#' % replacement + return replacement def short_to_long_text(bugdirs, text): return re.sub(REGEXP, IDreplacer(bugdirs, short_to_long_user), text) -- 2.26.2