102 lines
2.6 KiB
Python
Executable File
102 lines
2.6 KiB
Python
Executable File
#!/usr/bin/python
|
|
|
|
import contextlib
|
|
import glob
|
|
import os
|
|
import shutil
|
|
import subprocess
|
|
import sys
|
|
import tempfile
|
|
|
|
|
|
@contextlib.contextmanager
|
|
def tmpdir():
|
|
t = tempfile.mkdtemp()
|
|
try:
|
|
yield t
|
|
finally:
|
|
pass
|
|
#shutil.rmtree(t)
|
|
|
|
|
|
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)
|
|
info("Running %s" % (cmd))
|
|
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)
|
|
|
|
|
|
def info(msg):
|
|
print("INFO: %s" % (msg))
|
|
|
|
|
|
def warn(msg):
|
|
print("WARNING: %s" % (msg))
|
|
|
|
|
|
def archive_code():
|
|
(stdout, _stderr) = tiny_p([sys.executable,
|
|
join(os.getcwd(), 'tar-me')])
|
|
lines = stdout.splitlines()
|
|
revno = lines[0]
|
|
version = lines[1]
|
|
bname = lines[2]
|
|
arc_fn = lines[3]
|
|
return (revno, version, bname, arc_fn)
|
|
|
|
|
|
def main():
|
|
|
|
# cmd = ['apt-get', 'install', 'python-nose',
|
|
#'pyflakes', 'python-mocker', 'cdbs', 'debhelper']
|
|
# tiny_p(cmd)
|
|
|
|
with tmpdir() as td:
|
|
(revno, version, bname, archive_fn) = archive_code()
|
|
real_archive_fn = os.path.join(td, os.path.basename(archive_fn))
|
|
shutil.move(archive_fn, real_archive_fn)
|
|
info("Archived code to %s" % (real_archive_fn))
|
|
|
|
cmd = ['tar', '-xvzf', real_archive_fn, '-C', td]
|
|
stdout, stderr = tiny_p(cmd)
|
|
|
|
edir = join(td, bname)
|
|
shutil.move(edir, join(td, 'cloud-init'))
|
|
shutil.copytree('debian.trunk', join(td, 'cloud-init', 'debian'))
|
|
|
|
cmd = ['sed', '-i', '-e',"s,VERSION,%s," %(version),
|
|
'-e', "s,REVNO,bzr%s," % (revno),
|
|
join(td, 'cloud-init', 'debian', 'changelog')]
|
|
tiny_p(cmd)
|
|
|
|
# Seems to want an original tar ball
|
|
o_tar = "cloud-init_%s~bzr%s.orig.tar.gz" % (version, revno)
|
|
cmd = ['tar', '-czf', join(td, o_tar), '-C', join(td, 'cloud-init')]
|
|
cmd.extend(os.listdir(join(td, 'cloud-init')))
|
|
tiny_p(cmd)
|
|
|
|
ocwd = os.getcwd()
|
|
os.chdir(join(td, 'cloud-init'))
|
|
cmd = ['debuild']
|
|
tiny_p(cmd)
|
|
|
|
debname = "cloud-init_%s~bzr%s-1_all.deb" % (version, revno)
|
|
shutil.move(debname, join(owcwd, debname))
|
|
info("Wrote out debian package %s" % (join(owcwd, debname)))
|
|
|
|
return 0
|
|
|
|
|
|
if __name__ == '__main__':
|
|
sys.exit(main())
|