diff options
author | Todd Zullinger <tmz@pobox.com> | 2009-08-28 14:08:13 -0400 |
---|---|---|
committer | Todd Zullinger <tmz@pobox.com> | 2009-08-28 14:08:13 -0400 |
commit | b834081493101080cf2001a3d87c7b6d7a47491d (patch) | |
tree | 391d75d2cdaf1dfe6d6a33bf68280c30c1459f3e | |
parent | 42cb7ade8c8b049cd46d7053fb514c6b4463cd19 (diff) | |
download | puppet-host-package-b834081493101080cf2001a3d87c7b6d7a47491d.tar.gz puppet-host-package-b834081493101080cf2001a3d87c7b6d7a47491d.tar.xz puppet-host-package-b834081493101080cf2001a3d87c7b6d7a47491d.zip |
Don't run cleanup() in rpm(), call it explicitly
Running cleanup() from rpm() made it impossible to create a tarball or
other package after rpm() was called because it deleted the tmpdir,
which was made a class variable in ae26808.
-rwxr-xr-x | puppet-host-package | 2 | ||||
-rw-r--r-- | puppethost.py | 17 |
2 files changed, 8 insertions, 11 deletions
diff --git a/puppet-host-package b/puppet-host-package index f609836..9ad8b7e 100755 --- a/puppet-host-package +++ b/puppet-host-package @@ -103,11 +103,13 @@ def _main(): if not os.path.exists(host.files['cert']) or opts.force_cert: try: host.gencert() except puppethost.PuppetHostError, error: + host.cleanup() print error continue try: host.package() except Exception, error: + host.cleanup() print error continue diff --git a/puppethost.py b/puppethost.py index e1ce7ef..91c429b 100644 --- a/puppethost.py +++ b/puppethost.py @@ -187,10 +187,7 @@ class PuppetHost(object): rpmdir = self.opts['rpmdir'] if not self.tarball or not os.path.exists(self.tarball): - try: self.tar() - except: - self._cleanup(self.tmpdir) - raise + self.tar() spec = '%s/puppet-%s.spec' % (self.tmpdir, self.hostname) @@ -209,11 +206,9 @@ class PuppetHost(object): cmd = 'rpm -q --qf "%s/%s" --specfile %s' % (rpmdir, rpm_fmt, spec) status, rpm = commands.getstatusoutput(cmd) if status: - self._cleanup(self.tmpdir) raise PuppetHostError('Failed to get rpm filename:\n%s' % rpm) if os.path.exists(rpm) and not self.opts['force_package']: - self._cleanup(self.tmpdir) raise PuppetHostError('%s exists, not overwriting' % rpm) if self.opts['verbose']: @@ -228,13 +223,11 @@ class PuppetHost(object): status, output = commands.getstatusoutput(cmd) if status or not os.path.exists(rpm): - self._cleanup(self.tmpdir) raise PuppetHostError('Error building rpm:\n', output) if self.opts['verbose']: print 'done' - self._cleanup(self.tmpdir) self.packages.append(('rpm', rpm)) def _check_files(self): @@ -247,9 +240,11 @@ class PuppetHost(object): error += '\t%s' % f raise PuppetHostError(error) - def _cleanup(self, dir): - if os.path.isdir(dir): - shutil.rmtree(dir) + def cleanup(self, dirs=[]): + dirs.append(self.tmpdir) + for d in dirs: + if os.path.isdir(d): + shutil.rmtree(d) @property def files(self): |