📄 diff.py
字号:
#!/usr/bin/env python# # ***** BEGIN LICENSE BLOCK *****# Source last modified: $Id: diff.py,v 1.12 2004/08/10 16:39:53 hubbe Exp $# # Portions Copyright (c) 1995-2004 RealNetworks, Inc. All Rights Reserved.# # The contents of this file, and the files included with this file,# are subject to the current version of the RealNetworks Public# Source License (the "RPSL") available at# http://www.helixcommunity.org/content/rpsl unless you have licensed# the file under the current version of the RealNetworks Community# Source License (the "RCSL") available at# http://www.helixcommunity.org/content/rcsl, in which case the RCSL# will apply. You may also obtain the license terms directly from# RealNetworks. You may not use this file except in compliance with# the RPSL or, if you have a valid RCSL with RealNetworks applicable# to this file, the RCSL. Please see the applicable RPSL or RCSL for# the rights, obligations and limitations governing use of the# contents of the file.# # Alternatively, the contents of this file may be used under the# terms of the GNU General Public License Version 2 or later (the# "GPL") in which case the provisions of the GPL are applicable# instead of those above. If you wish to allow use of your version of# this file only under the terms of the GPL, and not to allow others# to use your version of this file under the terms of either the RPSL# or RCSL, indicate your decision by deleting the provisions above# and replace them with the notice and other provisions required by# the GPL. If you do not delete the provisions above, a recipient may# use your version of this file under the terms of any one of the# RPSL, the RCSL or the GPL.# # This file is part of the Helix DNA Technology. RealNetworks is the# developer of the Original Code and owns the copyrights in the# portions it created.# # This file, and the files included with this file, is distributed# and made available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY# KIND, EITHER EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS# ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET# ENJOYMENT OR NON-INFRINGEMENT.# # Technology Compatibility Kit Test Suite(s) Location:# http://www.helixcommunity.org/content/tck# # Contributor(s):# # ***** END LICENSE BLOCK *****# """Not part of the build system, but a really useful script for diffingthe code base. """import osimport sysimport stringimport getoptimport bifimport dependlistimport branchlistimport copyimport cvsimport typesimport chaingangimport distributionsimport shellimport moduleimport errimport timeimport posixpathimport reimport datelibdef htmlquote(str): str=string.strip(str) str=string.replace(str,"&","&") str=string.replace(str,"<","<") str=string.replace(str,">",">") str=string.replace(str,"\n","<br>") return strdef dec_rev(rev): tmp=string.split(rev,".") tmp[-1]=str(int(tmp[-1])-1) return string.join(tmp, ".")class File: def __init__(self, localname, rev, root, cvsfile, viewcvs_url): self.localname=localname self.rev=rev self.root=root self.cvsfile=cvsfile self.viewcvs_url=viewcvs_url def text(self): return ' %s: %s' % (self.localname, self.rev) def html(self): if self.viewcvs_url: return '<a href="%s">%s</a> <a href="%s?annotate=%s">%s</a> (<a href="%s.diff?r1=%s&r2=%s">diff</a>)' % ( self.viewcvs_url, htmlquote(self.localname), self.viewcvs_url, self.rev, self.rev, self.viewcvs_url, dec_rev(self.rev), self.rev, ) return "%s %s" % (htmlquote(self.localname), self.rev)class Checkin: def __init__(self, author, date, comment): self.begin_date=date self.end_date=date self.files=[] self.comment=comment self.author=author def add(self, file): self.files.append(file) def __repr__(self): ret=[] ret.append("===================Checkin======================"); ret.append("%s - %s, %s" % ( time.ctime(self.begin_date), time.ctime(self.end_date), self.author)) for (localname, rev, root, cvsfile) in self.files: ret.append(' %s: %s (%s <> %s))' % (localname, rev, root, cvsfile)) ret.append(self.comment) return string.join(ret,"\n") def text(self): ret=[] ret.append("Checkin by %s, %s" % (self.author, time.ctime(self.begin_date))) for f in self.files: ret.append(f.text()) ret.append("") ret.append(self.comment) ret.append("---------------------------------------------------") return string.join(ret,"\n") def html(self, blue): if blue: td="<td valign=top bgcolor='#ccccee'" else: td="<td valign=top bgcolor='#ffffff'" ret=[] ret.append("<tr align=top>") t=string.replace(datelib.asctime(self.begin_date), " "," ") ret.append("%s>%s</td>" % (td,t)) ret.append("%s>%s</td>" % (td, htmlquote(self.author))) ret.append("%s>%s</td>" % (td, htmlquote(self.comment))) files=[] for f in self.files: files.append(f.html()) ret.append("%s>%s</td>" % (td, string.join(files,"<br>"))) return string.join(ret,"") class Diff: def process_module(self, imodule): if imodule.type in ["cvs", "distribution"]: revisions=0 tmpdir="diff_tmp_"+str(distributions.my_get_thread_ident()) shell.rm(tmpdir) try: if imodule.type == "cvs": imodule.checkout( date = self.source_date, tag = self.source_tag, as = tmpdir) else: cvs.Checkout(self.source_tag or imodule.cvs_tag, "distribution", imodule.cvs_root, tmpdir, self.source_date or imodule.cvs_date) tag = "-b" try: tag=string.strip(open(os.path.join(tmpdir,"CVS","Tag"),"r").read()) ## Fixme: what if the sticky tag is a date?? if tag and tag[0] == "T": tag = "-r"+tag[1:] else: tag = "-b" except IOError: pass cmd='cvs log%s -N %s >cvs-log-temp-file' %( self.date_range, tag ) print "Running: %s (in %s + %s)" % (cmd, os.getcwd(), tmpdir) status, output = shell.run(cmd, dir = tmpdir) print output output=open(os.path.join(tmpdir,"cvs-log-temp-file"),"r").read() output=string.replace(output,"\r\n","\n") root="UNKNOWN" try: root=open(os.path.join(tmpdir,"CVS","Root"),"r").read() root=string.strip(root) except IOError: pass base_repository="UNKNOWN" try: base_repository=open(os.path.join(tmpdir,"CVS","Repository"),"r").read() base_repository=string.strip(base_repository) except IOError: pass viewcvs_base = cvs.GetViewCVSUrl(imodule.cvs_root, imodule.cvs_path or imodule.name) blocks=string.split(output, "=============================================================================") for file in blocks[:-2]: data=string.split(file,"----------------------------\nrevision ") wf=string.split(data[0],"Working file: ",1)[1] wf=string.split(wf,"\n",1)[0] local_name=os.path.join(imodule.name, wf) print " - %s, %d revisions" % (wf, len(data)-1) viewcvs_url=None if viewcvs_base: viewcvs_url=posixpath.join(viewcvs_base,wf) cvs_file=os.path.join(base_repository, wf) for revision in data[1:]: revdata=string.split(revision,";",3) author=string.split(revdata[1])[1] ## Ignore build farm checkins if author in [ "mserver", "drmbuild", "buildq", "codecbuild" ]: continue tmp=string.split(revdata[0]) rev=tmp[0] t="%s %s" % (tmp[2],tmp[3]) t=time.strptime(t,"%Y/%m/%d %H:%M:%S")
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -