home *** CD-ROM | disk | FTP | other *** search
/ PC World 2001 April / PCWorld_2001-04_cd.bin / Software / TemaCD / webclean / !!!python!!! / BeOpen-Python-2.0.exe / CVSFILES.PY < prev    next >
Encoding:
Python Source  |  2000-09-28  |  1.8 KB  |  73 lines

  1. #! /usr/bin/env python
  2.  
  3. """Print a list of files that are mentioned in CVS directories.
  4.  
  5. Usage: cvsfiles.py [-n file] [directory] ...
  6.  
  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. """
  12.  
  13. import os
  14. import sys
  15. import stat
  16. import getopt
  17. import string
  18.  
  19. cutofftime = 0
  20.  
  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(".")
  38.  
  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)
  64.  
  65. def getmtime(filename):
  66.     try:
  67.         st = os.stat(filename)
  68.     except os.error:
  69.         return 0
  70.     return st[stat.ST_MTIME]
  71.  
  72. sys.exit(main())
  73.