blob: e747c8dbac4b5354d330eccf022a1e543a5263f7 [file] [log] [blame]
Guido van Rossumec758ea1991-06-04 20:36:54 +00001#! /usr/local/python
2
3# xxci
4#
5# check in files for which rcsdiff returns nonzero exit status
6
7import sys
8import posix
9import stat
10import path
11import commands
12
13MAXSIZE = 200*1024 # Files this big must be binaries and are skipped.
14
15def 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
29badnames = ['tags', 'xyzzy']
30badprefixes = ['.', ',', '@', '#', 'o.']
31badsuffixes = \
32 ['~', '.a', '.o', '.old', '.bak', '.orig', '.new', '.prev', '.not']
33# XXX Should generalize even more to use fnmatch!
34
35def 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
47def badprefix(file):
48 for bad in badprefixes:
49 if file[:len(bad)] = bad: return 1
50 return 0
51
52def badsuffix(file):
53 for bad in badsuffixes:
54 if file[-len(bad):] = bad: return 1
55 return 0
56
57def 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
66def 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
73def askyesno(prompt):
74 s = raw_input(prompt)
75 return s in ['y', 'yes']
76
77go(getargs())