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 for name
in sorted(self
.entries
.keys()):
44 func(name
, self
.entries
[name
])
50 TopPath
= dirname
+ os
.sep
52 dirname
= dirname
.replace(TopPath
, '')
53 dirs
= dirname
.split(os
.sep
)
57 node
= t
.entries
[dirs
[-1]] = Dir(dirs
)
60 def collect_dirs(l
, dir):
66 dir.call_for_each_entry(recurse
)
69 def print_a_file(n
, d
):
72 sys
.stdout
.write('\ntest.write(%s, """\\\n' % l
)
73 p
= os
.path
.join(directory
, *l
)
74 sys
.stdout
.write(open(p
, 'r').read())
75 sys
.stdout
.write('""")\n')
76 dir.call_for_each_entry(print_a_file
)
81 dir.call_for_each_entry(recurse
)
83 for dirpath
, dirnames
, filenames
in os
.walk(directory
):
89 collect_dirs(subdir_list
, Top
)
90 subdir_list
= [ str(l
) for l
in subdir_list
]
91 sys
.stdout
.write('test.subdir(' + ',\n '.join(subdir_list
) + ')\n')
97 # indent-tabs-mode:nil
99 # vim: set expandtab tabstop=4 shiftwidth=4: