summaryrefslogtreecommitdiffstats
path: root/src/boost/tools/build/test/load_dir.py
blob: 1b082b1c6cb9d4945df16f087460b0037fc4cea8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/python

"""
Traverses a directory and output the code that would create the same directory
structure during testing. Assumes that the instance of Tester is called 't'.
"""

from __future__ import print_function

import sys
import os
import stat
import string

def usage():
    print("usage: load_dir.py directory")


def remove_first_component(path):
    result = [path]
    while 1:
        s = os.path.split(result[0])
        if not s[0]:
            break
        result[:1] = list(s)
    return os.path.join(*result[1:])


def create_file(arg, dirname, fnames):
    for n in fnames:
        path = os.path.join(dirname, n)
        if not os.path.isdir(path):
            print("t.write(\"%s\", \"\"\"" % (remove_first_component(path),),)
            f = open(path, "r")
            for l in f:
                print(l)
            print('\n""")\n')


header = """#!/usr/bin/python

#  Copyright (C) FILL SOMETHING HERE 2005.
#  Distributed under the Boost Software License, Version 1.0. (See
#  accompanying file LICENSE_1_0.txt or copy at
#  http://www.boost.org/LICENSE_1_0.txt)

import BoostBuild

t = BoostBuild.Tester()
"""

footer = """

t.run_build_system()

t.expect_addition("bin/$toolset/debug*/FILL_SOME_HERE.exe")

t.cleanup()
"""


def main():
    if len(sys.argv) != 2:
        usage()
    else:
        path = sys.argv[1]

        if not os.access(path, os.F_OK):
            print("Path '%s' does not exist" % (path,))
            sys.exit(1)

        if not os.path.isdir(path):
            print("Path '%s' is not a directory" % (path,))

        print(header)

        for root, _, files in os.walk(path):
            create_file(None, root, files)

        print(footer)


if __name__ == '__main__':
    main()