def Run(self): basedir, module = os.path.split(self.dir) console = ColorConsole() if os.path.exists(os.path.join(basedir, 'CVS')): console << kRed << 'Parent directory may not be CVS-controlled!\n' << kNormal return msg = 'Enter the CVSROOT of the repository you wish to add the new root module "%s" to!' % module title = 'Add Root Module' answer, root = App.CvsPrompt(str(Persistent('P_CVSROOT', '', 0)), 'Question', msg, alertTitle=title) if not (answer=='IDOK' and len(root)>0): print 'Operation cancelled by user.' return os.chdir(basedir) cvs = Cvs(1,0) print 'Preparing sandbox...' if not self.runCvs(cvs, console, '-d'+root, 'co', '-l', '.'): return print 'Creating new module %s/%s...' % (root, module) if not self.runCvs(cvs, console, 'add', module): return print 'Cleaning up...' shutil.rmtree(os.path.join(basedir, 'CVS')) print 'Done.'
def Run(self): print 'Removing %s...' % self.delinquent self.cnt = 0 self.skip = 0 self.dircnt = 0 self.dirskip = 0 console = ColorConsole() try: console << kNormal self.delEntries(self.sel, console) if self.cnt > 0: console << kRed else: console << kBrown console << '\nFiles removed: %d' % self.cnt if self.skip > 0: console << kGreen << '\tFiles skipped: %d\n' % self.skip else: console << '\n' if (self.dircnt > 0) or (self.dirskip > 0): if self.dircnt > 0: console << kRed else: console << kBrown console << 'Directories removed: %d' % self.dircnt if self.dirskip > 0: console << kBlue << '\tDirectories skipped: %d\n' % self.dirskip finally: console << kNormal << '\n'
def Run(self): cwdbup = os.getcwd() try: self.reConflicts = re.compile( '^<<<<<<< [^\n]*\n.*=======\n.*>>>>>>> [\d\.]*$', re.MULTILINE | re.DOTALL) console = ColorConsole() try: self.resolvingCount = 0 self.unresolvedCount = 0 self.errCount = 0 console << kNormal << '\nScanning for %s files...\n' % self.s_scantype self.scanEntries(self.sel, console) console << kBold if self.resolvingCount > 0: console << kGreen << '\n%4.d %s.' % ( self.resolvingCount, self.s_resolvingreport) if self.unresolvedCount > 0: console << kMagenta << '\n%4.d %s.' % ( self.unresolvedCount, self.s_unresolvedreport) if self.errCount > 0: console << kRed << '\n%4.d errors while scanning files.' % self.errCount if self.resolvingCount + self.unresolvedCount + self.errCount <= 0: console << 'No relevant files found.' finally: console << kNormal << '\nDone.\n\n' finally: os.chdir(cwdbup)
def Run(self): dlgTitle='Change module path' self.count = 0 self.errCnt = 0 self.mismatches = {} oldrepo = self.getRepo( self.sel[0]) answer, self.oldrepo = App.CvsPrompt(oldrepo, 'Question', \ 'Enter the old module path that is to be changed', \ '(this is not the new module path!).\n\n' \ +'Just press OK to accept current.', alertTitle=dlgTitle) if answer == 'IDOK': if self.oldrepo != '': oldrepo = self.oldrepo answer, self.newrepo = App.CvsPrompt(oldrepo, 'Question', 'Enter new module path.', \ 'Change old module path\n\n\t%s\n\nto new:' % self.oldrepo, alertTitle=dlgTitle) if answer == 'IDOK': console = ColorConsole() console << kNormal << '\nchanging module path %s to %s ...\n' % (self.oldrepo, self.newrepo) for entry in self.sel: self.changeRepos( entry, console) console << kBlue << 'Changed %d Repository entries.\n' % self.count if self.errCnt > 0: console << kRed << 'Encountered %d errors.\n' % self.errCnt << kNormal if len(self.mismatches) > 0: console << kBrown << 'Skipped %d mismatching module paths:\n' % len(self.mismatches) for repo, cnt in self.mismatches.items(): console << kBrown << '\t%s\t(%d directories)\n' % (repo, cnt) console << kNormal << '\n'
def Run(self): print "Zipping modified files..." # at this point we are sure we have only one regular folder sel = cvsgui.App.GetSelection() # find the common top path of the selection paths = [] for s in sel: paths.append(s.GetFullName()) dir = os.path.dirname(os.path.commonprefix(paths)) # we chdir because of Zip which stores with relative paths os.chdir(dir) zip = zipfile.ZipFile("archive.zip", "w", zipfile.ZIP_DEFLATED) toppath = dir if toppath[-1] != os.sep: toppath += os.sep console = ColorConsole() console << "\tZipping files :" << '\n' for s in sel: # zip the relative path name = string.replace(s.GetFullName(), toppath, "") console << kMagenta << "\t\t" << name << kNormal << '\n' zip.write(name) zip.close() print "%d file(s) zipped in '%s'." % ( len(sel), os.path.join(toppath, "archive.zip"))
def Run(self): cvs = Cvs(1) code, out, err = cvs.Run("co", "-c") console = ColorConsole() if out: lines = string.split(out, '\n') test1 = re.compile('^([\w-]+)(\s*)(.*)') test2 = re.compile('^(\s*)(.*)') for l in lines: m = test1.match(l) if m != None: console << kRed << m.group(1) << kNormal << '\n' console << kBlue << '\t' << m.group(3) << kNormal << '\n' else: m = test2.match(l) if m != None: console << kBlue << '\t' << m.group( 2) << kNormal << '\n' else: console << l << '\n' else: console << kRed << "No module entries found! Consult your repository's admin.\n" << kNormal del console
def Run( self): dlgTitle='Change CVSROOT' self.count = 0 self.errCnt = 0 self.mismatches = {} oldroot = self.getRoot( self.sel[0]) answer, self.oldroot = App.CvsPrompt(oldroot, 'Question', \ 'Enter the old CVSROOT that is to be changed.', \ '(this is not the new CVSROOT!).\n\n' \ +'Clear to change all existing CVSROOTs.\n\n' \ +'Just press OK to accept current.', alertTitle=dlgTitle) if answer == 'IDOK': if self.oldroot != '': oldroot = self.oldroot answer, self.newroot = App.CvsPrompt(oldroot, 'Question', \ 'Enter the new CVSROOT.', 'Change old CVSROOT\n\t%s\n\nto new:' % self.oldroot, alertTitle=dlgTitle) if answer == 'IDOK': console = ColorConsole() console << kNormal << '\nchanging CVSROOT %s to %s ...\n' % ( self.oldroot, self.newroot) for entry in self.sel: self.changeRoots( entry, console) console << kBlue << 'Changed %d Root entries.\n' % self.count if self.errCnt > 0: console << kRed << 'Encountered %d errors.\n' % self.errCnt << kNormal if len(self.mismatches) > 0: console << kBrown << 'Skipped %d mismatching CVSROOTs:\n' % len(self.mismatches) for root, cnt in self.mismatches.items(): console << kBrown << '\t%s\t(%d directories)\n' % (root, cnt) console << kNormal << '\n'
def Run(self): dlgTitle = 'List Module Contents' answer, cvsroot = App.CvsPrompt(str(self.config.root), 'Question', 'Enter CVSROOT.', \ alertTitle=dlgTitle) if answer == 'IDOK': self.config.root << cvsroot answer, module = App.CvsPrompt(str(self.config.module), 'Question', 'Enter Module.', \ '(enter a period (".") to get the top-level modules)', \ alertTitle=dlgTitle) if answer == 'IDOK': self.config.module << module answer, rev = App.CvsPrompt(str(self.config.rev), 'Question', 'Enter Revision/Branch.', \ alertTitle=dlgTitle) if answer == 'IDOK': self.config.rev << rev tmpdir = os.path.join(tempfile.gettempdir(), 'cvsrlist') cwdbup = os.getcwd() try: fakeCvsDir(tmpdir, cvsroot, module) cvs = Cvs(1, 0) console = ColorConsole() code, out, err = cvs.Run('-n', 'up', '-d', '-r' + rev) if code == 0: repo = string.join(cvsroot.split(':')[2:], ':') repo = repo[repo.find('@') + 1:] console << '\nContents of module ' << kBold << module << '\n' console << kNormal << '(Repository ' << kBold << repo << kNormal << '):\n' console << kMagenta << '=' * 60 << '\n' << kNormal rex = re.compile("New directory \`([^\']*)\' \-\- ignored") if err: for line in err.split('\n'): m_module = rex.search(line) if m_module: console << kGreen << '[%s]' % m_module.group( 1) << '\n' << kNormal if out: rex = re.compile("U (.*)$") for line in out.split('\n'): m_module = rex.search(line) if m_module: console << kBlue << m_module.group( 1) << '\n' << kNormal else: console << kRed << err << kNormal finally: os.chdir(cwdbup) if os.path.exists(tmpdir): shutil.rmtree(tmpdir)
def DoFolder(self, path): __doc__ = """Check all files in a folder and subfolders for DST problems. Simmilar to DoFile(), but with looping and recursion.""" numFixed = 0 toRecurse = [] list = {} list["modified"] = [] list["tofix"] = [] # build a list of interesting files for this path entries = GetCvsEntriesList(path) for e in entries: if e.IsFile(): tofix, mod_time = self.IsBadDSTentry(e) if tofix: list["tofix"].append((e, mod_time)) if _debugging: print "Appending '", e.GetFullName( ), "' to 'tofix' list: Entry: ", e, ", mod time: ", mod_time numFixed += 1 elif e.IsModified() and e.GetConflict() == '': list["modified"].append(e) elif not e.IsMissing() and not e.IsUnknown(): toRecurse.append(e.GetFullName()) # now print the list if len(list["modified"]) > 0 or len(list["tofix"]) > 0: print "In %s :" % path console = ColorConsole() console << ("\t%d Modified files :" % len(list["modified"])) << '\n' for e in list["modified"]: console << kMagenta << "\t\t" << e.GetName() << kNormal << '\n' console << ("\t%d Files to fix for DST:" % len(list["tofix"])) << '\n' for (ent, modtime) in list["tofix"]: console << kMagenta << "\t\t" << ent.GetName( ) << kNormal << '\n' #': ' << kRed << ent.GetUTC() << kMagenta \ # << '-->' << kBlue << modtime << kNormal << '\n' if (len(list["tofix"]) > 0): self.FixEntries(path, list["tofix"]) # recurse for f in toRecurse: numFixed += self.DoFolder(f) return numFixed
def Run(self): entry = self.sel[0] rev = entry.GetVersion() cvs = Cvs(1) os.chdir(entry.GetPath()) code, out, err = cvs.Run("log", "-N", "-r%s" % rev, entry.GetName()) console = ColorConsole() console << kBold << entry.GetFullName() << '\n' << kNormal #parse cvs output: lines = string.split(out, '\n') startParsing = 0 for line in lines: if startParsing or re.compile("^--------").match(line): startParsing = 1 if re.compile("^--------").match(line): console << kBlue << line << "\n" << kNormal elif re.compile("^revision").match(line): console << kNormal << "revision : " << kRed << kBold << rev << "\n" << kNormal elif re.compile("^date").match(line): entries = string.split(line, ';') for item in entries: tokens = string.split(item, ':') if len(tokens) > 1: console << kNormal << string.rjust(tokens[0], 8) << " : " console << kBold << string.strip( string.join(tokens[1:], ':')) << "\n" << kNormal else: console << item << '\n' elif re.compile("^========").match(line): pass else: console << kBrown << line << "\n" << kNormal
def Run(self): cwdbup = os.getcwd() try: console = ColorConsole() try: self.errCount = 0 self.cleanupCount = 0 console << kNormal << '\nScanning selection for missing files and folders...\n' self.cleanupMissingEntries(self.sel, console) console << kBold if self.cleanupCount > 0: console << kGreen << '\n%4.d missing items removed.' % self.cleanupCount if self.errCount > 0: console << kRed << '\n%4.d errors while cleaning up.' % self.errCount finally: console << kNormal << '\nDone.\n\n' finally: os.chdir(cwdbup)
def Run(self): cvs = Cvs(1) code, out, err = cvs.Run("--version") console = ColorConsole() lines = string.split(out, '\n') hasVersion = 0 for l in lines: if re.compile("^Concurrent Versions System").match(l): console << kRed << l << "\n" << kNormal hasVersion = 1 if re.compile(".*WinCVS.*").match(l): console << kBlue << l << "\n" << kNormal del console if not hasVersion: print out
def Run(self): """ Runs a CVS command on all selected items """ sel = App.GetSelection() searchVal = Persistent('PY_LogCommentSearchExpr', '', 1) answer, search = App.CvsPrompt(str(searchVal), 'Question', 'Enter search term.', \ '(multi-line, case-insensitive regular expression)', \ alertTitle='Locate in Log comments') if answer != 'IDOK': return searchVal << search cwdbup = os.getcwd() try: cvs = Cvs(1, 0) targets = [] prepareTargets(sel, targets) print 'Fetching log...' code, out, err = cvs.Run('log', *targets) if code == 0: self.searchLog(out, search, ColorConsole()) print '\nDone.' else: cvs_err(err) finally: os.chdir(cwdbup)
def DoFolder(self, path): numFound = 0 toRecurse = [] list = {} list["added"] = [] list["removed"] = [] list["modified"] = [] list["missing"] = [] list["conflict"] = [] # build a list of interesting files for this path entries = GetCvsEntriesList(path) for e in entries: if e.IsFile(): if e.IsRemoved(): list["removed"].append(e) numFound += 1 elif e.IsAdded(): list["added"].append(e) numFound += 1 elif e.IsModified(): if e.GetConflict() != "": list["conflict"].append(e) else: list["modified"].append(e) numFound += 1 elif e.IsMissing(): list["missing"].append(e) numFound += 1 elif not e.IsMissing() and not e.IsUnknown(): toRecurse.append(e.GetFullName()) # now print the list if len(list["added"]) > 0 or len(list["removed"]) > 0 or len( list["modified"]) > 0 or len(list["missing"]) > 0 or len( list["conflict"]) > 0: print "In %s :" % path console = ColorConsole() if len(list["conflict"]) > 0: console << kBold << "\tConflict files :" << kNormal << '\n' for e in list["conflict"]: console << kRed << "\t\t" << e.GetName() << kNormal << '\n' if len(list["added"]) > 0: console << "\tAdded files :" << '\n' for e in list["added"]: console << kMagenta << "\t\t" << e.GetName( ) << kNormal << '\n' if len(list["removed"]) > 0: console << "\tRemoved files :" << '\n' for e in list["removed"]: console << kMagenta << "\t\t" << e.GetName( ) << kNormal << '\n' if len(list["modified"]) > 0: console << "\tModified files :" << '\n' for e in list["modified"]: console << kMagenta << "\t\t" << e.GetName( ) << kNormal << '\n' if len(list["missing"]) > 0: console << kBold << "\tMissing files :" << kNormal << '\n' for e in list["missing"]: console << kRed << "\t\t" << e.GetName() << kNormal << '\n' # recurse for f in toRecurse: numFound += self.DoFolder(f) return numFound
def Run(self): console = ColorConsole() console << kRed << "This is red" << kBlue << " And this is blue\n" del console
def FixEntries(self, path, list): __doc__ = """Fix CVS/Entries file for parent directory path. For each entry in list (an entry is a two-tuple (cvs-entry, mod-time)), find the matching entry in path/CVS/Entries and edit the modification time to be mod_time.""" d = {} console = ColorConsole() for ent in list: d[ent[0].GetName()] = ent efname = path + '/CVS/Entries' push_tempdir = tempfile.gettempdir() tempfile.tempdir = path + '/CVS' outfname = tempfile.mktemp('.tmp') tempfile.tempdir = push_tempdir f_Entries = open(efname, 'r') f_out = open(outfname, 'w') r = re.compile( '^/(?P<fname>[^/]*)/(?P<rev>[^/]*)/(?P<date>[^/]*)/(?P<rest>.*)$') for line in f_Entries.xreadlines(): m = r.match(line) if m is not None: md = m.groupdict() if d.has_key(md['fname']): ent, modtime = d[md['fname']] ename = ent.GetName() mname = md['fname'] edate = ent.GetUTC() mdate = md['date'] if ename != mname: console << kRed << ( 'Internal error: "%s" does not match "%s".' % (ename, mname)) << kNormal << '\n' elif edate != mdate: console << kRed << ( 'Internal error: "%s" does not match "%s".' % (edate, mdate)) << kNormal << '\n' else: if _debugging: oldline = line line = '/' + md['fname'] + '/' + md[ 'rev'] + '/' + modtime + '/' + md['rest'] + '\n' if _debugging: console << kMagenta << 'Changing' << kRed << '\n\t' << oldline \ << kMagenta << 'to' << kBlue << '\n\t' << line f_out.write(line) f_Entries.close() f_out.close() if _debugging >= 2: os.rename(outfname, efname + '.new') else: # up to 20 backup files... # circular pool. If there are 20 files # of form Entries.000, .001, etc. # delete the oldest one and use that # for the current backup. xfbase = os.path.splitext(efname)[0] token = None for i in range(20): xfname = xfbase + '.%03d' % i # does the candidate name exist? if os.access(xfname, os.F_OK): mtime = os.stat(xfname)[8] if token is None or mtime < token[1]: token = (xfname, mtime) else: token = (xfname, 0) break if os.access(token[0], os.F_OK): os.unlink(token[0]) if _debugging: print 'Renaming "%s" --> "%s".' % (efname, token[0]) os.rename(efname, token[0]) if _debugging: print 'Renaming "%s" --> "%s".' % (outfname, efname) os.rename(outfname, efname)
def __init__(self): Macro.__init__(self, "", MACRO_SELECTION, 0, "Merge to other Branch") self.console = ColorConsole()