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