From: Thierry Parmentelat Date: Thu, 8 Oct 2009 12:48:35 +0000 (+0000) Subject: module-diff can generate html X-Git-Tag: 4.3-rc13~21 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=dc638b7421e82456baa91184404ae2b50fcc1e77;p=build.git module-diff can generate html --- diff --git a/module-tools.py b/module-tools.py index b9d0cb74..f5efe864 100755 --- a/module-tools.py +++ b/module-tools.py @@ -231,6 +231,66 @@ class Module: if prompt(question,True): self.run(command) + #################### + # store and restitute html fragments + @staticmethod + def html_href (url,text): return '%s'%(url,text) + @staticmethod + def html_anchor (url,text): return '%s'%(url,text) + + # only the fake error module has multiple titles + def html_store_title (self, title): + if not hasattr(self,'titles'): self.titles=[] + self.titles.append(title) + def html_store_raw (self, html): + if not hasattr(self,'body'): self.body='' + self.body += html + def html_store_pre (self, text): + if not hasattr(self,'body'): self.body='' + self.body += '
' + text + '
' + + def html_dump_header(self): + now=time.strftime("%Y-%m-%d %H:%M") + print """ + + + + Pending changes in %s + + + + +

Pending changes in %s - status at %s

+" + + @staticmethod + def html_dump_footer(): + print "',self.html_href ('#'+self.friendly_name(),title),'' + + def html_dump_body(self): + if hasattr(self,'titles'): + for title in self.titles: + print ('
') + print '

',self.html_anchor(self.friendly_name(),title),'

' + if hasattr(self,'body'): + print self.body + + #################### @staticmethod def init_homedir (options): topdir=options.workdir @@ -622,8 +682,17 @@ The module-sync function has the following limitations if diff_output: print self.name else: - if not self.options.only or diff_output: - print 'x'*30,'module',self.friendly_name() + anchor=self.friendly_name() + do_print=False + if self.options.www and diff_output: + self.html_store_title("Diffs in module %s (%d chars)"%(anchor,len(diff_output))) + link=self.html_href(tag_url,tag_url) + self.html_store_raw ('

< (left) %s

'%link) + link=self.html_href(edge_url,edge_url) + self.html_store_raw ('

> (right) %s

'%link) + self.html_store_pre (diff_output) + elif not self.options.www: + print 'x'*30,'module',anchor print 'x'*20,'<',tag_url print 'x'*20,'>',edge_url print diff_output @@ -1190,8 +1259,8 @@ Branches: parser.add_option("-m","--message", action="store", dest="message", default=None, help="specify log message") if mode == "diff" : - parser.add_option("-o","--only", action="store_true", dest="only", default=False, - help="report diff only for modules that exhibit differences") + parser.add_option("-W","--www", action="store", dest="www", default=False, + help="export diff in html format, e.g. -W trunk") if mode == "diff" : parser.add_option("-l","--list", action="store_true", dest="list", default=False, help="just list modules that exhibit differences") @@ -1259,16 +1328,37 @@ Branches: parser.print_help() sys.exit(1) Module.init_homedir(options) - for modname in args: - module=Module(modname,options) - if len(args)>1 and mode not in Main.silent_modes: + + # 2 passes for www output + modules=[ Module(modname,options) for modname in args ] + # hack: create a dummy Module to store errors/warnings + error_module = Module('__errors__',options) + + # pass 1 : do it, except if options.www + for module in modules: + if len(args)>1 and mode not in Main.silent_modes and not options.www: print '========================================',module.friendly_name() # call the method called do_ method=Module.__dict__["do_%s"%mode] try: method(module) except Exception,e: - print 'Skipping failed %s: '%modname,e + if options.www: + title=' Skipping module %s - failure: %s '%(module.name, str(e)) + error_module.html_store_title(title) + else: + print 'Skipping module %s: '%modname,e + + # in which case we do the actual printing in the second pass + if options.www: + modules.append(error_module) + error_module.html_dump_header() + for module in modules: + module.html_dump_toc() + Module.html_dump_middle() + for module in modules: + module.html_dump_body() + Module.html_dump_footer() #################### if __name__ == "__main__" :