5 # tree2test.py - turn a directory tree into TestSCons code
7 # A quick script for importing directory hierarchies containing test
8 # cases that people supply (typically in a .zip or .tar.gz file) into a
9 # TestSCons.py script. No error checking or options yet, it just walks
10 # the first command-line argument (assumed to be the directory containing
11 # the test case) and spits out code looking like the following:
13 # test.subdir(['sub1'],
16 # test.write(['sub1', 'file1'], """\
20 # test.write(['sub1', 'sub2', 'file2'], """\
24 # There's no massaging of contents, so any files that themselves contain
25 # """ triple-quotes will need to have their contents edited by hand.
28 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
33 directory = sys.argv[1]
39 def __init__(self, path):
42 def call_for_each_entry(self, func):
43 entries = self.entries
44 names = entries.keys()
47 func(name, entries[name])
53 TopPath = dirname + os.sep
55 dirname = dirname.replace(TopPath, '')
56 dirs = dirname.split(os.sep)
60 node = t.entries[dirs[-1]] = Dir(dirs)
63 def make_nodes(arg, dirname, fnames):
68 def collect_dirs(l, dir):
74 dir.call_for_each_entry(recurse)
77 def print_a_file(n, d):
80 sys.stdout.write('\ntest.write(%s, """\\\n' % l)
81 p = os.path.join(*([directory] + l))
82 sys.stdout.write(open(p, 'r').read())
83 sys.stdout.write('""")\n')
84 dir.call_for_each_entry(print_a_file)
89 dir.call_for_each_entry(recurse)
91 os.path.walk(directory, make_nodes, None)
94 collect_dirs(subdir_list, Top)
95 subdir_list = [ str(l) for l in subdir_list ]
96 sys.stdout.write('test.subdir(' + ',\n '.join(subdir_list) + ')\n')
102 # indent-tabs-mode:nil
104 # vim: set expandtab tabstop=4 shiftwidth=4: