From: W. Trevor King Date: Wed, 21 Oct 2009 15:03:50 +0000 (-0400) Subject: Merged Gianluca's recent `be html` work. X-Git-Tag: 1.0.0~59^2~85 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=8a89d3737b59b89cde7059969644136eb8c76c61;p=be.git Merged Gianluca's recent `be html` work. * Added --export-template and --export-template-dir * Fixed index page row colors. * Fixed --index-header Also a bit of tightening on my own: * Inspired by ._write_file, wrote ._read_file and .make_dir. * Wrapped some lines to stay under 80 characters, * Stripped trailing whitespace. --- 8a89d3737b59b89cde7059969644136eb8c76c61 diff --cc becommands/html.py index 81157a6,232aa80..d1bd625 --- a/becommands/html.py +++ b/becommands/html.py @@@ -49,13 -49,17 +49,15 @@@ def execute(args, manipulate_encodings= if len(args) > 0: raise cmdutil.UsageError, 'Too many arguments.' -- template = options.template - bd = bugdir.BugDir(from_disk=True, manipulate_encodings=manipulate_encodings) bd.load_all_bugs() html_gen = HTMLGen(bd, template=options.template, verbose=options.verbose, - title=options.title, ) - title=options.title, index_header=options.index_header ) ++ title=options.title, index_header=options.index_header) + if options.exp_template == True: - html_gen.write_default_template(options.exp_dir_template) ++ html_gen.write_default_template(options.exp_template_dir) + return html_gen.run(options.out_dir) def get_parser(): @@@ -63,15 -67,19 +65,23 @@@ parser.add_option('-o', '--output', metavar='DIR', dest='out_dir', help='Set the output path (%default)', default='./html_export') parser.add_option('-t', '--template-dir', metavar='DIR', dest='template', -- help='Use a different template, defaults to internal templates', default=None) ++ help='Use a different template, defaults to internal templates', ++ default=None) parser.add_option('--title', metavar='STRING', dest='title', help='Set the bug repository title (%default)', default='BugsEverywhere Issue Tracker') parser.add_option('--index-header', metavar='STRING', dest='index_header', help='Set the index page headers (%default)', default='BugsEverywhere Bug List') -- parser.add_option('-v', '--verbose', action='store_true', metavar='verbose', dest='verbose', - help='Verbose output, default is no', default=False) ++ parser.add_option('-v', '--verbose', action='store_true', ++ metavar='verbose', dest='verbose', + help='Verbose output, default is %default', default=False) - parser.add_option('-e', '--export-template', action='store_true', metavar='STRING', dest='exp_template', - help='Export the default template into a directory (%default)', default='./templates/default') - parser.add_option('-d', '--export-dir_template', metavar='STRING', dest='exp_dir_template', - help='Export the default template into a directory (%default)', default='./templates/default') ++ parser.add_option('-e', '--export-template', action='store_true', ++ dest='exp_template', ++ help='Export the default template and exit.', default=False) ++ parser.add_option('-d', '--export-template-dir', metavar='DIR', ++ dest='exp_template_dir', default='./default-templates/', ++ help='Set the directory for the template export (%default)') return parser longhelp=""" @@@ -129,36 -137,61 +139,33 @@@ class HTMLGen (object) else: up_link = "../index_inactive.html" self._write_bug_file(b, up_link) -- self._write_index_file(bugs_active, title=self.title, -- index_header=self.index_header, bug_type="active") -- self._write_index_file(bugs_inactive, title=self.title, -- index_header=self.index_header, bug_type="inactive") - - def write_default_template(self, out_dir): - if self.verbose: - print "Creating output directories" - self.out_dir = os.path.abspath(os.path.expanduser(out_dir)) - if not os.path.exists(self.out_dir): - try: - os.mkdir(self.out_dir) - except: - raise cmdutil.UsageError, "Cannot create output directory '%s'." % self.out_dir - if self.verbose: - print "Creating css file" - self._write_css_file() - if self.verbose: - print "Creating index_file.tpl file" - self._write_file(self.index_file, "index_file.tpl") - if self.verbose: - print "Creating index_bug_entry.tpl file" - self._write_file(self.index_bug_entry, "index_bug_entry.tpl") - if self.verbose: - print "Creating bug_file.tpl file" - self._write_file(self.bug_file, "bug_file.tpl") - if self.verbose: - print "Creating bug_comment_entry.tpl file" - self._write_file(self.bug_comment_entry, "bug_comment_entry.tpl") ++ self._write_index_file( ++ bugs_active, title=self.title, ++ index_header=self.index_header, bug_type="active") ++ self._write_index_file( ++ bugs_inactive, title=self.title, ++ index_header=self.index_header, bug_type="inactive") def _create_output_directories(self, out_dir): if self.verbose: print "Creating output directories" -- self.out_dir = os.path.abspath(os.path.expanduser(out_dir)) -- if not os.path.exists(self.out_dir): -- try: -- os.mkdir(self.out_dir) -- except: -- raise cmdutil.UsageError, "Cannot create output directory '%s'." % self.out_dir -- self.out_dir_bugs = os.path.join(self.out_dir, "bugs") -- if not os.path.exists(self.out_dir_bugs): -- os.mkdir(self.out_dir_bugs) ++ self.out_dir = self._make_dir(out_dir) ++ self.out_dir_bugs = self._make_dir( ++ os.path.join(self.out_dir, "bugs")) def _write_css_file(self): if self.verbose: print "Writing css file" -- assert hasattr(self, "out_dir"), "Must run after ._create_output_directories()" -- f = codecs.open(os.path.join(self.out_dir,"style.css"), "w", self.encoding) -- f.write(self.css_file) -- f.close() ++ assert hasattr(self, "out_dir"), \ ++ "Must run after ._create_output_directories()" ++ self._write_file(self.css_file, ++ [self.out_dir,"style.css"]) def _write_bug_file(self, bug, up_link): 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()" ++ assert hasattr(self, "out_dir_bugs"), \ ++ "Must run after ._create_output_directories()" bug.load_comments(load_full=True) comment_entries = self._generate_bug_comment_entries(bug) @@@ -173,19 -206,19 +180,20 @@@ 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() ++ self._write_file(self.bug_file % template_info, [fullpath]) def _generate_bug_comment_entries(self, bug): -- assert hasattr(self, "out_dir_bugs"), "Must run after ._create_output_directories()" ++ 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): while len(stack) > depth: -- stack.pop(-1) # pop non-parents off the stack -- comment_entries.append("\n") # close non-parent
\n") assert len(stack) == depth stack.append(comment) if depth == 0: @@@ -214,14 -247,14 +222,13 @@@ 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 ++ self._write_file( ++ '\n ForceType %s\n' \ ++ % (comment.uuid, comment.content_type), ++ [per_bug_dir, '.htaccess'], mode='a') ++ self._write_file( ++ comment.body, ++ [per_bug_dir, comment.uuid], mode='wb') else: value = self._escape(value) template_info[attr] = value @@@ -256,9 -289,9 +263,8 @@@ template_info['active_class'] = 'tab nsel' template_info['inactive_class'] = 'tab sel' -- f = codecs.open(os.path.join(self.out_dir, filename), "w", self.encoding) -- f.write(self.index_file % template_info) -- f.close() ++ self._write_file(self.index_file % template_info, ++ [self.out_dir, filename]) def _generate_index_bug_entries(self, bugs): bug_entries = [] @@@ -292,10 -325,15 +298,52 @@@ ('bug_comment_entry.tpl','bug_comment_entry')]: fullpath = os.path.join(self.template, filename) if os.path.exists(fullpath): -- f = codecs.open(fullpath, "r", self.encoding) -- setattr(self, attr, f.read()) -- f.close() - - def _write_file(self, tpl, filename ): - f = codecs.open(os.path.join(self.out_dir, filename), "w", self.encoding) - f.write(tpl) ++ setattr(self, attr, self._read_file([fullpath])) ++ ++ def _make_dir(self, dir_path): ++ dir_path = os.path.abspath(os.path.expanduser(dir_path)) ++ if not os.path.exists(dir_path): ++ try: ++ os.mkdir(dir_path) ++ except: ++ raise cmdutil.UsageError, "Cannot create output directory '%s'." % dir_path ++ return dir_path ++ ++ def _write_file(self, content, path_array, mode='w'): ++ f = codecs.open(os.path.join(*path_array), mode, self.encoding) ++ f.write(content) ++ f.close() ++ ++ def _read_file(self, path_array, mode='r'): ++ f = codecs.open(os.path.join(*path_array), mode, self.encoding) ++ content = f.read() + f.close() - ++ return content ++ ++ def write_default_template(self, out_dir): ++ if self.verbose: ++ print "Creating output directories" ++ self.out_dir = self._make_dir(out_dir) ++ if self.verbose: ++ print "Creating css file" ++ self._write_css_file() ++ if self.verbose: ++ print "Creating index_file.tpl file" ++ self._write_file(self.index_file, ++ [self.out_dir, "index_file.tpl"]) ++ if self.verbose: ++ print "Creating index_bug_entry.tpl file" ++ self._write_file(self.index_bug_entry, ++ [self.out_dir, "index_bug_entry.tpl"]) ++ if self.verbose: ++ print "Creating bug_file.tpl file" ++ self._write_file(self.bug_file, ++ [self.out_dir, "bug_file.tpl"]) ++ if self.verbose: ++ print "Creating bug_comment_entry.tpl file" ++ self._write_file(self.bug_comment_entry, ++ [self.out_dir, "bug_comment_entry.tpl"]) + def _load_default_templates(self): self.css_file = """ body { @@@ -404,9 -442,9 +452,9 @@@ /* bug detail pages */ td.bug_detail_label { text-align: right; } -- td.bug_detail { } ++ td.bug_detail { } td.bug_comment_label { text-align: right; vertical-align: top; } -- td.bug_comment { } ++ td.bug_comment { } div.comment { padding: 20px; @@@ -486,14 -524,14 +534,14 @@@ -- ++

BugsEverywhere Bug List

Back to Index

Bug: %(shortname)s

-- ++ @@@ -555,5 -593,5 +603,5 @@@ for attr in ['css_file', 'index_file', 'index_bug_entry', 'bug_file', 'bug_comment_entry']: value = getattr(self, attr) -- value = '\n'.join(value.split('\n'+' '*12)) ++ value = value.replace('\n'+' '*12, '\n') setattr(self, attr, value.strip()+'\n')
ID : %(uuid)s
Short name :