From b834081493101080cf2001a3d87c7b6d7a47491d Mon Sep 17 00:00:00 2001 From: Todd Zullinger Date: Fri, 28 Aug 2009 14:08:13 -0400 Subject: 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. --- puppethost.py | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) (limited to 'puppethost.py') 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): -- cgit