diff options
Diffstat (limited to 'packages/make-tarball')
-rwxr-xr-x | packages/make-tarball | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/packages/make-tarball b/packages/make-tarball new file mode 100755 index 00000000..479e11af --- /dev/null +++ b/packages/make-tarball @@ -0,0 +1,67 @@ +#!/usr/bin/python + +import contextlib +import os +import shutil +import subprocess +import sys +import tempfile + + +# Use the util functions from cloudinit +possible_topdir = os.path.normpath(os.path.join(os.path.abspath( + sys.argv[0]), os.pardir, os.pardir)) +if os.path.exists(os.path.join(possible_topdir, "cloudinit", "__init__.py")): + sys.path.insert(0, possible_topdir) + +from cloudinit import util + + +def main(args): + + base_fn = None + if args: + base_fn = args[0] + + with util.tempdir() as tdir: + + if not base_fn: + (stdout, _stderr) = util.subp(['bzr', 'revno']) + revno = stdout.strip() + + cmd = [sys.executable, + util.abs_join(os.pardir, 'tools', 'read-version')] + (stdout, _stderr) = util.subp(cmd) + version = stdout.strip() + base_fn = 'cloud-init-%s-%s' % (version, revno) + + util.ensure_dir(util.abs_join(tdir, base_fn)) + arch_fn = '%s.tar.gz' % (base_fn) + + with util.chdir(os.pardir): + (stdout, _stderr) = util.subp(['bzr', 'ls', '--versioned']) + fns = [fn for fn in stdout.splitlines() + if fn and not fn.startswith('.')] + # TODO - only copy the right files + # ie do a recursive versioned... + for fn in fns: + if os.path.isfile(fn): + shutil.copy(fn, util.abs_join(tdir, base_fn, fn)) + else: + shutil.copytree(fn, util.abs_join(tdir, base_fn, fn)) + + cmd = ['tar', '-czf', + util.abs_join(tdir, arch_fn), + '-C', tdir, base_fn] + util.subp(cmd) + + shutil.move(util.abs_join(tdir, arch_fn), + util.abs_join(os.getcwd(), arch_fn)) + print(os.path.abspath(arch_fn)) + + return 0 + + +if __name__ == '__main__': + sys.exit(main(sys.argv[1:])) + |