From 74864cbce9ded7764e05647d5433fc7c9958e22a Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Tue, 20 Oct 2009 09:37:22 -0400 Subject: [PATCH] Save non-text/ comments as separate files. Inline images. --- becommands/html.py | 86 ++++++++++++++++++++++++++++++---------------- 1 file changed, 57 insertions(+), 29 deletions(-) diff --git a/becommands/html.py b/becommands/html.py index dd7ce65..81157a6 100644 --- a/becommands/html.py +++ b/becommands/html.py @@ -159,9 +159,27 @@ class HTMLGen (object): if self.verbose: print "\tCreating bug file for %s" % self.bd.bug_shortname(bug) assert hasattr(self, "out_dir_bugs"), "Must run after ._create_output_directories()" - esc = self._escape bug.load_comments(load_full=True) + comment_entries = self._generate_bug_comment_entries(bug) + filename = "%s.html" % bug.uuid + fullpath = os.path.join(self.out_dir_bugs, filename) + template_info = {'title':self.title, + 'charset':self.encoding, + 'up_link':up_link, + 'shortname':self.bd.bug_shortname(bug), + 'comment_entries':comment_entries, + 'generation_time':self.generation_time} + for attr in ['uuid', 'severity', 'status', 'assigned', 'target', + 'reporter', 'creator', 'time_string', 'summary']: + template_info[attr] = self._escape(getattr(bug, attr)) + f = codecs.open(fullpath, "w", self.encoding) + f.write(self.bug_file % template_info) + f.close() + + def _generate_bug_comment_entries(self, bug): + assert hasattr(self, "out_dir_bugs"), "Must run after ._create_output_directories()" + stack = [] comment_entries = [] for depth,comment in bug.comment_root.thread(flatten=False): @@ -178,34 +196,40 @@ class HTMLGen (object): for attr in ['uuid', 'author', 'date', 'body']: value = getattr(comment, attr) if attr == 'body': + save_body = False if comment.content_type == 'text/html': pass # no need to escape html... elif comment.content_type.startswith('text/'): - value = '
\n'+esc(value)+'\n
' + value = '
\n'+self._escape(value)+'\n
' + elif comment.content_type.startswith('image/'): + save_body = True + value = '' \ + % (bug.uuid, comment.uuid) else: - value = "TODO: linkout to %s" % comment.content_type + save_body = True + value = 'Link to %s file.' \ + % (bug.uuid, comment.uuid, comment.content_type) + if save_body == True: + per_bug_dir = os.path.join(self.out_dir_bugs, bug.uuid) + if not os.path.exists(per_bug_dir): + os.mkdir(per_bug_dir) + comment_path = os.path.join(per_bug_dir, comment.uuid) + f = codecs.open(os.path.join(per_bug_dir, '.htaccess'), + 'a', self.encoding) + f.write('\n ForceType %s\n' \ + % (comment.uuid, comment.content_type)) + f.close() + f = open(os.path.join(per_bug_dir, comment.uuid), "wb") + f.write(comment.body) + f.close else: - value = esc(value) + value = self._escape(value) template_info[attr] = value comment_entries.append(self.bug_comment_entry % template_info) while len(stack) > 0: stack.pop(-1) comment_entries.append("\n") # close every remaining