Guido van Rossum | ec758ea | 1991-06-04 20:36:54 +0000 | [diff] [blame] | 1 | #! /usr/local/python |
| 2 | |
| 3 | # xxci |
| 4 | # |
| 5 | # check in files for which rcsdiff returns nonzero exit status |
| 6 | |
| 7 | import sys |
| 8 | import posix |
| 9 | import stat |
| 10 | import path |
| 11 | import commands |
| 12 | |
| 13 | MAXSIZE = 200*1024 # Files this big must be binaries and are skipped. |
| 14 | |
| 15 | def getargs(): |
| 16 | args = sys.argv[1:] |
| 17 | if args: |
| 18 | return args |
| 19 | print 'No arguments, checking almost *' |
| 20 | for file in posix.listdir('.'): |
| 21 | if not skipfile(file): |
| 22 | args.append(file) |
| 23 | if not args: |
| 24 | print 'Nothing to do -- exit 1' |
| 25 | sys.exit(1) |
| 26 | args.sort() |
| 27 | return args |
| 28 | |
Guido van Rossum | 185d06e | 1991-06-04 20:44:11 +0000 | [diff] [blame^] | 29 | badnames = ['tags', 'TAGS', 'xyzzy', 'nohup.out', 'core'] |
Guido van Rossum | ec758ea | 1991-06-04 20:36:54 +0000 | [diff] [blame] | 30 | badprefixes = ['.', ',', '@', '#', 'o.'] |
| 31 | badsuffixes = \ |
| 32 | ['~', '.a', '.o', '.old', '.bak', '.orig', '.new', '.prev', '.not'] |
| 33 | # XXX Should generalize even more to use fnmatch! |
| 34 | |
| 35 | def skipfile(file): |
| 36 | if file in badnames or \ |
| 37 | badprefix(file) or badsuffix(file) or \ |
| 38 | path.islink(file) or path.isdir(file): |
| 39 | return 1 |
| 40 | # Skip huge files -- probably binaries. |
| 41 | try: |
| 42 | st = posix.stat(file) |
| 43 | except posix.error: |
| 44 | return 1 # Doesn't exist -- skip it |
| 45 | return st[stat.ST_SIZE] >= MAXSIZE |
| 46 | |
| 47 | def badprefix(file): |
| 48 | for bad in badprefixes: |
| 49 | if file[:len(bad)] = bad: return 1 |
| 50 | return 0 |
| 51 | |
| 52 | def badsuffix(file): |
| 53 | for bad in badsuffixes: |
| 54 | if file[-len(bad):] = bad: return 1 |
| 55 | return 0 |
| 56 | |
| 57 | def go(args): |
| 58 | for file in args: |
| 59 | print file + ':' |
| 60 | if run('rcsdiff -c', file): |
| 61 | if askyesno('Check in ' + file + ' ? '): |
| 62 | sts = run('rcs -l', file) # ignored |
| 63 | # can't use run() here because it's interactive |
| 64 | sts = posix.system('ci -l ' + file) |
| 65 | |
| 66 | def run(cmd, file): |
| 67 | sts, output = commands.getstatusoutput(cmd + commands.mkarg(file)) |
| 68 | if sts: |
| 69 | print output |
| 70 | print 'Exit status', sts |
| 71 | return sts |
| 72 | |
| 73 | def askyesno(prompt): |
| 74 | s = raw_input(prompt) |
| 75 | return s in ['y', 'yes'] |
| 76 | |
| 77 | go(getargs()) |