blob: 253ad2dce9aa2d8f5c23e4347b0044172655c797 [file] [log] [blame]
Guido van Rossum2fa5a7f1991-07-01 18:23:06 +00001#! /ufs/guido/bin/sgi/python
Guido van Rossumec758ea1991-06-04 20:36:54 +00002#! /usr/local/python
3
4# xxci
5#
6# check in files for which rcsdiff returns nonzero exit status
7
8import sys
9import posix
10import stat
11import path
12import commands
13
14MAXSIZE = 200*1024 # Files this big must be binaries and are skipped.
15
16def getargs():
17 args = sys.argv[1:]
18 if args:
19 return args
20 print 'No arguments, checking almost *'
21 for file in posix.listdir('.'):
22 if not skipfile(file):
23 args.append(file)
24 if not args:
25 print 'Nothing to do -- exit 1'
26 sys.exit(1)
27 args.sort()
28 return args
29
Guido van Rossum185d06e1991-06-04 20:44:11 +000030badnames = ['tags', 'TAGS', 'xyzzy', 'nohup.out', 'core']
Guido van Rossumec758ea1991-06-04 20:36:54 +000031badprefixes = ['.', ',', '@', '#', 'o.']
32badsuffixes = \
33 ['~', '.a', '.o', '.old', '.bak', '.orig', '.new', '.prev', '.not']
34# XXX Should generalize even more to use fnmatch!
35
36def skipfile(file):
37 if file in badnames or \
38 badprefix(file) or badsuffix(file) or \
39 path.islink(file) or path.isdir(file):
40 return 1
41 # Skip huge files -- probably binaries.
42 try:
43 st = posix.stat(file)
44 except posix.error:
45 return 1 # Doesn't exist -- skip it
46 return st[stat.ST_SIZE] >= MAXSIZE
47
48def badprefix(file):
49 for bad in badprefixes:
50 if file[:len(bad)] = bad: return 1
51 return 0
52
53def badsuffix(file):
54 for bad in badsuffixes:
55 if file[-len(bad):] = bad: return 1
56 return 0
57
58def go(args):
59 for file in args:
60 print file + ':'
Guido van Rossum2fa5a7f1991-07-01 18:23:06 +000061 if differing(file):
62 sts = posix.system('rcsdiff ' + file) # ignored
Guido van Rossumec758ea1991-06-04 20:36:54 +000063 if askyesno('Check in ' + file + ' ? '):
Guido van Rossum2fa5a7f1991-07-01 18:23:06 +000064 sts = posix.system('rcs -l ' + file) # ignored
Guido van Rossumec758ea1991-06-04 20:36:54 +000065 sts = posix.system('ci -l ' + file)
66
Guido van Rossum2fa5a7f1991-07-01 18:23:06 +000067def differing(file):
68 try:
69 this = open(file, 'r').read()
70 that = posix.popen('co -p '+file+' 2>/dev/null', 'r').read()
71 return this <> that
72 except:
73 return 1
Guido van Rossumec758ea1991-06-04 20:36:54 +000074
75def askyesno(prompt):
76 s = raw_input(prompt)
77 return s in ['y', 'yes']
78
79go(getargs())