示例#1
0
 def Checkout(self, event=None):
     idx, module, prefix = self.GetSelection()
     cvs = Cvs(0, 0)
     cwdbup = os.getcwd()
     try:
         dlgTitle = 'Checkout module ' + module
         answer, targetDir = App.CvsPrompt(cwdbup,
                                           'Question',
                                           'Checkout to:',
                                           alertTitle=dlgTitle)
         if answer == 'IDOK':
             p_args = Persistent('PY_RListCOArgs', '', 1)
             answer, args = App.CvsPrompt(str(p_args),
                                          'Question',
                                          'Additional Checkout arguments:',
                                          alertTitle=dlgTitle)
             if answer == 'IDOK':
                 p_args << args
                 args = string.split(args)
                 args.append(module)
                 os.chdir(targetDir)
                 args = ['-q', 'checkout'] + args
                 if self.cvsroot.get():
                     args.insert(0, '-d' + self.cvsroot.get())
                 print 'cvs %s (in %s)' % (string.join(args), os.getcwd())
                 cvs.Run(*args)
     finally:
         os.chdir(cwdbup)
         self.master.destroy()
示例#2
0
 def Run(self):
     cwdbup = os.getcwd()
     try:
         cvs = Cvs(1, 0)
         msg = 'Enter the name of the %s you wish to create:' % self.cmdname
         title = self.cmdname + ' and Update'
         answer, branch = App.CvsPrompt('',
                                        'Question',
                                        msg,
                                        alertTitle=title)
         if (answer == 'IDOK') and len(branch) > 0:
             args = []
             prepareTargets(self.sel, args)
             print 'Creating %s "%s" on selection...' % (self.cmdname,
                                                         branch)
             cmdargs = ['-q', 'tag'] + self.cmdoptions + [branch
                                                          ] + args  #'-c',
             #print '\tcvs %s (in %s)'%(string.join(cmdargs), os.getcwd())
             code, out, err = cvs.Run(*cmdargs)
             if code == 0:
                 print 'Updating selection to %s "%s"...' % (self.cmdname,
                                                             branch)
                 #print '\tcvs -q update -r%s %s (in %s)'%(branch, string.join(args), os.getcwd())
                 code, out, err = cvs.Run('-q', 'up', '-r' + branch, *args)
                 if code == 0:
                     print 'Done.'
                 else:
                     print 'Update failed!'
                     print err
             else:
                 print self.cmdname + ' creation failed!'
                 print err
     finally:
         os.chdir(cwdbup)
示例#3
0
    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
示例#4
0
    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)
示例#5
0
def runCvs(args):
    if asMacro:
        cvs = Cvs(1, 0)
        return cvs.Run(*args)
    else:
        f_in, f_out, f_err = os.popen3('cvs ' + string.join(args))
        out = f_out.read()
        err = f_err.read()
        f_out.close()
        f_err.close()
        code = f_in.close()
        if not code: code = 0
        return code, out, err
示例#6
0
    def DoIt(self, autoCommitOptions):
        folderCount = 0
        fileCount = 0
        commitCount = 0
        try:
            cvs = Cvs(1, 0)
            #create batches grouped by parent folder and kmode
            batches = {}
            print 'reorganizing file list...'
            for ext, item in self.items.items():
                kmode = item[KMODE].get()
                if not kmode == 'i':
                    for file in item[FILES]:
                        parent, filename = os.path.split(file)
                        if parent not in batches:
                            batches[parent] = {}
                        if kmode not in batches[parent]:
                            batches[parent][kmode] = []
                        batches[parent][kmode].append(filename)

            #run batches:
            print 'adding files and folders...'
            for dir, batch in batches.items():
                #ensure folder is added already:
                if not os.path.exists(os.path.join(dir, 'CVS')):
                    folderCount += self.addFolder(dir, cvs)

                os.chdir(dir)

                for kmode, files in batch.items():
                    cvsArgs = files
                    if kmode.strip() <> '':  # != KModes[3]:
                        cvsArgs = [kmode] + cvsArgs
                    #print 'cvs add %s (in %s)\n\n' % (string.join( cvsArgs), os.getcwd())
                    code, out, err = cvs.Run('add', *cvsArgs)
                    if code == 0:
                        fileCount += len(files)
                        if autoCommitOptions.autoCommit:
                            commitCount += self.commitFiles(
                                files, autoCommitOptions, cvs)
                    else:
                        cvs_err(err + '\n\n')
                        cvs_err('Commandline was:\ncvs add %s (in %s)\n\n' %
                                (string.join(cvsArgs), os.getcwd()))

        finally:
            print 'Added %d folders and %d files' % (folderCount, fileCount)
            if autoCommitOptions.autoCommit:
                print 'Committed %d files' % commitCount
