[Cvsshell-devel] CVS: cvsshell/src cvs_cmds.py,1.25,1.26 cvs_shell.py,1.49,1.50 utils.py,1.17,1.18
Status: Beta
Brought to you by:
stefanheimann
From: Stefan H. <ste...@us...> - 2003-09-24 13:38:30
|
Update of /cvsroot/cvsshell/cvsshell/src In directory sc8-pr-cvs1:/tmp/cvs-serv19906/src Modified Files: cvs_cmds.py cvs_shell.py utils.py Log Message: added basic support for filtering based on status Index: cvs_cmds.py =================================================================== RCS file: /cvsroot/cvsshell/cvsshell/src/cvs_cmds.py,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** cvs_cmds.py 26 Apr 2003 12:49:58 -0000 1.25 --- cvs_cmds.py 24 Sep 2003 13:38:24 -0000 1.26 *************** *** 21,25 **** import os, re, string, getopt, utils ! from cvs_shell import CvsShell, Listing, Entry, CvsError, InternalCvsError from app import AppError --- 21,26 ---- import os, re, string, getopt, utils ! from cvs_shell import CvsShell, Listing, Entry, CvsError, InternalCvsError, \ ! createStatusFilter from app import AppError *************** *** 328,331 **** --- 329,339 ---- app.printErr(msg) return + # only commit regular files + commitFilenames = [] + for f in filenames: + if os.path.isfile(f): + commitFilenames.append(f) + if not commitFilenames: + return # answ = app.prompt("\nThe files have been scheduled for addition.\n" \ *************** *** 334,338 **** if answ == 'yes': try: ! args = app.getInitialLogmessageOption() + filenames app.runCvsCmd('commit', rootDir=toAddListing.getRootDir(), fork=0, args=args) --- 342,346 ---- if answ == 'yes': try: ! args = app.getInitialLogmessageOption() + commitFilenames app.runCvsCmd('commit', rootDir=toAddListing.getRootDir(), fork=0, args=args) *************** *** 586,589 **** --- 594,617 ---- def printListing(app, name, args): """Print out the current listing. + + You can filter the files by their status. The filter is specified by + giving the corresponding status letters as an optional argument to the + command. If the first letter is a `!', the following letters are + interpreted as statuses which should not be displayed. + + Examples: + + list MC + + displays only the modified and the files which have a conflict. The + status letters are case-insensitive. + + list ! ? + + displays all files which are not unknown to CVS. + + + Listing format: + --------------- The numbers on the left side of the listing are the IDs of the files. *************** *** 606,617 **** selects the files with the ids 3, 4, 7, 9, 10, 12, 19 ! The listing can be filtered by setting the variable `filter' in the ! CONFIG section of ~/.cvsshellrc. If the listing was produced by a cvs ! command like ``update'', the CVS filtering rules apply. If the listing ! was produced by a non-CVS command (for example with the builtin ! ``refresh'' command), only the filters in $CVSIGNORE, ~/.cvsignore and ! ./.cvsignore are considered. """ ! app.printListing() --- 634,655 ---- selects the files with the ids 3, 4, 7, 9, 10, 12, 19 ! You can hide files matching a specific pattern by setting the variable ! `filter' in the CONFIG section of ~/.cvsshellrc. If the listing was ! produced by a cvs command like ``update'', the CVS filtering rules ! apply as well. If the listing was produced by a non-CVS command (for ! example with the builtin ``refresh'' command), only the filters in ! $CVSIGNORE, ~/.cvsignore and ./.cvsignore are considered. """ ! n = len(args) ! if n == 0: ! app.printListing() ! else: ! s = ''.join(args) ! try: ! filter = createStatusFilter(s) ! app.printListing(statusFilter = filter) ! except ValueError, e: ! app.printErr(str(e)) ! Index: cvs_shell.py =================================================================== RCS file: /cvsroot/cvsshell/cvsshell/src/cvs_shell.py,v retrieving revision 1.49 retrieving revision 1.50 diff -C2 -d -r1.49 -r1.50 *** cvs_shell.py 4 Jun 2003 06:34:37 -0000 1.49 --- cvs_shell.py 24 Sep 2003 13:38:24 -0000 1.50 *************** *** 392,396 **** ! def printListing(self, footer=None): def refresh(): self.printMsg('getting listing from `' + self.cvsRoot + --- 392,396 ---- ! def printListing(self, footer=None, statusFilter=None): def refresh(): self.printMsg('getting listing from `' + self.cvsRoot + *************** *** 407,411 **** refresh() else: ! self.listing.printEntries(footer=footer) if self.getDirtyListing(): self.printMsg("Listing may be out-of-date. " \ --- 407,411 ---- refresh() else: ! self.listing.printEntries(footer=footer, statusFilter=statusFilter) if self.getDirtyListing(): self.printMsg("Listing may be out-of-date. " \ *************** *** 590,593 **** --- 590,594 ---- if not filter.filter(e.name): self.entries.append(e) + self.statusFilter = None def sortEntries(self): *************** *** 613,620 **** return None ! def printEntries(self, verbose=1, footer=None): if not self.entries: if verbose: self.app.printMsg('No entries available.') return maxStatus = 0 maxName = 0 --- 614,623 ---- return None ! def printEntries(self, verbose=1, footer=None, statusFilter=None): if not self.entries: if verbose: self.app.printMsg('No entries available.') return + if statusFilter is None: + statusFilter = self.statusFilter maxStatus = 0 maxName = 0 *************** *** 622,626 **** maxStatus = max(len(e.status), maxStatus) maxName = max(len(e.name), maxName) ! formatStr = " %%%dd %%-%ds %%s%%s" % (len(`len(self.entries)`), maxStatus) oldDir = None id = 0 --- 625,630 ---- maxStatus = max(len(e.status), maxStatus) maxName = max(len(e.name), maxName) ! formatStr = " %%%dd %%-%ds %%s%%s" % (len(`len(self.entries)`), ! maxStatus) oldDir = None id = 0 *************** *** 628,631 **** --- 632,636 ---- self.app.printMsg('Root Directory: ' + os.path.abspath(self.rootDir)) hidden = 0 + filtered = 0 for e in self.entries: if e.status == Entry.S_OK and not self.app.showUnmodified: *************** *** 633,636 **** --- 638,645 ---- id += 1 continue + if statusFilter is not None and e.status not in statusFilter: + filtered += 1 + id += 1 + continue newDir = e.dir if oldDir != newDir: *************** *** 650,654 **** lines.append(footer + '\n') if hidden: ! lines.append("%d files are unmodified.\nEnable the option `show-unmodified' to show these files.\n" % hidden) self.app.more(lines) --- 659,667 ---- lines.append(footer + '\n') if hidden: ! lines.append("%d files are unmodified.\n" \ ! "Enable the option `show-unmodified' to show " \ ! "these files.\n" % hidden) ! if filtered: ! lines.append('%d files are filtered\n' % filtered) self.app.more(lines) *************** *** 658,671 **** ############################## class Entry(GetSetProvider): ! S_ADDED = 'A' # file was added to the repository but has not been commited ! S_CONFLICT = 'C' # there is a conflict between the repository revision and the working revison S_MODIFIED = 'M' # file was locally modified S_PATCHED = 'P' # file was patched by the server ! S_REMOVED = 'R' # file has been scheduled for removal, but has not been commited S_UPDATED = 'U' # file was updated by the server S_UNKNOWN = '?' # status is unknown S_OK = 'OK' # file on the sandbox is in sync with repository S_DELETED = 'D' # removal has been commited to the repository statusToColorKey = None def __init__(self, dir, name, status, info=''): --- 671,725 ---- ############################## + def createStatusFilter(s): + """ + + Creates a list of entry statuses from the given string. The + string contains the letters of the statuses which should be + contained in the list. The case of the letters does not matter. + Raises ValueError if the string contains an unknown character. If + the first letter is a '!', the following letters are interpreted + as statuses which should not be included in the filter. + + """ + if len(s) == 0: + return [] + if s[0] == '!': + s = s[1:] + negative = 1 + else: + negative = 0 + s = s.upper() + for c in s: + if c not in Entry.statusList: + raise ValueError("Illegal status: %s" % c) + + if negative: + filter = Entry.statusList[:] # copy status list + for c in s: + utils.removeAll(filter, c) + else: + filter = [] + for c in s: + filter.append(c) + + return filter + + class Entry(GetSetProvider): ! S_ADDED = 'A' # file was added to the repository but has not been ! # commited ! S_CONFLICT = 'C' # there is a conflict between the repository revision ! # and the working revison S_MODIFIED = 'M' # file was locally modified S_PATCHED = 'P' # file was patched by the server ! S_REMOVED = 'R' # file has been scheduled for removal, but has not ! # been commited S_UPDATED = 'U' # file was updated by the server S_UNKNOWN = '?' # status is unknown S_OK = 'OK' # file on the sandbox is in sync with repository S_DELETED = 'D' # removal has been commited to the repository + statusList = [S_ADDED, S_CONFLICT, S_MODIFIED, S_PATCHED, S_REMOVED, + S_UPDATED, S_UNKNOWN, S_OK, S_DELETED] + statusToColorKey = None def __init__(self, dir, name, status, info=''): Index: utils.py =================================================================== RCS file: /cvsroot/cvsshell/cvsshell/src/utils.py,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** utils.py 21 Apr 2003 20:08:52 -0000 1.17 --- utils.py 24 Sep 2003 13:38:24 -0000 1.18 *************** *** 224,228 **** ! ############################## # Tests --- 224,233 ---- ! def removeAll(list, value): ! while 1: ! try: list.remove(value) ! except ValueError: break ! ! ############################## # Tests *************** *** 321,322 **** --- 326,328 ---- unittest.main() + |