]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | #!/usr/bin/python |
2 | ||
3 | """ | |
4 | Traverses a directory and output the code that would create the same directory | |
5 | structure during testing. Assumes that the instance of Tester is called 't'. | |
6 | """ | |
7 | ||
92f5a8d4 TL |
8 | from __future__ import print_function |
9 | ||
7c673cae FG |
10 | import sys |
11 | import os | |
12 | import stat | |
13 | import string | |
14 | ||
15 | def usage(): | |
92f5a8d4 | 16 | print("usage: load_dir.py directory") |
7c673cae FG |
17 | |
18 | ||
19 | def remove_first_component(path): | |
20 | result = [path] | |
21 | while 1: | |
22 | s = os.path.split(result[0]) | |
23 | if not s[0]: | |
24 | break | |
25 | result[:1] = list(s) | |
92f5a8d4 | 26 | return os.path.join(*result[1:]) |
7c673cae FG |
27 | |
28 | ||
29 | def create_file(arg, dirname, fnames): | |
30 | for n in fnames: | |
31 | path = os.path.join(dirname, n) | |
32 | if not os.path.isdir(path): | |
92f5a8d4 | 33 | print("t.write(\"%s\", \"\"\"" % (remove_first_component(path),),) |
7c673cae FG |
34 | f = open(path, "r") |
35 | for l in f: | |
92f5a8d4 TL |
36 | print(l) |
37 | print('\n""")\n') | |
7c673cae FG |
38 | |
39 | ||
40 | header = """#!/usr/bin/python | |
41 | ||
42 | # Copyright (C) FILL SOMETHING HERE 2005. | |
43 | # Distributed under the Boost Software License, Version 1.0. (See | |
1e59de90 TL |
44 | # accompanying file LICENSE.txt or copy at |
45 | # https://www.bfgroup.xyz/b2/LICENSE.txt) | |
7c673cae FG |
46 | |
47 | import BoostBuild | |
48 | ||
49 | t = BoostBuild.Tester() | |
50 | """ | |
51 | ||
52 | footer = """ | |
53 | ||
54 | t.run_build_system() | |
55 | ||
b32b8144 | 56 | t.expect_addition("bin/$toolset/debug*/FILL_SOME_HERE.exe") |
7c673cae FG |
57 | |
58 | t.cleanup() | |
59 | """ | |
60 | ||
61 | ||
62 | def main(): | |
63 | if len(sys.argv) != 2: | |
64 | usage() | |
65 | else: | |
66 | path = sys.argv[1] | |
67 | ||
68 | if not os.access(path, os.F_OK): | |
92f5a8d4 | 69 | print("Path '%s' does not exist" % (path,)) |
7c673cae FG |
70 | sys.exit(1) |
71 | ||
72 | if not os.path.isdir(path): | |
92f5a8d4 | 73 | print("Path '%s' is not a directory" % (path,)) |
7c673cae | 74 | |
92f5a8d4 | 75 | print(header) |
7c673cae | 76 | |
92f5a8d4 TL |
77 | for root, _, files in os.walk(path): |
78 | create_file(None, root, files) | |
7c673cae | 79 | |
92f5a8d4 | 80 | print(footer) |
7c673cae FG |
81 | |
82 | ||
83 | if __name__ == '__main__': | |
84 | main() |