⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cvs.py

📁 linux下的一款播放器
💻 PY
📖 第 1 页 / 共 2 页
字号:
            shell.mkdir("cvs_temp")            os.chdir("cvs_temp")            self.checkout(tag,module_list, None, timestamp, nonrecursive)            os.chdir(odir)            for m in module_list:                shell.cp(os.path.join(odir, "cvs_temp", m),                         os.path.join(odir, as))            shell.rm("cvs_temp")            return                if nonrecursive:            e = err.Error()            e.Set("Nonrecursive not supported by MacCVS")            raise err.error, e                session_name = self.cvs_session_path[1:-1]        session_name = os.path.basename(session_name)        script = ascript.CreateAppleScript(            'tell application %s' % (self.cvs_path),            '  activate',            '  open alias %s' % (self.cvs_session_path),            '  set thesession to session named "%s"' % (session_name),            '  set local root of thesession to alias "%s"' % (os.getcwd()),            '  with timeout of 99999 seconds')        for module in module_list:            cmd = 'check out thesession module "%s"' % (module)            if tag:                cmd = cmd +' revision "%s"' % (tag)            if timestamp:                cmd = cmd +' date "%s"' % (timestamp)            script.Append(cmd)        script.Append(            '  end timeout',            '  quit',            'end tell')        if self.script_save_path == '':            result = script.CompileAndExecute()        else:            script.CompileAndSave(self.script_save_path)            launch_script = ascript.CreateAppleScript(                'set scriptobj to (load script file "%s")' % (                self.script_save_path),                'tell scriptobj',                '  run',                'end tell')            result = launch_script.CompileAndExecute()        if result and result != '':            outmsg.error('cvs checkout error %s' % (result))    def update(self, tag, module_list):        ## FIXME: check 'tag'        session_name = self.cvs_session_path[1:-1]        session_name = os.path.basename(session_name)##        if source == '':##            (path, module) = os.path.split(os.getcwd())##        else:##            (path, module) = os.path.split(source)        (path, module) = os.path.split(os.getcwd())        script = ascript.CreateAppleScript(            'tell application %s' % (self.cvs_path),            '  activate',            '  open alias %s' % (self.cvs_session_path),            '  set thesession to session named "%s"' % (session_name),            '  set local root of thesession to alias "%s"' % (path),            '  with timeout of 99999 seconds')        for module in module_list:##            script.Append('update thesession module "%s"' % (module))            script.Append('check out thesession module "%s"' % (module))        script.Append(            '  end timeout',            '  quit',            'end tell')        result = script.CompileAndExecute()        if result and result != "":            outmsg.error("cvs update error %s" % (result))class MultiCVS:    def __init__(self, root, shadow = None, viewcvs = None):        self.root = root        if self.root[-1] != '/':            self.root = self.root + "/"        self.shadow = shadow        self.viewcvs=viewcvs    def fix(self, path, dir = None):        tmp=string.split(path,"/")        base=tmp[0]        path=string.join(tmp[1:],"/")        if path == "":            path = "."        if dir:            dir=os.path.join(dir,base)        else:            dir=base        return (base, path, dir)    def get_root(self, module):        tmp=string.split(module,"/")        base=tmp[0]        return self.root + base    def Status(self, path, dir=None):        base, path, dir = self.fix(path, dir)        return _Cvs(self.root + base).Status(path,dir)    def Commit(self, path, message, dir=None):        base, path, dir = self.fix(path, dir)        return _Cvs(self.root + base).Commit(path,message,dir)    def Tag(self, path, message, dir=None):        base, path, dir = self.fix(path, dir)        return _Cvs(self.root + base).Tag(path,message,dir)    def Checkout(self, tag, module_list, as=None, timestamp=None, nonrecursive=0):        tmp={}        for m in module_list:            base, mod, dir = self.fix(m, ".")            if tmp.has_key(base):                tmp[base].append( mod )            else:                tmp[base]=[mod]        for base in tmp.keys():            ns=None            if self.shadow:                ns=self.shadow + base            if as:                dir = None            else:                dir = base                shell.mkdir(dir)            _Cvs(self.root + base, ns).Checkout(tag,                                                tmp[base],                                                as,                                                timestamp,                                                nonrecursive,                                                dir)    def get_viewcvs_url(self, path):        if not self.viewcvs:            return None        try:            project, path = string.split(path,"/",1)        except ValueError:            project = path            path = ""        return string.replace(self.viewcvs,"$project", project) + path## create CVS class instance_Cvs = None_cvs = Noneif os.name == "posix" or (os.name == 'nt' and \    os.environ.get('OS') == 'Windows_NT'):    _Cvs = UNIXWinCVSelif os.name == "dos" or \    string.find(os.environ.get("winbootdir", ""), "WINDOWS") >= 0:    _Cvs = Win9xCVSelif os.name == "mac":    if os.environ.get("CVSROOT","") != "":        _Cvs=UNIXWinCVS    else:        _Cvs = MacCVSelse:    e = err.Error()    e.Set("Unsupported OS for cvs.py.")    raise err.error, ecvs_class_cache = {}cvs_error = "cvs error"def Get(name):    if cvs_class_cache.has_key(name):        return cvs_class_cache[name]    ret = None    if name == "":        if _Cvs == MacCVS:            ret = _Cvs(os.environ.get("CVSSESSION_PATH"))        else:            ret = _Cvs(os.environ.get("CVSROOT"))    if not ret:        print "Failed to find CVS repository '%s' in your .buildrc." % name        print "Please refer to the documentation to find out how to"        print "add cvs repositories to your buildrc file."        raise cvs_error    cvs_class_cache[name] = ret    return retdef Add(name, root, shadow = None, viewcvs = None):    cvs_class_cache[name] = _Cvs(root, shadow, viewcvs)def AddMulti(name, root, shadow = None, viewcvs = None):    cvs_class_cache[name] = MultiCVS(root, shadow, viewcvs)def AddMacCVS(name, session_file, shadow_session = None, viewcvs = None):    cvs_class_cache[name] = MacCvs(session_file, shadow_session, viewcvs)def AddCmdCVS(name, root, shadow = None, viewcvs = None):    if _Cvs != MacCVS:        Add(name, root, shadow, viewcvs)    else:        cvs_class_cache[name] = UNIXWinCVS(root, shadow, viewcvs)get_reverse_cache={}def GetReverse(root, path):    if not get_reverse_cache.has_key(root):        for (name, cl) in cvs_class_cache.items():            if cl.root == root[:len(cl.root)]:                get_reverse_cache[root]=name                break    return get_reverse_cache[root]    cvs_checkout_hook = None## entrypointsdef Checkout(tag,             module_list,             repository_name = "",             as = None,             timestamp = None,             nonrecursive = 0,             zap = None):    module_list = listify(module_list)    if cvs_checkout_hook:        module_list = cvs_checkout_hook(tag, module_list, repository_name, as, timestamp, nonrecursive)    if not module_list:        return    if zap:        for mod in module_list:            if as:                mod = as            if os.path.exists(mod):                import thread                print "DELETING: %s [%d] START" % (mod, thread.get_ident())                shell.rm(mod)                print "DELETING: %s [%d] END" % (mod, thread.get_ident())    return Get(repository_name).Checkout(tag, module_list, as, timestamp, nonrecursive)def Status(repository, path, dir = None):    return Get(repository).Status(path, dir)def Commit(repository, path, message, dir = None):    return Get(repository).Commit(path, message, dir)def Tag(repository, path, tag, dir=None):    return Get(repository).Tag(path, tag, dir)def GetViewCVSUrl(repository, path):    return Get(repository).get_viewcvs_url(path)import posixpathclass MagicFixDir:        def is_new(self):        return self.new_cvs_dir    def get_root(self):        if not self.cvsdir:            return None        return open(os.path.join(self.cvsdir,"Root"),"r").read()    def get_repository(self):        return open(os.path.join(self.cvsdir,"Repository"),"r").read()    def get_parent_repository(self):        rep_all=self.get_repository()        rep=string.rstrip(rep_all)        dname=posixpath.dirname(rep)        if not dname:            dname="."        return dname + rep_all[ len(rep) - len(rep_all) : ]    def get_tag(self):        try:            return open(string.join(self.cvsdir,"Tag"),"r").read()        except IOError:            return None    def mkparent(self):        return (            self.get_root(),            self.get_parent_repository(),            self.get_tag()            )    def get_entry(self):        return "D/%s////\n" % os.path.basename(self.dir)    def __init__(self, dir="."):        self.dir=dir        self.new_cvs_dir=None        self.cvsdir = os.path.join(dir, "CVS")        subdirs=[]        entries=[]        try:            files=os.listdir(dir)        except:            return        for e in files:            if e in ["CVS"]:                continue            path = os.path.join(dir, e)            if os.path.isdir(path):                ndir = MagicFixDir(path)                if ndir.cvsdir:                    subdirs.append(ndir)        if not os.path.isdir(self.cvsdir):            if subdirs:                self.new_cvs_dir=1                use_fake=0                q=subdirs[0].mkparent()                for n in subdirs:                    entries.append(n.get_entry())                    #print "==========="                    #print n.cvsdir                    #print n.mkparent()                    #print q                    #print "==========="                    if n.mkparent() != q:                        use_fake=1                if use_fake:                    print "Adding faux CVS dir: %s" % self.cvsdir                    faux=os.path.join(os.environ["BUILD_ROOT"],"lib","faux-cvs","CVS")                    if os.path.isdir(faux):                        shell.mkdir(self.cvsdir)                        shell.cp(os.path.join(faux,"Root"), os.path.join(self.cvsdir,"Root"))                        shell.cp(os.path.join(faux,"Repository"),                                 os.path.join(self.cvsdir,"Repository"))                    else:                        print "Faux cvs dir missing, skipping"                        self.cvsdir=None                        return                else:                    print "Adding PARENT CVS dir: %s" % self.cvsdir                    shell.mkdir(self.cvsdir)                    open(os.path.join(self.cvsdir,"Root"),"w").write(q[0])                    open(os.path.join(self.cvsdir,"Repository"),"w").write(q[1])                    if q[2]:                        open(os.path.join(self.cvsdir,"Tag"),"w").write(q[2])                                    open(os.path.join(self.cvsdir,"Entries"),"w").write(string.join(entries,""))            else:                self.cvsdir=None        else:            for n in subdirs:                if n.is_new():                    entries.append(n.get_entry())            if entries:                print "Adding CVS entries in %s" % self.cvsdir                e=open(os.path.join(self.cvsdir,"Entries"),"a")                e.write(string.join(entries,""))        

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -