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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6642
diff changeset
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
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6642
diff changeset
25 print msg
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6642
diff changeset
26 print __doc__,
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6642
diff changeset
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
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6642
diff changeset
31 if o == '-n':
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6642
diff changeset
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
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6642
diff changeset
34 for arg in args:
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6642
diff changeset
35 process(arg)
6033
ac7554f29313 Print a list of files under CVS.
Guido van Rossum <guido@python.org>
parents:
diff changeset
36 else:
7735
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6642
diff changeset
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
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6642
diff changeset
44 fullname = os.path.join(dir, name)
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6642
diff changeset
45 if name == "CVS":
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6642
diff changeset
46 cvsdir = fullname
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6642
diff changeset
47 else:
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6642
diff changeset
48 if os.path.isdir(fullname):
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6642
diff changeset
49 if not os.path.islink(fullname):
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6642
diff changeset
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
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6642
diff changeset
52 entries = os.path.join(cvsdir, "Entries")
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6642
diff changeset
53 for e in open(entries).readlines():
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6642
diff changeset
54 words = string.split(e, '/')
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6642
diff changeset
55 if words[0] == '' and words[1:]:
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6642
diff changeset
56 name = words[1]
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6642
diff changeset
57 fullname = os.path.join(dir, name)
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6642
diff changeset
58 if cutofftime and getmtime(fullname) <= cutofftime:
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6642
diff changeset
59 pass
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6642
diff changeset
60 else:
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6642
diff changeset
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
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6642
diff changeset
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
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6642
diff changeset
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
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6642
diff changeset
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())