📄 cvs.py
字号:
# # ***** BEGIN LICENSE BLOCK *****# Source last modified: $Id: cvs.py,v 1.37 2004/12/09 22:17:01 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 *****# """Multi-platform classes to checkout source code from CVS. This moduleautomatically determines the platform and instances the correct platformspecific CVS class. Only the entry points Checkout and Update are meant tobe used."""import osimport sysimport stringimport typesimport timeimport errimport shellimport outmsgimport ascriptimport outmsgimport redef listify(string_or_list): """Takes a string or list of strings as input, and returns a list of strings.""" list = None if type(string_or_list) == types.ListType: list = string_or_list else: list = [string_or_list] ## filter list to have only unique items for item in list: while list.count(item) > 1: list.remove(item) return listdef mkdirhier(dir): if not dir or os.path.isdir(dir): return mkdirhier(os.path.dirname(dir)) if not os.path.isdir(dir): os.mkdir(dir)class CVS: """Abstract CVS class.""" def update_checkout_list(self, tag, module_list, as, dir): update_list = [] checkout_list = [] if tag == "HEAD": tag = "" ## separate the modules which need to be checked out ## from the modules which need to be updated ## and go through the list of modules to be updated, and ## check that the current module's CVS/Tag entry is the same ## before updating; if it's not, then throw a error and let ## the developer handle it update_error_list = [] for module in update_list: opath = module if dir: opath = os.path.join(dir, module) if as: opath = as if not os.path.isdir(opath): checkout_list.append(module) continue update_list.append(module) tag_path = os.path.join(opath, "CVS", "Tag") try: current_tag = string.strip(open(tag_path).read()) except IOError: current_tag = "" if current_tag in [ "HEAD", "THEAD", "NHEAD" ]: current_tag = "" tag_match = 0 ## some versions of CVS put a "N" or "T" before the actual tag if re.match(r'^[NT]?' + tag, current_tag): tag_match = 1 if not tag_match: update_error_list.append( "module=\"%s\" current tag=\"%s\"" % (module, current_tag)) ## now error out if there were conflicts if update_error_list: e = err.Error() e.Set("There are CVS modules in your source tree which "\ "were originally checked out from a different CVS "\ "branch than the current .bif file is requesting. "\ "This is most likely because of a change in the .bif "\ "file. You will need to remove or move these modules "\ "by hand before the build system can continue.\n%s" % ( string.join(update_error_list, "\n"))) raise err.error, e return update_list, checkout_list def Checkout(self, tag, module_list, as = None, timestamp = None, nonrecursive = 0, dir = None): """Given a CVS tag and a list of CVS modules, check them out.""" #print "cvs.Checkout(%s,%s,as=%s,timestamp=%s, %s, %s)" % ( # repr(tag),repr(module_list), # repr(as),repr(timestamp), repr(nonrecursive), repr(dir)) module_list = listify(module_list) if as: if len(module_list) > 1: print "Cannot checkout two modules as the same name" sys.exit(1) self.checkout(tag, module_list, as, timestamp, nonrecursive) return update_list,checkout_list = self.update_checkout_list(tag, module_list, as, dir) #if update_list: # self.update(tag, update_list, timestamp, nonrecursive) #if checkout_list: # self.checkout(tag, checkout_list, as, timestamp, nonrecursive, dir) self.checkout(tag, module_list, as, timestamp, nonrecursive, dir) def get_viewcvs_url(self, path): if not self.viewcvs: return None return self.viewcvs + pathclass UNIXCVS(CVS): def __init__(self, root, shadow = None, viewcvs = None): self.root = root self.shadow = shadow self.viewcvs = viewcvs def get_root(self, module): return self.root def Cmd(self, cmd, path, dir = None): cmd='cvs -d "%s" %s "%s"' % (self.root, cmd, path) outmsg.verbose("running %s in %s + %s" % (repr(cmd), repr(os.getcwd()), repr(dir))) return shell.run(cmd, dir = dir) def Status(self, path, dir=None): return self.Cmd("status",path, dir) def Commit(self, path, message, dir=None): return self.Cmd('commit -m "%s"' % message, path, dir) def Tag(self, path, tag, dir=None): return self.Cmd('tag "%s"' % tag, path, dir) def update(self, tag, module_list, timestamp = None, nonrecursive = 0): #print "cvs.update(%s,%s,timestamp=%s,%s)" % ( # repr(tag),repr(module_list), # repr(timestamp), repr(nonrecursive)) cmd = "cvs" if self.root: if self.shadow: cmd = "%s -d %s" % (cmd, self.shadow) else: cmd = "%s -d %s" % (cmd, self.root) cmd = "%s update" % cmd if nonrecursive: cmd = cmd + " -l" if len(tag): if tag == "HEAD": cmd = "%s -A" % cmd else: cmd = '%s -r "%s"' % (cmd, tag) if timestamp: cmd = '%s -D "%s"' % (cmd, timestamp) def line_cb(line): line = string.strip(line) outmsg.verbose(line) if not line: return elif line[0] == "U" or line[0] == "P": outmsg.send("CVS(updated): %s" % (line[2:])) elif line[0] == "M": outmsg.send("CVS(locally modified): %s" % (line[2:])) elif line[0] == "C": outmsg.send("CVS(*conflict*): %s" % (line[2:])) command = "%s %s" % (cmd, string.join(module_list)) shell.run(command, line_cb) for dir in module_list: dir=os.path.join(os.curdir, dir) if os.path.isdir(dir): ## Create a timestamp file timestamp=os.path.join(dir, "CVS", "timestamp") shell.rm(timestamp) open(timestamp,"w").write(str(int(time.time()))) def checkout(self, tag, module_list, as = None, timestamp = None, nonrecursive = 0, checkout_dir = None): # print "TAG = %s" % tag # print "TIMESTAMP = %s" % timestamp if checkout_dir == None: checkout_dir = os.curdir cmd = "cvs" if self.root: if self.shadow: cmd = "%s -d %s" % (cmd, self.shadow) else: cmd = "%s -d %s" % (cmd, self.root) cmd = "%s checkout" % cmd if nonrecursive: cmd = cmd + " -l" if len(tag): if tag == "HEAD": cmd = "%s -A" % cmd else: cmd = '%s -r "%s"' % (cmd, tag) if timestamp: cmd = '%s -D "%s"' % (cmd, timestamp) out_dirs = [] for x in module_list: #print "%s" % repr( [checkout_dir] + string.split(x,"/")) out_dirs.append(apply(os.path.join, [checkout_dir] + string.split(x,"/"))) as_arg = "" if as: dir, base = os.path.split(as) if dir: mkdirhier(dir) checkout_dir = dir cmd = "%s -d %s" % (cmd , base) out_dirs = [as] cmd = "%s %s" % (cmd, string.join(module_list)) outmsg.verbose("running %s in %s (as = %s)" % (repr(cmd), repr(os.getcwd()), repr(as))) def line_cb(line): outmsg.verbose(string.strip(line)) retcode, output = shell.run(cmd, line_cb, dir = checkout_dir) #if retcode: # print "CVS process exited with error code: %d" % retcode dirs = out_dirs[:] for dir in dirs: if os.path.isdir(dir): ## Create a timestamp file timestamp=os.path.join(dir, "CVS", "timestamp") shell.rm(timestamp) try: open(timestamp,"w").write(str(int(time.time()))) except IOError: continue if self.shadow: for subdir in os.listdir(dir): if string.lower(subdir) != "cvs": subdir=os.path.join(dir, subdir) if os.path.isdir(subdir): dirs.append(subdir) rootfile = os.path.join(dir, "CVS", "Root") open(rootfile,"w").write("%s\n" % self.root)class UNIXWinCVS(UNIXCVS): def update(self, tag, module_list, timestamp = None, nonrecursive = 0): step=20 for d in range(0, len(module_list), step): UNIXCVS.update(self, tag, module_list[d:d+step],timestamp,nonrecursive) def checkout(self, tag, module_list, as = None, timestamp = None, nonrecursive = 0, dir = None): step=20 for d in range(0, len(module_list), step): UNIXCVS.checkout(self,tag,module_list[d:d+step],as,timestamp,nonrecursive, dir)class Win9xCVS(UNIXCVS): def update(self, tag, module_list, timestamp = None, nonrecursive = 0): for module in module_list: UNIXCVS.update(self, tag, [module], timestamp, nonrecursive) def checkout(self, tag, module_list, as = None, timestamp = None, nonrecursive = 0, dir=None): for module in module_list: UNIXCVS.checkout(self, tag, [module], as, timestamp, nonrecursive, dir)class MacCVS(CVS): def __init__(self, cvssession, shadow = None, viewcvs = None): self.viewcvs=viewcvs if os.environ.has_key('MACCVS_PATH'): self.cvs_path = os.environ['MACCVS_PATH'] else: e = err.Error() e.Set("You need to set the MACCVS_PATH environment variable "\ "to the path of MacCVS.") raise err.error, e if cvssession: self.cvs_session_path = cvssession else: e = err.Error() e.Set("You need to set the CVSSESSION_PATH environment variable "\ "to the path of the MacCVS session file.") raise err.error, e if os.environ.has_key('CVSSCRIPT_PATH'): self.script_save_path = os.environ['CVSSCRIPT_PATH'] else: self.script_save_path = '' def checkout(self, tag, module_list, as = None, timestamp = None, nonrecursive = 0, dir = None): ### FIXME: ### test this! if dir: odir=os.getcwd() try: os.chdir(dir) ret=self.checkout(tag, module_list, as, timestamp, nonrecursive) finally: os.chdir(odir) return ret if as: odir=os.getcwd()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -