[Cvsshell-devel] CVS: cvsshell/src basic_cmds.py,1.1.1.1,1.2
Status: Beta
Brought to you by:
stefanheimann
From: Stefan H. <ste...@us...> - 2002-03-07 10:37:37
|
Update of /cvsroot/cvsshell/cvsshell/src In directory usw-pr-cvs1:/tmp/cvs-serv28018 Modified Files: basic_cmds.py Log Message: added support for status Index: basic_cmds.py =================================================================== RCS file: /cvsroot/cvsshell/cvsshell/src/basic_cmds.py,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** basic_cmds.py 7 Mar 2002 00:03:22 -0000 1.1.1.1 --- basic_cmds.py 7 Mar 2002 10:37:35 -0000 1.2 *************** *** 62,66 **** os.path.expanduser(opts) try: ! os.chdir(opts) except OSError, msg: app.printErr(msg) --- 62,66 ---- os.path.expanduser(opts) try: ! _cd(opts) except OSError, msg: app.printErr(msg) *************** *** 75,85 **** def status(name, args, context): - # FIXME status with args should also be possible app = context['APP'] entries = [] ! regexHead = re.compile(r'File: (?P<file>\S+)\s+Status: (?P<status>\S+)') regexDir = re.compile(r'.*Examining (?P<dir>\S+)') ! # problem: information about directories are printed ! # on stderr!! def update(name, args, context, simulate=0): --- 75,113 ---- def status(name, args, context): app = context['APP'] entries = [] ! regexHead = re.compile(r'File: (?P<name>\S+)\s+Status: (?P<status>.+)') regexDir = re.compile(r'.*Examining (?P<dir>\S+)') ! regexUnknown = re.compile(r'^\?\s+(?P<filename>\S+)') ! try: ! lines = _runCvsCmd(context, 'status', args=args, getStderr=1) ! except CvsError: return ! entries = [] ! dir = None ! for line in lines: ! unknownRes = regexUnknown.search(line) ! if unknownRes: ! name = os.path.basename(unknownRes.group('filename')) ! dir = os.path.dirname(unknownRes.group('filename')) ! entries.append(utils.Entry(dir, name, utils.Entry.S_UNKNOWN)) ! continue ! headRes = regexHead.search(line) ! if headRes and dir is None: ! raise InternalCvsError, "Parsing of status message failed: " \ ! "`dir' is not set when get file information." ! elif headRes: ! name = headRes.group('name') ! status = headRes.group('status').strip() ! entries.append(utils.Entry(dir, name, status)) ! continue ! dirRes = regexDir.search(line) ! if dirRes: ! dir = dirRes.group('dir') ! if dir == '.': dir = '' ! l = context['basic_cmds.listing'] = utils.Listing(os.getcwd(), ! entries) ! context['basic_cmds.dirty_listing'] = 0 ! l.sortEntries() ! _printListing(context) def update(name, args, context, simulate=0): *************** *** 89,94 **** try: lines = _runCvsCmd(context, 'update', globOpts=globOpts, args=args) ! except CvsError: ! return entries = [] for line in lines: --- 117,121 ---- try: lines = _runCvsCmd(context, 'update', globOpts=globOpts, args=args) ! except CvsError: return entries = [] for line in lines: *************** *** 98,104 **** dir = os.path.dirname(x[1]) entries.append(utils.Entry(dir, name, status)) ! context['basic_cmds.listing'] = utils.Listing(os.getcwd(), ! entries) context['basic_cmds.dirty_listing'] = 0 _printListing(context) --- 125,132 ---- dir = os.path.dirname(x[1]) entries.append(utils.Entry(dir, name, status)) ! l = context['basic_cmds.listing'] = utils.Listing(os.getcwd(), ! entries) context['basic_cmds.dirty_listing'] = 0 + l.sortEntries() _printListing(context) *************** *** 114,118 **** else: module = args[0] ! _runCvsCmd(context, 'checkout', args=module) def add(name, args, context): --- 142,148 ---- else: module = args[0] ! try: ! _runCvsCmd(context, 'checkout', args=module) ! except CvsError: pass def add(name, args, context): *************** *** 121,148 **** args = app.prompt('enter filenumbers to add: ') if args is None: return - filenames = [] def __doIt(e,filename): - filenames.append(filename) e.status = utils.Entry.S_ADDED ! _applyOnEntryList(args, context, __doIt) if filenames: ! _runCvsCmd(context, 'add', args=utils.list2string(filenames)) def commit(name, args, context): app = context['APP'] if args == '': ! _runCvsCmd(context, 'commit', fork=1) ! context['basic_cmds.dirty_listing'] = 1 return - filenames = [] def __doIt(e,filename): - filenames.append(filename) if e.status == utils.Entry.S_REMOVED: e.status = utils.Entry.S_DELETED else: e.status = utils.Entry.S_OK ! _applyOnEntryList(args, context, __doIt) if filenames: ! _runCvsCmd(context, 'commit', args=utils.list2string(filenames), fork=1) def remove(name, args, context): --- 151,190 ---- args = app.prompt('enter filenumbers to add: ') if args is None: return def __doIt(e,filename): e.status = utils.Entry.S_ADDED ! return filename ! (rootDir, filenames) = _applyOnEntryList(args, context, __doIt) if filenames: ! try: ! _runCvsCmd(context, 'add', rootDir=rootDir, args=utils.list2string(filenames)) ! except CvsError: pass ! try: os.chdir(oldDir) ! except OSError, msg: app.printErr(msg) def commit(name, args, context): app = context['APP'] if args == '': ! try: ! _runCvsCmd(context, 'commit', rootDir=rootDir, fork=1) ! context['basic_cmds.dirty_listing'] = 1 ! except CvsError: pass return def __doIt(e,filename): if e.status == utils.Entry.S_REMOVED: e.status = utils.Entry.S_DELETED else: e.status = utils.Entry.S_OK ! return filename ! (rootDir, filenames) = _applyOnEntryList(args, context, __doIt) if filenames: ! try: oldDir = os.chdir(rootDir) ! except OSError,msg: ! app.printErr("Could not change to the root directory of the current listing: %s" % str(msg)) ! return ! try: ! _runCvsCmd(context, 'commit', rootDir=rootDir, args=utils.list2string(filenames), fork=1) ! except CvsError: pass ! try: os.chdir(oldDir) ! except OSError, msg: app.printErr(msg) def remove(name, args, context): *************** *** 151,160 **** args = app.prompt('enter filenumbers to remove: ') if args is None: return - toDelete = [] def __doIt(e,filename): ! toDelete.append(e) ! _applyOnEntryList(args, context, __doIt) ! listing = context['basic_cmds.listing'] ! toDeleteList = utils.Listing(listing.rootDir, toDelete) filenames = [] for e in toDeleteList.entries: --- 193,200 ---- args = app.prompt('enter filenumbers to remove: ') if args is None: return def __doIt(e,filename): ! return filename ! (rootDir, toDelete) = _applyOnEntryList(args, context, __doIt) ! toDeleteList = utils.Listing(rootDir, toDelete) filenames = [] for e in toDeleteList.entries: *************** *** 169,173 **** if filenames: args = utils.list2string(filenames) ! _runCvsCmd(context, 'remove', args=args) toDeleteList.printEntries(app.output) answ = app.prompt("\nThe files have been scheduled for removal.\n" \ --- 209,215 ---- if filenames: args = utils.list2string(filenames) ! try: ! _runCvsCmd(context, 'remove', rootDir=rootDir, args=args) ! except CvsError: return toDeleteList.printEntries(app.output) answ = app.prompt("\nThe files have been scheduled for removal.\n" \ *************** *** 177,181 **** for e in toDeleteList.entries: e.status = utils.Entry.S_DELETED ! _runCvsCmd(context, 'commit', fork=1, args=args) def printListing(name, args, context): --- 219,223 ---- for e in toDeleteList.entries: e.status = utils.Entry.S_DELETED ! _runCvsCmd(context, 'commit', rootDir=rootDir, fork=1, args=args) def printListing(name, args, context): *************** *** 240,244 **** def _applyOnEntryList(opts, context, fun): """fun must take 2 argument as the entry and its ! filename is passed to it.""" app = context['APP'] try: --- 282,287 ---- def _applyOnEntryList(opts, context, fun): """fun must take 2 argument as the entry and its ! filename is passed to it. Returns a tuple ! (rootdir of listing, list with the return values from fun).""" app = context['APP'] try: *************** *** 255,266 **** app.printErr(noListingErrMsg) return for x in nums: e = listing.entries[x] ! name = os.path.join(listing.rootDir, e.dir, e.name) ! fun(e,name) ! def _runCvsCmd(context, cmd, globOpts = '', opts='', args='', fork=0): """ * cmd is the command to execute * globOpts are global options passed by a function. These options override the default global options --- 298,313 ---- app.printErr(noListingErrMsg) return + result = [] for x in nums: e = listing.entries[x] ! name = os.path.join(e.dir, e.name) ! result.append(fun(e,name)) ! return listing.rootDir, result ! ! def _runCvsCmd(context, cmd, rootDir=None, globOpts = '', opts='', args='', fork=0, getStderr=0): """ * cmd is the command to execute + * rootDir is the directory the command should be executed in * globOpts are global options passed by a function. These options override the default global options *************** *** 272,275 **** --- 319,331 ---- """ app = context['APP'] + + oldDir = None + if rootDir is not None: + try: + oldDir = os.chdir(rootDir) + except OSError,msg: + app.printErr("Could not change to the root directory of the current listing: %s" % str(msg)) + raise CvsError + defGlobOpts,defOpts = _getOptions(context,cmd) userGlobOpts, userOpts = _splitOpts(args) *************** *** 284,287 **** --- 340,344 ---- cmd = 'cvs %s %s %s' % (globOpts, cmd, opts) + if getStderr: cmd += ' 2>&1' app.printVMsg(cmd) if not fork: *************** *** 297,300 **** --- 354,364 ---- raise CvsError + if oldDir is not None: + try: + os.chdir(oldDir) + except OSError,msg: + app.printErr(msg) + + def _isDirtyListing(context): try: *************** *** 364,367 **** --- 428,437 ---- # Helper functions ############################## + + def _cd(dir): + """Changes the current working directory. Returns the old directory.""" + oldDir = os.getcwd() + os.chdir(dir) + return oldDir def _splitOpts(args): |