summaryrefslogtreecommitdiff
path: root/packages/make-tarball
diff options
context:
space:
mode:
authorJoshua Harlow <harlowja@yahoo-inc.com>2012-06-26 12:17:11 -0700
committerJoshua Harlow <harlowja@yahoo-inc.com>2012-06-26 12:17:11 -0700
commit2b1916db723148dcc291f3ac991bb0340943587e (patch)
tree6f7d39aebd684906a3f8750ad30a2d6e8881725a /packages/make-tarball
parentd3402eac1ca362e1db0b40eb677e7cfc74a3d2c9 (diff)
downloadvyos-cloud-init-2b1916db723148dcc291f3ac991bb0340943587e.tar.gz
vyos-cloud-init-2b1916db723148dcc291f3ac991bb0340943587e.zip
Shrink these down by using the cloudinit utils.
Diffstat (limited to 'packages/make-tarball')
-rwxr-xr-xpackages/make-tarball108
1 files changed, 43 insertions, 65 deletions
diff --git a/packages/make-tarball b/packages/make-tarball
index 98f669a9..479e11af 100755
--- a/packages/make-tarball
+++ b/packages/make-tarball
@@ -8,78 +8,56 @@ import sys
import tempfile
-def join(*paths):
- p = os.path.join(*paths)
- return os.path.abspath(p)
+# 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 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)
+def main(args):
-@contextlib.contextmanager
-def tmpdir():
- t = tempfile.mkdtemp()
- try:
- yield t
- finally:
- shutil.rmtree(t)
-
+ base_fn = None
+ if args:
+ base_fn = args[0]
+ with util.tempdir() as tdir:
-def main(args):
+ if not base_fn:
+ (stdout, _stderr) = util.subp(['bzr', 'revno'])
+ revno = stdout.strip()
- 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)
-
- out = [revno, version, bfn, os.path.abspath(fn)]
- print('\t'.join(out))
+ 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