cvsfiles.py 1.75 KB
Newer Older
1 2
#! /usr/bin/env python

3 4 5 6 7 8 9 10 11
"""Print a list of files that are mentioned in CVS directories.

Usage: cvsfiles.py [-n file] [directory] ...

If the '-n file' option is given, only files under CVS that are newer
than the given file are printed; by default, all files under CVS are
printed.  As a special case, if a file does not exist, it is always
printed.
"""
12 13 14

import os
import sys
15 16
import stat
import getopt
17

18 19
cutofftime = 0

20
def main():
21
    try:
Guido van Rossum's avatar
Guido van Rossum committed
22
        opts, args = getopt.getopt(sys.argv[1:], "n:")
23
    except getopt.error, msg:
Guido van Rossum's avatar
Guido van Rossum committed
24 25 26
        print msg
        print __doc__,
        return 1
27 28 29
    global cutofftime
    newerfile = None
    for o, a in opts:
Guido van Rossum's avatar
Guido van Rossum committed
30 31
        if o == '-n':
            cutofftime = getmtime(a)
32
    if args:
Guido van Rossum's avatar
Guido van Rossum committed
33 34
        for arg in args:
            process(arg)
35
    else:
Guido van Rossum's avatar
Guido van Rossum committed
36
        process(".")
37 38 39 40 41 42

def process(dir):
    cvsdir = 0
    subdirs = []
    names = os.listdir(dir)
    for name in names:
Guido van Rossum's avatar
Guido van Rossum committed
43 44 45 46 47 48 49
        fullname = os.path.join(dir, name)
        if name == "CVS":
            cvsdir = fullname
        else:
            if os.path.isdir(fullname):
                if not os.path.islink(fullname):
                    subdirs.append(fullname)
50
    if cvsdir:
Guido van Rossum's avatar
Guido van Rossum committed
51 52
        entries = os.path.join(cvsdir, "Entries")
        for e in open(entries).readlines():
53
            words = e.split('/')
Guido van Rossum's avatar
Guido van Rossum committed
54 55 56 57 58 59 60
            if words[0] == '' and words[1:]:
                name = words[1]
                fullname = os.path.join(dir, name)
                if cutofftime and getmtime(fullname) <= cutofftime:
                    pass
                else:
                    print fullname
61
    for sub in subdirs:
Guido van Rossum's avatar
Guido van Rossum committed
62
        process(sub)
63

64 65
def getmtime(filename):
    try:
Guido van Rossum's avatar
Guido van Rossum committed
66
        st = os.stat(filename)
67
    except os.error:
Guido van Rossum's avatar
Guido van Rossum committed
68
        return 0
69 70
    return st[stat.ST_MTIME]

71 72
if __name__ == '__main__':
    main()