Mercurial > cpython-lru_cache-weakref
annotate Tools/scripts/cvsfiles.py @ 25838:8540887bcec6 2.2
Backport of 2.183:
Fix memory leak in add_subclass() found by NealN with valgrind.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Fri, 18 Oct 2002 13:42:21 +0000 |
| parents | 7a9afaba88d8 |
| children | 8a7a2f1f88f0 |
| rev | line source |
|---|---|
|
6033
ac7554f29313
Print a list of files under CVS.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1 #! /usr/bin/env python |
|
ac7554f29313
Print a list of files under CVS.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
2 |
|
6642
2518ac9251f0
Added "-n file" option to only print files newer than the given file.
Guido van Rossum <guido@python.org>
parents:
6320
diff
changeset
|
3 """Print a list of files that are mentioned in CVS directories. |
|
2518ac9251f0
Added "-n file" option to only print files newer than the given file.
Guido van Rossum <guido@python.org>
parents:
6320
diff
changeset
|
4 |
|
2518ac9251f0
Added "-n file" option to only print files newer than the given file.
Guido van Rossum <guido@python.org>
parents:
6320
diff
changeset
|
5 Usage: cvsfiles.py [-n file] [directory] ... |
|
2518ac9251f0
Added "-n file" option to only print files newer than the given file.
Guido van Rossum <guido@python.org>
parents:
6320
diff
changeset
|
6 |
|
2518ac9251f0
Added "-n file" option to only print files newer than the given file.
Guido van Rossum <guido@python.org>
parents:
6320
diff
changeset
|
7 If the '-n file' option is given, only files under CVS that are newer |
|
2518ac9251f0
Added "-n file" option to only print files newer than the given file.
Guido van Rossum <guido@python.org>
parents:
6320
diff
changeset
|
8 than the given file are printed; by default, all files under CVS are |
|
2518ac9251f0
Added "-n file" option to only print files newer than the given file.
Guido van Rossum <guido@python.org>
parents:
6320
diff
changeset
|
9 printed. As a special case, if a file does not exist, it is always |
|
2518ac9251f0
Added "-n file" option to only print files newer than the given file.
Guido van Rossum <guido@python.org>
parents:
6320
diff
changeset
|
10 printed. |
|
2518ac9251f0
Added "-n file" option to only print files newer than the given file.
Guido van Rossum <guido@python.org>
parents:
6320
diff
changeset
|
11 """ |
|
6033
ac7554f29313
Print a list of files under CVS.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
12 |
|
ac7554f29313
Print a list of files under CVS.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
13 import os |
|
ac7554f29313
Print a list of files under CVS.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
14 import sys |
|
6642
2518ac9251f0
Added "-n file" option to only print files newer than the given file.
Guido van Rossum <guido@python.org>
parents:
6320
diff
changeset
|
15 import stat |
|
2518ac9251f0
Added "-n file" option to only print files newer than the given file.
Guido van Rossum <guido@python.org>
parents:
6320
diff
changeset
|
16 import getopt |
|
6033
ac7554f29313
Print a list of files under CVS.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
17 import string |
|
ac7554f29313
Print a list of files under CVS.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
18 |
|
6642
2518ac9251f0
Added "-n file" option to only print files newer than the given file.
Guido van Rossum <guido@python.org>
parents:
6320
diff
changeset
|
19 cutofftime = 0 |
|
2518ac9251f0
Added "-n file" option to only print files newer than the given file.
Guido van Rossum <guido@python.org>
parents:
6320
diff
changeset
|
20 |
|
6033
ac7554f29313
Print a list of files under CVS.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
21 def main(): |
|
6642
2518ac9251f0
Added "-n file" option to only print files newer than the given file.
Guido van Rossum <guido@python.org>
parents:
6320
diff
changeset
|
22 try: |
| 7735 | 23 opts, args = getopt.getopt(sys.argv[1:], "n:") |
|
6642
2518ac9251f0
Added "-n file" option to only print files newer than the given file.
Guido van Rossum <guido@python.org>
parents:
6320
diff
changeset
|
24 except getopt.error, msg: |
| 7735 | 25 print msg |
| 26 print __doc__, | |
| 27 return 1 | |
|
6642
2518ac9251f0
Added "-n file" option to only print files newer than the given file.
Guido van Rossum <guido@python.org>
parents:
6320
diff
changeset
|
28 global cutofftime |
|
2518ac9251f0
Added "-n file" option to only print files newer than the given file.
Guido van Rossum <guido@python.org>
parents:
6320
diff
changeset
|
29 newerfile = None |
|
2518ac9251f0
Added "-n file" option to only print files newer than the given file.
Guido van Rossum <guido@python.org>
parents:
6320
diff
changeset
|
30 for o, a in opts: |
| 7735 | 31 if o == '-n': |
| 32 cutofftime = getmtime(a) | |
|
6033
ac7554f29313
Print a list of files under CVS.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
33 if args: |
| 7735 | 34 for arg in args: |
| 35 process(arg) | |
|
6033
ac7554f29313
Print a list of files under CVS.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
36 else: |
| 7735 | 37 process(".") |
|
6033
ac7554f29313
Print a list of files under CVS.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
38 |
|
ac7554f29313
Print a list of files under CVS.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
39 def process(dir): |
|
ac7554f29313
Print a list of files under CVS.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
40 cvsdir = 0 |
|
ac7554f29313
Print a list of files under CVS.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
41 subdirs = [] |
|
ac7554f29313
Print a list of files under CVS.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
42 names = os.listdir(dir) |
|
ac7554f29313
Print a list of files under CVS.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
43 for name in names: |
| 7735 | 44 fullname = os.path.join(dir, name) |
| 45 if name == "CVS": | |
| 46 cvsdir = fullname | |
| 47 else: | |
| 48 if os.path.isdir(fullname): | |
| 49 if not os.path.islink(fullname): | |
| 50 subdirs.append(fullname) | |
|
6033
ac7554f29313
Print a list of files under CVS.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
51 if cvsdir: |
| 7735 | 52 entries = os.path.join(cvsdir, "Entries") |
| 53 for e in open(entries).readlines(): | |
| 54 words = string.split(e, '/') | |
| 55 if words[0] == '' and words[1:]: | |
| 56 name = words[1] | |
| 57 fullname = os.path.join(dir, name) | |
| 58 if cutofftime and getmtime(fullname) <= cutofftime: | |
| 59 pass | |
| 60 else: | |
| 61 print fullname | |
|
6033
ac7554f29313
Print a list of files under CVS.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
62 for sub in subdirs: |
| 7735 | 63 process(sub) |
|
6033
ac7554f29313
Print a list of files under CVS.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
64 |
|
6642
2518ac9251f0
Added "-n file" option to only print files newer than the given file.
Guido van Rossum <guido@python.org>
parents:
6320
diff
changeset
|
65 def getmtime(filename): |
|
2518ac9251f0
Added "-n file" option to only print files newer than the given file.
Guido van Rossum <guido@python.org>
parents:
6320
diff
changeset
|
66 try: |
| 7735 | 67 st = os.stat(filename) |
|
6642
2518ac9251f0
Added "-n file" option to only print files newer than the given file.
Guido van Rossum <guido@python.org>
parents:
6320
diff
changeset
|
68 except os.error: |
| 7735 | 69 return 0 |
|
6642
2518ac9251f0
Added "-n file" option to only print files newer than the given file.
Guido van Rossum <guido@python.org>
parents:
6320
diff
changeset
|
70 return st[stat.ST_MTIME] |
|
2518ac9251f0
Added "-n file" option to only print files newer than the given file.
Guido van Rossum <guido@python.org>
parents:
6320
diff
changeset
|
71 |
|
2518ac9251f0
Added "-n file" option to only print files newer than the given file.
Guido van Rossum <guido@python.org>
parents:
6320
diff
changeset
|
72 sys.exit(main()) |
