Mercurial > cpython-lru_cache-weakref
annotate Tools/scripts/xxci.py @ 5817:48b94de85bf3 legacy-trunk
Extensive changes by AMK.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Thu, 17 Jul 1997 16:29:42 +0000 |
| parents | 73758db2f464 |
| children | 14a27acc755a |
| rev | line source |
|---|---|
|
4573
73758db2f464
/usr/local/bin/python -> /usr/bin/env python
Guido van Rossum <guido@python.org>
parents:
1506
diff
changeset
|
1 #! /usr/bin/env python |
| 274 | 2 |
| 3 # xxci | |
| 4 # | |
| 5 # check in files for which rcsdiff returns nonzero exit status | |
| 6 | |
| 7 import sys | |
| 755 | 8 import os |
|
682
7544ebac5698
Use fnmatch; read ".xxcign" for additional patterns to ignore.
Guido van Rossum <guido@python.org>
parents:
559
diff
changeset
|
9 from stat import * |
| 274 | 10 import commands |
|
682
7544ebac5698
Use fnmatch; read ".xxcign" for additional patterns to ignore.
Guido van Rossum <guido@python.org>
parents:
559
diff
changeset
|
11 import fnmatch |
|
7544ebac5698
Use fnmatch; read ".xxcign" for additional patterns to ignore.
Guido van Rossum <guido@python.org>
parents:
559
diff
changeset
|
12 import string |
| 274 | 13 |
|
503
e14d46440ea7
Better check to avoid executables.
Guido van Rossum <guido@python.org>
parents:
299
diff
changeset
|
14 EXECMAGIC = '\001\140\000\010' |
|
e14d46440ea7
Better check to avoid executables.
Guido van Rossum <guido@python.org>
parents:
299
diff
changeset
|
15 |
| 274 | 16 MAXSIZE = 200*1024 # Files this big must be binaries and are skipped. |
| 17 | |
| 18 def getargs(): | |
| 19 args = sys.argv[1:] | |
| 20 if args: | |
| 21 return args | |
|
682
7544ebac5698
Use fnmatch; read ".xxcign" for additional patterns to ignore.
Guido van Rossum <guido@python.org>
parents:
559
diff
changeset
|
22 print 'No arguments, checking almost *, in "ls -t" order' |
|
7544ebac5698
Use fnmatch; read ".xxcign" for additional patterns to ignore.
Guido van Rossum <guido@python.org>
parents:
559
diff
changeset
|
23 list = [] |
| 755 | 24 for file in os.listdir(os.curdir): |
| 274 | 25 if not skipfile(file): |
|
682
7544ebac5698
Use fnmatch; read ".xxcign" for additional patterns to ignore.
Guido van Rossum <guido@python.org>
parents:
559
diff
changeset
|
26 list.append((getmtime(file), file)) |
|
7544ebac5698
Use fnmatch; read ".xxcign" for additional patterns to ignore.
Guido van Rossum <guido@python.org>
parents:
559
diff
changeset
|
27 list.sort() |
|
7544ebac5698
Use fnmatch; read ".xxcign" for additional patterns to ignore.
Guido van Rossum <guido@python.org>
parents:
559
diff
changeset
|
28 if not list: |
| 274 | 29 print 'Nothing to do -- exit 1' |
| 30 sys.exit(1) | |
|
682
7544ebac5698
Use fnmatch; read ".xxcign" for additional patterns to ignore.
Guido van Rossum <guido@python.org>
parents:
559
diff
changeset
|
31 list.sort() |
|
7544ebac5698
Use fnmatch; read ".xxcign" for additional patterns to ignore.
Guido van Rossum <guido@python.org>
parents:
559
diff
changeset
|
32 list.reverse() |
|
7544ebac5698
Use fnmatch; read ".xxcign" for additional patterns to ignore.
Guido van Rossum <guido@python.org>
parents:
559
diff
changeset
|
33 for mtime, file in list: args.append(file) |
| 274 | 34 return args |
| 35 | |
|
682
7544ebac5698
Use fnmatch; read ".xxcign" for additional patterns to ignore.
Guido van Rossum <guido@python.org>
parents:
559
diff
changeset
|
36 def getmtime(file): |
|
7544ebac5698
Use fnmatch; read ".xxcign" for additional patterns to ignore.
Guido van Rossum <guido@python.org>
parents:
559
diff
changeset
|
37 try: |
| 755 | 38 st = os.stat(file) |
|
682
7544ebac5698
Use fnmatch; read ".xxcign" for additional patterns to ignore.
Guido van Rossum <guido@python.org>
parents:
559
diff
changeset
|
39 return st[ST_MTIME] |
| 755 | 40 except os.error: |
|
682
7544ebac5698
Use fnmatch; read ".xxcign" for additional patterns to ignore.
Guido van Rossum <guido@python.org>
parents:
559
diff
changeset
|
41 return -1 |
|
7544ebac5698
Use fnmatch; read ".xxcign" for additional patterns to ignore.
Guido van Rossum <guido@python.org>
parents:
559
diff
changeset
|
42 |
|
275
80001c023b2b
Added to list of bad filenames.
Guido van Rossum <guido@python.org>
parents:
274
diff
changeset
|
43 badnames = ['tags', 'TAGS', 'xyzzy', 'nohup.out', 'core'] |
| 274 | 44 badprefixes = ['.', ',', '@', '#', 'o.'] |
| 45 badsuffixes = \ | |
|
503
e14d46440ea7
Better check to avoid executables.
Guido van Rossum <guido@python.org>
parents:
299
diff
changeset
|
46 ['~', '.a', '.o', '.old', '.bak', '.orig', '.new', '.prev', '.not', \ |
| 1300 | 47 '.pyc', '.fdc', '.rgb', '.elc', ',v'] |
|
871
22169fcc1182
Change the way ignore is assigned to
Guido van Rossum <guido@python.org>
parents:
755
diff
changeset
|
48 ignore = [] |
|
682
7544ebac5698
Use fnmatch; read ".xxcign" for additional patterns to ignore.
Guido van Rossum <guido@python.org>
parents:
559
diff
changeset
|
49 |
|
7544ebac5698
Use fnmatch; read ".xxcign" for additional patterns to ignore.
Guido van Rossum <guido@python.org>
parents:
559
diff
changeset
|
50 def setup(): |
|
871
22169fcc1182
Change the way ignore is assigned to
Guido van Rossum <guido@python.org>
parents:
755
diff
changeset
|
51 ignore[:] = badnames |
|
682
7544ebac5698
Use fnmatch; read ".xxcign" for additional patterns to ignore.
Guido van Rossum <guido@python.org>
parents:
559
diff
changeset
|
52 for p in badprefixes: |
|
7544ebac5698
Use fnmatch; read ".xxcign" for additional patterns to ignore.
Guido van Rossum <guido@python.org>
parents:
559
diff
changeset
|
53 ignore.append(p + '*') |
|
7544ebac5698
Use fnmatch; read ".xxcign" for additional patterns to ignore.
Guido van Rossum <guido@python.org>
parents:
559
diff
changeset
|
54 for p in badsuffixes: |
|
7544ebac5698
Use fnmatch; read ".xxcign" for additional patterns to ignore.
Guido van Rossum <guido@python.org>
parents:
559
diff
changeset
|
55 ignore.append('*' + p) |
|
7544ebac5698
Use fnmatch; read ".xxcign" for additional patterns to ignore.
Guido van Rossum <guido@python.org>
parents:
559
diff
changeset
|
56 try: |
|
7544ebac5698
Use fnmatch; read ".xxcign" for additional patterns to ignore.
Guido van Rossum <guido@python.org>
parents:
559
diff
changeset
|
57 f = open('.xxcign', 'r') |
|
7544ebac5698
Use fnmatch; read ".xxcign" for additional patterns to ignore.
Guido van Rossum <guido@python.org>
parents:
559
diff
changeset
|
58 except IOError: |
|
7544ebac5698
Use fnmatch; read ".xxcign" for additional patterns to ignore.
Guido van Rossum <guido@python.org>
parents:
559
diff
changeset
|
59 return |
|
871
22169fcc1182
Change the way ignore is assigned to
Guido van Rossum <guido@python.org>
parents:
755
diff
changeset
|
60 ignore[:] = ignore + string.split(f.read()) |
| 274 | 61 |
| 62 def skipfile(file): | |
|
682
7544ebac5698
Use fnmatch; read ".xxcign" for additional patterns to ignore.
Guido van Rossum <guido@python.org>
parents:
559
diff
changeset
|
63 for p in ignore: |
|
7544ebac5698
Use fnmatch; read ".xxcign" for additional patterns to ignore.
Guido van Rossum <guido@python.org>
parents:
559
diff
changeset
|
64 if fnmatch.fnmatch(file, p): return 1 |
| 274 | 65 try: |
| 755 | 66 st = os.lstat(file) |
| 67 except os.error: | |
| 274 | 68 return 1 # Doesn't exist -- skip it |
|
682
7544ebac5698
Use fnmatch; read ".xxcign" for additional patterns to ignore.
Guido van Rossum <guido@python.org>
parents:
559
diff
changeset
|
69 # Skip non-plain files. |
|
7544ebac5698
Use fnmatch; read ".xxcign" for additional patterns to ignore.
Guido van Rossum <guido@python.org>
parents:
559
diff
changeset
|
70 if not S_ISREG(st[ST_MODE]): return 1 |
|
7544ebac5698
Use fnmatch; read ".xxcign" for additional patterns to ignore.
Guido van Rossum <guido@python.org>
parents:
559
diff
changeset
|
71 # Skip huge files -- probably binaries. |
|
7544ebac5698
Use fnmatch; read ".xxcign" for additional patterns to ignore.
Guido van Rossum <guido@python.org>
parents:
559
diff
changeset
|
72 if st[ST_SIZE] >= MAXSIZE: return 1 |
|
503
e14d46440ea7
Better check to avoid executables.
Guido van Rossum <guido@python.org>
parents:
299
diff
changeset
|
73 # Skip executables |
|
e14d46440ea7
Better check to avoid executables.
Guido van Rossum <guido@python.org>
parents:
299
diff
changeset
|
74 try: |
|
e14d46440ea7
Better check to avoid executables.
Guido van Rossum <guido@python.org>
parents:
299
diff
changeset
|
75 data = open(file, 'r').read(len(EXECMAGIC)) |
| 559 | 76 if data == EXECMAGIC: return 1 |
|
503
e14d46440ea7
Better check to avoid executables.
Guido van Rossum <guido@python.org>
parents:
299
diff
changeset
|
77 except: |
|
e14d46440ea7
Better check to avoid executables.
Guido van Rossum <guido@python.org>
parents:
299
diff
changeset
|
78 pass |
|
e14d46440ea7
Better check to avoid executables.
Guido van Rossum <guido@python.org>
parents:
299
diff
changeset
|
79 return 0 |
| 274 | 80 |
| 81 def badprefix(file): | |
| 82 for bad in badprefixes: | |
| 559 | 83 if file[:len(bad)] == bad: return 1 |
| 274 | 84 return 0 |
| 85 | |
| 86 def badsuffix(file): | |
| 87 for bad in badsuffixes: | |
| 559 | 88 if file[-len(bad):] == bad: return 1 |
| 274 | 89 return 0 |
| 90 | |
| 91 def go(args): | |
| 92 for file in args: | |
| 93 print file + ':' | |
|
299
f7090f5814c2
Use posix.popen to read output from a command instead if command.get*.
Guido van Rossum <guido@python.org>
parents:
275
diff
changeset
|
94 if differing(file): |
| 755 | 95 showdiffs(file) |
| 274 | 96 if askyesno('Check in ' + file + ' ? '): |
| 755 | 97 sts = os.system('rcs -l ' + file) # ignored |
| 98 sts = os.system('ci -l ' + file) | |
| 274 | 99 |
|
299
f7090f5814c2
Use posix.popen to read output from a command instead if command.get*.
Guido van Rossum <guido@python.org>
parents:
275
diff
changeset
|
100 def differing(file): |
| 755 | 101 cmd = 'co -p ' + file + ' 2>/dev/null | cmp -s - ' + file |
| 102 sts = os.system(cmd) | |
| 103 return sts != 0 | |
| 104 | |
| 105 def showdiffs(file): | |
| 106 cmd = 'rcsdiff ' + file + ' 2>&1 | ${PAGER-more}' | |
| 107 sts = os.system(cmd) | |
| 274 | 108 |
| 109 def askyesno(prompt): | |
| 110 s = raw_input(prompt) | |
| 111 return s in ['y', 'yes'] | |
| 112 | |
|
1103
fcaafd5ec695
Friendlier response to interrupt. Use /usr/local/*bin*/python.
Guido van Rossum <guido@python.org>
parents:
1077
diff
changeset
|
113 try: |
|
fcaafd5ec695
Friendlier response to interrupt. Use /usr/local/*bin*/python.
Guido van Rossum <guido@python.org>
parents:
1077
diff
changeset
|
114 setup() |
|
fcaafd5ec695
Friendlier response to interrupt. Use /usr/local/*bin*/python.
Guido van Rossum <guido@python.org>
parents:
1077
diff
changeset
|
115 go(getargs()) |
|
fcaafd5ec695
Friendlier response to interrupt. Use /usr/local/*bin*/python.
Guido van Rossum <guido@python.org>
parents:
1077
diff
changeset
|
116 except KeyboardInterrupt: |
|
fcaafd5ec695
Friendlier response to interrupt. Use /usr/local/*bin*/python.
Guido van Rossum <guido@python.org>
parents:
1077
diff
changeset
|
117 print '[Intr]' |
