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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
#!/usr/bin/python
import contextlib
import os
import shutil
import subprocess
import sys
import tempfile
def join(*paths):
p = os.path.join(*paths)
return os.path.abspath(p)
def tiny_p(cmd):
# Darn python 2.6 doesn't have check_output (argggg)
sp = subprocess.Popen(cmd, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, stdin=None)
(out, err) = sp.communicate()
if sp.returncode not in [0]:
raise RuntimeError("Failed running %s [rc=%s] (%s, %s)"
% (cmd, sp.returncode, out, err))
return (out, err)
@contextlib.contextmanager
def tmpdir():
t = tempfile.mkdtemp()
try:
yield t
finally:
shutil.rmtree(t)
def main(args):
tag = None
if args:
tag = args[0]
with tmpdir() as td:
(stdout, _stderr) = tiny_p(['bzr', 'revno'])
revno = stdout.strip()
cmd = [sys.executable, join(os.pardir, 'tools', 'read-version')]
(stdout, _stderr) = tiny_p(cmd)
version = stdout.strip()
owcd = os.getcwd()
os.chdir(os.path.abspath(os.pardir))
if not os.path.exists('setup.py'):
raise RuntimeError("No setup.py found in %s" % (os.getcwd()))
cmd = ['bzr', 'ls', '--versioned']
(stdout, _stderr) = tiny_p(cmd)
fns = []
for fn in stdout.splitlines():
fn = fn.strip()
if not fn or fn.startswith("."):
continue
fns.append(fn)
bfn = 'cloud-init-%s-%s' % (version, revno)
os.makedirs(join(td, bfn))
for fn in fns:
if os.path.isfile(fn):
shutil.copy(fn, join(td, bfn, fn))
else:
shutil.copytree(fn, join(td, bfn, fn))
fn = '%s.tar.gz' % (bfn)
o_fn = join(td, fn)
cmd = ['tar', '-czf', o_fn, '-C', join(td), bfn]
tiny_p(cmd)
os.chdir(owcd)
shutil.move(o_fn, fn)
print revno
print version
print bfn
print(os.path.abspath(fn))
return 0
if __name__ == '__main__':
sys.exit(main(sys.argv[1:]))
|