68 lines
1.9 KiB
Python
Executable File
68 lines
1.9 KiB
Python
Executable File
#!/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:]))
|
|
|