blob: ef4ff11d9b2a01073447697003646a1025c097c5 [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
Guido van Rossum97dddba1991-12-18 13:39:16 +000014EXECMAGIC = '\001\140\000\010'
15
Guido van Rossumec758ea1991-06-04 20:36:54 +000016MAXSIZE = 200*1024 # Files this big must be binaries and are skipped.
17
18def getargs():
19 args = sys.argv[1:]
20 if args:
21 return args
22 print 'No arguments, checking almost *'
23 for file in posix.listdir('.'):
24 if not skipfile(file):
25 args.append(file)
26 if not args:
27 print 'Nothing to do -- exit 1'
28 sys.exit(1)
29 args.sort()
30 return args
31
Guido van Rossum185d06e1991-06-04 20:44:11 +000032badnames = ['tags', 'TAGS', 'xyzzy', 'nohup.out', 'core']
Guido van Rossumec758ea1991-06-04 20:36:54 +000033badprefixes = ['.', ',', '@', '#', 'o.']
34badsuffixes = \
Guido van Rossum97dddba1991-12-18 13:39:16 +000035 ['~', '.a', '.o', '.old', '.bak', '.orig', '.new', '.prev', '.not', \
36 '.pyc', '.elc']
Guido van Rossumec758ea1991-06-04 20:36:54 +000037# XXX Should generalize even more to use fnmatch!
38
39def skipfile(file):
40 if file in badnames or \
41 badprefix(file) or badsuffix(file) or \
42 path.islink(file) or path.isdir(file):
43 return 1
44 # Skip huge files -- probably binaries.
45 try:
46 st = posix.stat(file)
47 except posix.error:
48 return 1 # Doesn't exist -- skip it
Guido van Rossum97dddba1991-12-18 13:39:16 +000049 if st[stat.ST_SIZE] >= MAXSIZE: return 1
50 # Skip executables
51 try:
52 data = open(file, 'r').read(len(EXECMAGIC))
53 if data = EXECMAGIC: return 1
54 except:
55 pass
56 return 0
Guido van Rossumec758ea1991-06-04 20:36:54 +000057
58def badprefix(file):
59 for bad in badprefixes:
60 if file[:len(bad)] = bad: return 1
61 return 0
62
63def badsuffix(file):
64 for bad in badsuffixes:
65 if file[-len(bad):] = bad: return 1
66 return 0
67
68def go(args):
69 for file in args:
70 print file + ':'
Guido van Rossum2fa5a7f1991-07-01 18:23:06 +000071 if differing(file):
72 sts = posix.system('rcsdiff ' + file) # ignored
Guido van Rossumec758ea1991-06-04 20:36:54 +000073 if askyesno('Check in ' + file + ' ? '):
Guido van Rossum2fa5a7f1991-07-01 18:23:06 +000074 sts = posix.system('rcs -l ' + file) # ignored
Guido van Rossumec758ea1991-06-04 20:36:54 +000075 sts = posix.system('ci -l ' + file)
76
Guido van Rossum2fa5a7f1991-07-01 18:23:06 +000077def differing(file):
78 try:
79 this = open(file, 'r').read()
80 that = posix.popen('co -p '+file+' 2>/dev/null', 'r').read()
81 return this <> that
82 except:
83 return 1
Guido van Rossumec758ea1991-06-04 20:36:54 +000084
85def askyesno(prompt):
86 s = raw_input(prompt)
87 return s in ['y', 'yes']
88
89go(getargs())