Added 'description' class attribute to every command class (to help the
[python/dscho.git] / Tools / scripts / cvsfiles.py
blobd133a40fd81fe6c038e0c20a7fc29fb48a12cd67
1 #! /usr/bin/env python
3 """Print a list of files that are mentioned in CVS directories.
5 Usage: cvsfiles.py [-n file] [directory] ...
7 If the '-n file' option is given, only files under CVS that are newer
8 than the given file are printed; by default, all files under CVS are
9 printed. As a special case, if a file does not exist, it is always
10 printed.
11 """
13 import os
14 import sys
15 import stat
16 import getopt
17 import string
19 cutofftime = 0
21 def main():
22 try:
23 opts, args = getopt.getopt(sys.argv[1:], "n:")
24 except getopt.error, msg:
25 print msg
26 print __doc__,
27 return 1
28 global cutofftime
29 newerfile = None
30 for o, a in opts:
31 if o == '-n':
32 cutofftime = getmtime(a)
33 if args:
34 for arg in args:
35 process(arg)
36 else:
37 process(".")
39 def process(dir):
40 cvsdir = 0
41 subdirs = []
42 names = os.listdir(dir)
43 for name in names:
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)
51 if cvsdir:
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
62 for sub in subdirs:
63 process(sub)
65 def getmtime(filename):
66 try:
67 st = os.stat(filename)
68 except os.error:
69 return 0
70 return st[stat.ST_MTIME]
72 sys.exit(main())