From e51b3c2f0e248421eea40347208ea34d2cf82bab Mon Sep 17 00:00:00 2001 From: Andrew Gaffney Date: Sun, 13 Sep 2009 14:38:10 -0500 Subject: [PATCH] Add catalyst.util.create_tarball() helper function and modify snapshot target to use it --- ChangeLog | 5 +++++ modules/catalyst/target/snapshot.py | 7 +++---- modules/catalyst/util.py | 15 +++++++++++++++ 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 77a995e9..0380a5f9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,11 @@ # Distributed under the GPL v2 # $Id$ + 13 Sep 2009; Andrew Gaffney + modules/catalyst/target/snapshot.py, modules/catalyst/util.py: + Add catalyst.util.create_tarball() helper function and modify snapshot + target to use it + 13 Sep 2009; Andrew Gaffney modules/catalyst/target/snapshot.py, modules/catalyst/util.py: Create catalyst.util.rsync() helper function diff --git a/modules/catalyst/target/snapshot.py b/modules/catalyst/target/snapshot.py index 3a52530c..cbee31fd 100644 --- a/modules/catalyst/target/snapshot.py +++ b/modules/catalyst/target/snapshot.py @@ -40,7 +40,7 @@ class snapshot_target(catalyst.target.generic.generic_target): msg("Creating Portage tree snapshot " + self.settings["version_stamp"] + \ " from " + self.settings["portdir"] + "...") - mytmp=self.settings["tmp_path"] + mytmp = self.settings["tmp_path"] if not os.path.exists(mytmp): os.makedirs(mytmp) @@ -48,8 +48,7 @@ class snapshot_target(catalyst.target.generic.generic_target): extra_opts="--exclude /distfiles/ --exclude /local/ --exclude CVS/ --exclude .svn --filter=H_**/files/digest-*") msg("Compressing Portage snapshot tarball...") - cmd("tar cjf "+self.settings["snapshot_path"]+" -C "+mytmp+" portage",\ - "Snapshot creation failure",env=self.env) + catalyst.util.create_tarball(self.settings["snapshot_path"], "portage", mytmp) catalyst.hash.gen_contents_file(self.settings["snapshot_path"], self.settings) catalyst.hash.gen_digest_file(self.settings["snapshot_path"], self.settings) @@ -62,7 +61,7 @@ class snapshot_target(catalyst.target.generic.generic_target): msg("Cleaning up...") def purge(self): - myemp=self.settings["tmp_path"] + myemp = self.settings["tmp_path"] if os.path.isdir(myemp): msg("Emptying directory " + myemp) catalyst.util.empty_dir(myemp) diff --git a/modules/catalyst/util.py b/modules/catalyst/util.py index 94240c93..b960227a 100644 --- a/modules/catalyst/util.py +++ b/modules/catalyst/util.py @@ -243,4 +243,19 @@ def rsync(src, dest, delete=False, extra_opts=""): if retval != 0: raise CatalystError("Could not rsync '%s' to '%s'" % (src, dest)) +def create_tarball(target, src, working_dir=None, keep_perm=False): + pack_cmd = "tar " + if keep_perm: + pack_cmd += "cjpf " + else: + pack_cmd += "cjf " + pack_cmd += target + if working_dir: + pack_cmd += " -C " + working_dir + pack_cmd += " " + src + retval = catalyst.spawn.spawn_bash(pack_cmd) + if retval != 0: + raise CatalystError("Could not create tarball '%s'" % (target,)) + + # vim: ts=4 sw=4 sta noet sts=4 ai -- 2.26.2