diff options
author | Rob Austein <sra@hactrn.net> | 2013-02-25 03:58:36 +0000 |
---|---|---|
committer | Rob Austein <sra@hactrn.net> | 2013-02-25 03:58:36 +0000 |
commit | d2bb943731ec492941e367fc9c399a1c9fd89e11 (patch) | |
tree | a9be1eba3ac2748649a0c78333c9b4165e70e745 /buildtools/wrap-tree.py | |
parent | b033927cf90652a52ce2d71d95a4572527602d8f (diff) | |
parent | 10408f676d398b1961d24daf360d42f79b8ecfc5 (diff) |
Merge platform-specific packaging changes back to trunk. Closes #377,
#374, #395, #398. Also see #373, which ended up not being covered by
this branch after all.
svn path=/trunk/; revision=5065
Diffstat (limited to 'buildtools/wrap-tree.py')
-rw-r--r-- | buildtools/wrap-tree.py | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/buildtools/wrap-tree.py b/buildtools/wrap-tree.py new file mode 100644 index 00000000..2123b79b --- /dev/null +++ b/buildtools/wrap-tree.py @@ -0,0 +1,61 @@ +""" +Package a directory tree inside a Python script. This is mostly +useful when generating templates for small trees of files one wants to +generate automatically with some customizations (eg, the skeleton for +some the packaging files needed by some platform or another). + +$Id$ + +Copyright (C) 2013 Internet Systems Consortium, Inc. ("ISC") + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH +REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, +INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE +OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +PERFORMANCE OF THIS SOFTWARE. +""" + +import os +import sys + +result = {} + +for root in sys.argv[1:] or ["."]: + if root != ".": + result[root] = None + for dirpath, dirs, files in os.walk(root): + for dn in dirs: + dn = os.path.relpath(os.path.join(dirpath, dn)) + result[dn] = None + for fn in files: + fn = os.path.relpath(os.path.join(dirpath, fn)) + with open(fn, "r") as f: + result[fn] = f.read() + +sys.stdout.write("# Automatically generated. Hack if you like, but beware of overwriting.\n\nimport os\n") + +for k in sorted(result): + v = result[k] + if v is None: + sys.stdout.write("\nos.makedirs(%r)\n" % k) + else: + sys.stdout.write("\nwith open(%r, \"wb\") as f:\n" % k) + lines = v.splitlines() + if v.endswith("\n"): + lines.append("") + sys.stdout.write(" f.write('''\\\n") + while lines: + words = lines.pop(0).replace("\\", "\\\\").split("'''") + sys.stdout.write(words[0]) + for word in words[1:]: + sys.stdout.write("''' + \"'''\" + '''") + sys.stdout.write(word) + if not lines: + sys.stdout.write("''')") + sys.stdout.write("\n") |