]> git.saurik.com Git - wxWidgets.git/blame - wxPython/distrib/genfilelist.py
added tech note about writing unit tests
[wxWidgets.git] / wxPython / distrib / genfilelist.py
CommitLineData
1e4a197e
RD
1"""
2Walk a directory tree and output a filename list suitable for use
3in an RPM spec.
4
5Usage: genfilelist.py [-r] build_root filespec(s)
6
7"""
8
9
10import sys, os, glob, stat
11
12
13def walktree(names, buildroot, recurse):
14 for name in names:
15 isdir = os.path.isdir(name)
16 printfilename(name, buildroot, isdir)
17 if isdir and recurse:
18 walktree([os.path.join(name, x) for x in os.listdir(name)], buildroot, recurse)
19
20
21def printfilename(name, buildroot, isdir):
22 s = os.lstat(name)
23 realname = name[len(buildroot):]
24 if isdir:
25 fmt = "%%dir %%attr(%o, root, root) %s"
26 else:
27 fmt = "%%attr(%o, root, root) %s"
28 print fmt % (s[stat.ST_MODE] & 0777, realname)
29
30
31def main(args):
32 if args[0] == '-r':
33 recurse = 1
34 args = args[1:]
35 else:
36 recurse = 0
37
38 if len(args) < 2:
39 print __str__
40 sys.exit(1)
41
42 buildroot = args[0]
43 for arg in args[1:]:
44 if arg[0] == '/':
45 arg = arg[1:]
46 walktree(glob.glob(os.path.join(buildroot, arg)), buildroot, recurse)
47
48if __name__ == "__main__":
49 main(sys.argv[1:])
50
51