📄 diff.py
字号:
t=time.mktime(t)-time.timezone author=string.split(revdata[1])[1] comment=string.split(revdata[3],"\n",1)[1] if string.split(comment,":",1)[0] == "branches": comment=string.split(comment,"\n",1)[1] ci=Checkin(author, t, comment) ci.add(File(local_name, rev, root, cvs_file, viewcvs_url)) self.checkins.append(ci) revisions = revisions + 1 if status: print "Diff module %s failed\n" % imodule.id except cvs.cvs_error: print "Diff module %s failed\n" % imodule.id shell.rm(tmpdir) print "%d revisions in %s" % (revisions, imodule.id) def cmpfun(self, x, y): if x.begin_date != y.begin_date: if x.begin_date < y.begin_date: return 1 if x.begin_date > y.begin_date: return -1 if x.author != y.author: return x.author < y.author return x.files[0].localname < y.files[0].localname def merge_checkins(self): if not len(self.checkins): return self.checkins.sort(self.cmpfun) c=[ self.checkins[0] ] for x in self.checkins[1:]: if x.comment == c[-1].comment and x.author == c[-1].author: c[-1].end_date=x.end_date c[-1].files.extend(x.files) else: c.append(x) self.checkins=c def __init__(self, module_id, source_branch, source_tag, source_date, start_date, end_date): if start_date: if not re.match("^[-a-zA-Z0-9:/ ]*$",start_date): raise "Invalid start date" if end_date: if not re.match("^[-a-zA-Z0-9:/ ]*$",end_date): raise "Invalid start date" self.source_tag = source_tag self.source_date = source_date self.checkins = [] todo={} if type(module_id) != types.ListType: module_id=[ module_id ] self.module_id = module_id self.source_branch = source_branch self.start_date = start_date self.end_date = end_date if self.start_date: self.start_date_local=self.start_date self.start_date = datelib.cvs_server_time(datelib.date_to_gmticks(self.start_date)) if self.end_date: self.end_date_local=self.end_date self.end_date = datelib.cvs_server_time(datelib.date_to_gmticks(self.end_date)) self.date_range = " -d '%s<%s'" % (self.start_date or "", self.end_date or "") if self.date_range == " -d '<'": self.date_range = "" ## find the BIF file for the branch name branch_list = branchlist.BranchList(source_tag, source_date) old_filename = branch_list.file(source_branch) if not old_filename: print "no BIF file for branch=\"%s\"" % (source_branch) return 0 ## parse old BIF file, and create the new BIF file ## Do not include shadows print "parsing file=\"%s\"" % (old_filename) bdata1 = bif.load_bif_data(old_filename, branch_list, 0) ## compute the dependancy list for the target if module_id == [ "ALL" ]: print "diffing all modules" % (string.capitalize(branch_or_tag)) deplist1_list = bdata1.module_hash.values() else: print "computing dependancy tree for target=%s" % (repr(module_id)) deplist1_list = dependlist.DependList(bdata1, module_id).list() modules_to_diff = [] dists_done={} for mod in deplist1_list: if mod.type not in ["cvs", "distribution" ]: continue if mod.type == "distribution": if dists_done.has_key(mod.cvs_root): continue dists_done[mod.cvs_root]=1 modules_to_diff.append(mod) #print "TAGME: %s" % repr(modules_to_diff) chaingang.ProcessModules_anyorder(modules_to_diff, self.process_module) self.merge_checkins() def html(self): rownum=0 ret=[] ret.append("<table width='100%'>") ret.append("<tr>") ret.append('<th bgcolor="#88ff88">Date</th>') ret.append('<th bgcolor="#88ff88">Author</th>') ret.append('<th bgcolor="#88ff88">Comment</th>') ret.append('<th bgcolor="#88ff88">Files</th>') ret.append("</tr>\n") for x in self.checkins: ret.append("<tr>") ret.append(x.html(rownum & 1)) ret.append("</tr>\n") rownum = rownum + 1 if not self.checkins: ret.append("<tr>") ret.append('<td align=center bgcolor="#ffffff" colspan=4>no changes</td>') ret.append("</tr>\n") ret.append("</table>") return ret def html2(self): ret=[] ret.append("<table width=100% bgcolor='#e6e6e6'><tr><td>") ret.append("<table bgcolor='#e6e6e6'>") ret.append("<tr><td align=right><b>BIF:</b></td><td>%s</td>\n" % htmlquote(self.source_branch)) ret.append("<tr><td align=right><b>Target:</b></td><td>%s</td>\n" % htmlquote(string.join(self.module_id,", "))) if self.source_tag: ret.append("<tr><td align=right><b>CVS Tag:</b></td><td>%s</td>\n" % htmlquote(self.source_tag)) if self.source_date: ret.append("<tr><td align=right><b>CVS Date:</b></td><td>%s</td>\n" % htmlquote(self.source_date)) if self.start_date: ret.append("<tr><td align=right><b>History Start:</b></td><td>%s</td>\n" % htmlquote(self.start_date_local)) if self.end_date: ret.append("<tr><td align=right><b>History End:</b></td><td>%s</td>\n" % htmlquote(self.end_date_local)) ret.append("</table>") ret.append("</table>") ret.extend(self.html()) return ret def html3(self): ret=[] ret.append("<html>") ret.append("<header><title>Diff report</title></header>") ret.append("<body>") ret.append("<center><h2>Diff report</h2></center>") ret.extend(self.html2()) ret.append("</body>") ret.append("</html>") return ret ## print usage informationdef usage(): print 'Usage: diff.py [-r cvs-tag-to-branch-from] [-D cvs-date-to-read-bif-from]' print ' [-S start-date] [-E end-date]' print ' [-o output.html] -b BIF-file-id TARGET' print 'If target is "ALL", all targets will be diffed.' print 'default output filename is diff.html' sys.exit(1)## MAINif __name__ == '__main__': make_cmd="make" opt_list, arg_list = getopt.getopt(sys.argv[1:], 'r:b:D:o:S:E:') if len(arg_list) != 1: usage() ## create a hash from the opt_list opt_hash = {} for opt in opt_list: opt_hash[opt[0]] = opt[1] source_tag = '' source_branch = '' source_date='' ribosome=None cvs_flags='' bif_dir=None output_filename="diff.html" start_date=None end_date=None if opt_hash.has_key('-r'): source_tag = opt_hash['-r'] if opt_hash.has_key('-b'): source_branch = opt_hash['-b'] if opt_hash.has_key('-D'): source_date = opt_hash['-D'] if opt_hash.has_key('-o'): output_filename = opt_hash['-o'] if opt_hash.has_key('-S'): start_date = opt_hash['-S'] if opt_hash.has_key('-E'): end_date = opt_hash['-E'] target_module_id = arg_list[0] if not source_branch: usage() import buildmenu buildmenu.call_buildrc() try: diff=Diff(target_module_id, source_branch, source_tag, source_date, start_date, end_date) except err.error, e: print "Something went wrong:" print e.Text() open(output_filename,"w").write(string.join(diff.html3(),""))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -