/Tools/scripts/cvsfiles.py

http://unladen-swallow.googlecode.com/ · Python · 72 lines · 66 code · 1 blank · 5 comment · 0 complexity · 07ad9391c96df479db16c612c40994eb MD5 · raw file

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