summaryrefslogtreecommitdiff
path: root/packages/make-tarball
blob: 479e11af3899d9282d4c33ddac4d1fab1e99046b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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:]))