load_dir.py

来自「Boost provides free peer-reviewed portab」· Python 代码 · 共 82 行

PY
82
字号
#!/usr/bin/python"""Traverses a directory and output the code that would create the same directorystructure during testing. Assumes that the instance of Tester is called 't'."""import sysimport osimport statimport stringdef 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 apply(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 BoostBuildt = 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        os.path.walk(path, create_file, None)        print footerif __name__ == '__main__':    main()

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?