1#! /usr/bin/env python 2 3"""Print a list of files that are mentioned in CVS directories. 4 5Usage: cvsfiles.py [-n file] [directory] ... 6 7If the '-n file' option is given, only files under CVS that are newer 8than the given file are printed; by default, all files under CVS are 9printed. As a special case, if a file does not exist, it is always 10printed. 11""" 12 13import os 14import sys 15import stat 16import getopt 17 18cutofftime = 0 19 20def main(): 21 try: 22 opts, args = getopt.getopt(sys.argv[1:], "n:") 23 except getopt.error, msg: 24 print msg 25 print __doc__, 26 return 1 27 global cutofftime 28 newerfile = None 29 for o, a in opts: 30 if o == '-n': 31 cutofftime = getmtime(a) 32 if args: 33 for arg in args: 34 process(arg) 35 else: 36 process(".") 37 38def process(dir): 39 cvsdir = 0 40 subdirs = [] 41 names = os.listdir(dir) 42 for name in names: 43 fullname = os.path.join(dir, name) 44 if name == "CVS": 45 cvsdir = fullname 46 else: 47 if os.path.isdir(fullname): 48 if not os.path.islink(fullname): 49 subdirs.append(fullname) 50 if cvsdir: 51 entries = os.path.join(cvsdir, "Entries") 52 for e in open(entries).readlines(): 53 words = e.split('/') 54 if words[0] == '' and words[1:]: 55 name = words[1] 56 fullname = os.path.join(dir, name) 57 if cutofftime and getmtime(fullname) <= cutofftime: 58 pass 59 else: 60 print fullname 61 for sub in subdirs: 62 process(sub) 63 64def getmtime(filename): 65 try: 66 st = os.stat(filename) 67 except os.error: 68 return 0 69 return st[stat.ST_MTIME] 70 71if __name__ == '__main__': 72 main() 73