13
# Use the util functions from cloudinit
14
possible_topdir = os.path.normpath(os.path.join(os.path.abspath(
15
sys.argv[0]), os.pardir, os.pardir))
16
if os.path.exists(os.path.join(possible_topdir, "cloudinit", "__init__.py")):
17
sys.path.insert(0, possible_topdir)
19
from cloudinit import util
22
def find_versioned_files():
23
(stdout, _stderr) = util.subp(['bzr', 'ls', '--versioned', '--recursive'])
24
fns = [fn for fn in stdout.splitlines()
25
if fn and not fn.startswith('.')]
30
def copy(fn, where_to, verbose):
32
print("Copying %r --> %r" % (fn, where_to))
33
if os.path.isfile(fn):
34
shutil.copy(fn, where_to)
35
elif os.path.isdir(fn) and not os.path.isdir(where_to):
38
raise RuntimeError("Do not know how to copy %s" % (fn))
43
parser = optparse.OptionParser()
44
parser.add_option("-f", "--file", dest="filename",
45
help="write archive to FILE", metavar="FILE")
46
parser.add_option("-v", "--verbose",
47
action="store_true", dest="verbose", default=False,
48
help="show verbose messaging")
50
(options, args) = parser.parse_args()
52
base_fn = options.filename
54
(stdout, _stderr) = util.subp(['bzr', 'revno'])
55
revno = stdout.strip()
56
cmd = [sys.executable,
57
util.abs_join(os.pardir, 'tools', 'read-version')]
58
(stdout, _stderr) = util.subp(cmd)
59
version = stdout.strip()
60
base_fn = 'cloud-init-%s-%s' % (version, revno)
62
with util.tempdir() as tdir:
63
util.ensure_dir(util.abs_join(tdir, base_fn))
64
arch_fn = '%s.tar.gz' % (base_fn)
66
with util.chdir(os.pardir):
67
fns = find_versioned_files()
69
copy(fn, util.abs_join(tdir, base_fn, fn),
70
verbose=options.verbose)
72
arch_full_fn = util.abs_join(tdir, arch_fn)
73
cmd = ['tar', '-czvf', arch_full_fn, '-C', tdir, base_fn]
75
print("Creating an archive from directory %r to %r" %
76
(util.abs_join(tdir, base_fn), arch_full_fn))
78
util.subp(cmd, capture=(not options.verbose))
79
shutil.move(util.abs_join(tdir, arch_fn),
80
util.abs_join(os.getcwd(), arch_fn))
82
print(os.path.abspath(arch_fn))
87
if __name__ == '__main__':