示例#7
0
    def addSel(self, kmode):
        cwdbup = os.getcwd()
        try:
            cvs = Cvs(1, 0)
            targets = []
            basedir = prepareTargets(self.sel, targets, 0)
            os.chdir(basedir)
            code, out, err = cvs.Run('add', kmode, *targets)
            if code == 0:
                print 'Done'
            else:
                print err

        finally:
            os.chdir(cwdbup)
	def Run(self):
		sel = cvsgui.App.GetSelection()
		cvs = Cvs()
		list = ("update", "-A")
		for s in sel:
			if os.access(self._tempName(s.GetName()), os.F_OK):
				os.unlink(self._tempName(s.GetName()))
			os.rename(s.GetName(), self._tempName(s.GetName()))
			list = list + (s.GetName(),)
		cvs.Run(*list)
		for s in sel:
			if os.access(s.GetName(), os.F_OK):
				os.unlink(s.GetName())
			os.rename(self._tempName(s.GetName()), s.GetName())
		return 0;
示例#9
0
  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.'
示例#10
0
    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
示例#11
0
    def Run(self):
        sel = cvsgui.App.GetSelection()

        entry = sel[0]

        root, ext = os.path.splitext(entry.GetName())
        if ext != "":
            ign = "*" + ext
        else:
            ign = root

        msg = "Add '%s' to .cvsignore ?" % ign
        title = "Add to .cvsignore"
        answer, ign = cvsgui.App.CvsPrompt(ign,
                                           'Question',
                                           msg,
                                           alertTitle=title)
        if (answer != 'IDOK') or len(ign) == 0:
            return

        cvsignore = os.path.join(entry.GetPath(), ".cvsignore")
        createIgnore = 0
        if not os.path.isfile(cvsignore):
            createIgnore = 1

        if createIgnore:
            msg = "Create and add '%s' to the sandbox ?" % cvsignore
            title = "Create .cvsignore"
            if cvsgui.App.CvsAlert('Question', msg, 'Yes', 'No', '', '',
                                   title) != 'IDOK':
                return

        fd = open(cvsignore, "a+")
        entries = fd.readlines()
        entries.append(ign + "\n")
        fd.truncate(0)
        fd.writelines(entries)
        fd.close()

        if createIgnore:
            cvs = Cvs()
            dirname, filename = os.path.split(cvsignore)
            os.chdir(dirname)
            code, out, err = cvs.Run("add", filename)
示例#12
0
 def getHelp(self):
     res = ''
     code, out, err = Cvs(1, 0).Run('up', '-k?')
     if code == 1:
         lines = err.splitlines()
         for line in lines[1:]:
             #print '"%s" "%s"' % (line[1], line[1:3])
             if (line[:3] <> 'cvs') and (line[:8] <> '(Specify'):
                 res += line + '\n'
     return res
示例#13
0
    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
示例#14
0
    def doStuff(self):
        """ Runs a CVS command on all selected items """
        cwdbup = os.getcwd()
        try:
            cvs = Cvs(1, 0)
            targets = []
            prepareTargets(App.GetSelection(), targets)

            #substitute 'command' and 'myargs' with your actual cvs command
            # and arguments, e.g.
            #   code, out, err = cvs.Run('update', '-d yesterday', '-C', *targets)

            code, out, err = cvs.Run('command', 'myargs', *targets)
            if code == 0:
                print 'Done.'
            else:
                cvs_err(err)
        finally:
            os.chdir(cwdbup)
示例#15
0
    def Run(self):
        cwdbup = os.getcwd()
        try:
            cvs = Cvs(1, 0)
            args = []
            prepareTargets(self.sel, args)
            path = self.sel[0].GetPath()
            branch = self.getDirTag(path)

            # validate selection:
            if not branch:
                cvs_err('Not on a branch.\n')
                return

            for entry in self.sel:
                if entry.GetVersion().count('.') > 1:
                    cvs_err('%s is already branched!\n' % entry.GetFullName())
                    return
                if entry.GetPath() <> path:
                    path = entry.GetPath()
                    if self.getDirTag(path) <> branch:
                        cvs_err('All files have to be on the same branch.\n')
                        return

            print 'Updating to HEAD'
            code, out, err = cvs.Run('up', '-A', *args)
            if code == 0:
                if out: print out
                print 'Moving branchpoint'
                code, out, err = cvs.Run('tag', '-bBF', branch, *args)
            if code == 0:
                if out: print out
                print 'Updating back to branch'
                code, out, err = cvs.Run('up', '-r' + branch, *args)
            if code == 0:
                if out: print out
                print 'Done.\n'
            else:
                cvs_err(err)
        finally:
            os.chdir(cwdbup)
示例#16
0
    def changeKopt(self, kopt, commitMsg):
        """ Changes the k-option on all selected files. """
        sel = App.GetSelection()
        ok = 1
        for entry in sel:
            if entry.GetKeyword() <> self.sel0kopt:
                # should be "Warning":
                ok = CvsAlert('Question', 'Selection contains files with different options!', \
                              'Change options of all selected files anyway?', \
                              'Yes', 'No', '', '', 'Change File Options') == 'IDOK'
                break

        if ok:
            cwdbup = os.getcwd()
            try:
                cvs = Cvs(1, 0)
                targets = []
                prepareTargets(sel, targets)

                print 'Registering option change...'
                code, out, err = cvs.Run('admin', kopt, *targets)
                if (code == 0) and (not err) or (
                        err.find('admin -k no longer affects') < 0):
                    print 'Updating sandbox...'
                    code, out, err = cvs.Run('update', kopt, *targets)
                    if (code == 0) and (commitMsg <> ''):
                        print 'Committing option change...'
                        code, out, err = cvs.Run('commit', '-m' + commitMsg,
                                                 '-f', *targets)
                    if code == 0:
                        print 'Done.\n'

                if code <> 0:
                    cvs_err(err)
            finally:
                os.chdir(cwdbup)
        else:
            cvs_err('Aborted by user.\n\n')
示例#17
0
    def Run(self):
        cwdbup = os.getcwd()
        try:
            cvs = Cvs(1, 0)
            args = []
            code = 1
            err = 'Failed.'
            prepareTargets(self.sel, args)

            try:
                if self.backupFiles(args):
                    print 'Retrieving up-to-date files from repository...'
                    code, out, err = cvs.Run('update', *args)
                    if code == 0:
                        self.removeFiles(args)
            finally:
                self.restoreFiles(args)

            if code == 0:
                print 'Done.'
            else:
                print err
        finally:
            os.chdir(cwdbup)
示例#18
0
    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)
示例#19
0
def getModuleList(root, module='.', rev='HEAD', tmpdir=None):
    def fakeCvsDir(tmpdir, root, repo):
        def writeToFile(file, line):
            f_file = open(file, 'w')
            try:
                f_file.write(line)
            finally:
                f_file.close()

        cvsDir = os.path.join(tmpdir, 'CVS')
        if not os.path.exists(cvsDir):
            os.makedirs(os.path.join(cvsDir, 'CVS'))
        writeToFile(os.path.join(cvsDir, 'Root'), root)
        writeToFile(os.path.join(cvsDir, 'Repository'), repo)
        writeToFile(os.path.join(cvsDir, 'Entries'), '\n')

    result = []
    if tmpdir == None:
        tmpdir = os.path.join(tempfile.gettempdir(), 'cvsrlist')
    fakeCvsDir(tmpdir, root, module)
    cvs = Cvs(1, 0)
    cwdbup = os.getcwd()
    try:
        os.chdir(tmpdir)
        code, out, err = cvs.Run('-n', 'up', '-d', '-r' + rev)
        if code == 0 and err:
            rex = re.compile("New directory \`([^\']+)\' \-\- ignored")
            for line in err.split('\n'):
                m_module = rex.search(line)
                if m_module:
                    result.append(m_module.group(1))
    finally:
        os.chdir(cwdbup)
        if os.path.exists(tmpdir):
            shutil.rmtree(tmpdir)
        return result
示例#20
0
 def Run(self):
     dir = self.sel[0].GetFullName()
     answer, filename = App.CvsPrompt('', 'Question', 'Enter the name of the file to be resurrected.', \
                                      alertTitle='Resurrect File')
     if answer == 'IDOK':
         print 'Resurrection of ' + os.path.join(dir, filename)
         if not os.path.exists(os.path.join(dir, filename)):
             tag = self.determineBranch(dir)
             if tag:
                 os.chdir(dir)
                 self.cvs = Cvs(1, 0)
                 try:
                     ok, deadrev, aliverev = self.determineRevisions(
                         filename, tag)
                     if ok:
                         self.resurrectFile(filename, deadrev, aliverev)
                 finally:
                     del self.cvs
         else:
             print 'File already exists. Nothing to do.'