More clean up with using subprocess
Have a function we call over and over Log the output, trace on stderr
This commit is contained in:
parent
069f8f98a9
commit
dbc2db0a8b
@ -63,6 +63,21 @@ class Pungi:
|
|||||||
if subfile.startswith(self.destdir):
|
if subfile.startswith(self.destdir):
|
||||||
return subfile.replace(self.destdir + os.path.sep, '')
|
return subfile.replace(self.destdir + os.path.sep, '')
|
||||||
|
|
||||||
|
def _doRunCommand(self, command, rundir='/tmp', output=subprocess.PIPE, error=subprocess.PIPE):
|
||||||
|
"""Run a command and log the output. Error out if we get something on stderr"""
|
||||||
|
|
||||||
|
|
||||||
|
log.info("Running %s" % ' '.join(command))
|
||||||
|
|
||||||
|
try:
|
||||||
|
(out, err) = subprocess.Popen(command, cwd=rundir, stdout=output, stderr=error).communicate()
|
||||||
|
except:
|
||||||
|
log.error("Got an error from %s" % command[0])
|
||||||
|
log.error(err)
|
||||||
|
raise
|
||||||
|
|
||||||
|
log.info(out)
|
||||||
|
|
||||||
def doBuildinstall(self):
|
def doBuildinstall(self):
|
||||||
"""Run anaconda-runtime's buildinstall on the tree."""
|
"""Run anaconda-runtime's buildinstall on the tree."""
|
||||||
|
|
||||||
@ -77,9 +92,7 @@ class Pungi:
|
|||||||
createrepo.append(self.topdir)
|
createrepo.append(self.topdir)
|
||||||
|
|
||||||
# run the command
|
# run the command
|
||||||
subprocess.check_call(createrepo, cwd=self.topdir)
|
self._doRunCommand(createrepo, rundir=self.topdir)
|
||||||
# log something here
|
|
||||||
|
|
||||||
|
|
||||||
# setup the buildinstall call
|
# setup the buildinstall call
|
||||||
buildinstall = ['/usr/lib/anaconda-runtime/buildinstall']
|
buildinstall = ['/usr/lib/anaconda-runtime/buildinstall']
|
||||||
@ -104,8 +117,7 @@ class Pungi:
|
|||||||
buildinstall.append(self.topdir)
|
buildinstall.append(self.topdir)
|
||||||
|
|
||||||
# run the command
|
# run the command
|
||||||
subprocess.check_call(buildinstall)
|
self._doRunCommand(buildinstall)
|
||||||
#log.info("Result from buildinstall %s: %s" % (args, res))
|
|
||||||
|
|
||||||
# write out the tree data for snake
|
# write out the tree data for snake
|
||||||
self.writeinfo('tree: %s' % self.mkrelative(self.topdir))
|
self.writeinfo('tree: %s' % self.mkrelative(self.topdir))
|
||||||
@ -123,9 +135,8 @@ class Pungi:
|
|||||||
pkgorder.append(self.config.get('default', 'product_path'))
|
pkgorder.append(self.config.get('default', 'product_path'))
|
||||||
|
|
||||||
# run the command
|
# run the command
|
||||||
subprocess.check_call(pkgorder, stdout=pkgorderfile)
|
self._doRunCommand(pkgorder, output=pkgorderfile)
|
||||||
pkgorderfile.close()
|
pkgorderfile.close()
|
||||||
#log.info("Result from pkgorder: %s" % res)
|
|
||||||
|
|
||||||
def doGetRelnotes(self):
|
def doGetRelnotes(self):
|
||||||
"""Get extra files from packages in the tree to put in the topdir of
|
"""Get extra files from packages in the tree to put in the topdir of
|
||||||
@ -157,8 +168,7 @@ class Pungi:
|
|||||||
if pkgname == relnoterpm:
|
if pkgname == relnoterpm:
|
||||||
extraargs = [os.path.join(self.topdir, self.config.get('default', 'product_path'), pkg)]
|
extraargs = [os.path.join(self.topdir, self.config.get('default', 'product_path'), pkg)]
|
||||||
p1 = subprocess.Popen(rpm2cpio + extraargs, cwd=docsdir, stdout=subprocess.PIPE)
|
p1 = subprocess.Popen(rpm2cpio + extraargs, cwd=docsdir, stdout=subprocess.PIPE)
|
||||||
p2 = subprocess.Popen(cpio, cwd=docsdir, stdin=p1.stdout)
|
subprocess.Popen(cpio, cwd=docsdir, stdin=p1.stdout)
|
||||||
#log.info("Result from rpm2cpio: %s" % res)
|
|
||||||
# Walk the tree for our files
|
# Walk the tree for our files
|
||||||
for dirpath, dirname, filelist in os.walk(docsdir):
|
for dirpath, dirname, filelist in os.walk(docsdir):
|
||||||
for filename in filelist:
|
for filename in filelist:
|
||||||
@ -262,8 +272,7 @@ class Pungi:
|
|||||||
createrepo.append('%s-disc%s' % (self.topdir, disc))
|
createrepo.append('%s-disc%s' % (self.topdir, disc))
|
||||||
|
|
||||||
# run the command
|
# run the command
|
||||||
subprocess.check_call(createrepo)
|
self._doRunCommand(createrepo)
|
||||||
#log.info("Result from createrepo %s: %s" %(args, res))
|
|
||||||
|
|
||||||
def doCreateIsos(self):
|
def doCreateIsos(self):
|
||||||
"""Create isos from the various split directories."""
|
"""Create isos from the various split directories."""
|
||||||
@ -320,19 +329,16 @@ class Pungi:
|
|||||||
extraargs.append(os.path.join('%s-disc%s' % (self.topdir, disc)))
|
extraargs.append(os.path.join('%s-disc%s' % (self.topdir, disc)))
|
||||||
|
|
||||||
# run the command
|
# run the command
|
||||||
subprocess.check_call(mkisofs + extraargs)
|
self._doRunCommand(mkisofs + extraargs)
|
||||||
#log.info("Result from mkisofs: %s" % res)
|
|
||||||
|
|
||||||
# implant md5 for mediacheck on all but source arches
|
# implant md5 for mediacheck on all but source arches
|
||||||
if not self.config.get('default', 'arch') == 'source':
|
if not self.config.get('default', 'arch') == 'source':
|
||||||
subprocess.check_call(['/usr/lib/anaconda-runtime/implantisomd5', isofile])
|
self._doRunCommand(['/usr/lib/anaconda-runtime/implantisomd5', isofile])
|
||||||
#log.info("Result from implantisomd5: %s" % res)
|
|
||||||
|
|
||||||
# shove the sha1sum into a file
|
# shove the sha1sum into a file
|
||||||
sha1file = open(os.path.join(self.isodir, 'SHA1SUM'), 'a')
|
sha1file = open(os.path.join(self.isodir, 'SHA1SUM'), 'a')
|
||||||
subprocess.check_call(['/usr/bin/sha1sum', isoname], cwd=self.isodir, stdout=sha1file)
|
self._doRunCommand(['/usr/bin/sha1sum', isoname], rundir=self.isodir, output=sha1file)
|
||||||
sha1file.close()
|
sha1file.close()
|
||||||
#log.info("Result from sha1sum: %s" % res)
|
|
||||||
|
|
||||||
# keep track of the CD images we've written
|
# keep track of the CD images we've written
|
||||||
isolist.append(self.mkrelative(isofile))
|
isolist.append(self.mkrelative(isofile))
|
||||||
@ -380,18 +386,15 @@ class Pungi:
|
|||||||
extraargs.append(self.topdir)
|
extraargs.append(self.topdir)
|
||||||
|
|
||||||
# run the command
|
# run the command
|
||||||
subprocess.check_call(mkisofs + extraargs)
|
self._doRunCommand(mkisofs + extraargs)
|
||||||
#log.info("Result from DVD mkisofs: %s" % res)
|
|
||||||
|
|
||||||
# implant md5 for mediacheck on all but source arches
|
# implant md5 for mediacheck on all but source arches
|
||||||
subprocess.check_call(['/usr/lib/anaconda-runtime/implantisomd5', isofile])
|
self._doRunCommand(['/usr/lib/anaconda-runtime/implantisomd5', isofile])
|
||||||
#log.info("Result from implantisomd5: %s" % res)
|
|
||||||
|
|
||||||
# shove the sha1sum into a file
|
# shove the sha1sum into a file
|
||||||
sha1file = open(os.path.join(self.isodir, 'SHA1SUM'), 'a')
|
sha1file = open(os.path.join(self.isodir, 'SHA1SUM'), 'a')
|
||||||
subprocess.check_call(['/usr/bin/sha1sum', isoname], cwd=self.isodir, stdout=sha1file)
|
self._doRunCommand(['/usr/bin/sha1sum', isoname], rundir=self.isodir, output=sha1file)
|
||||||
sha1file.close()
|
sha1file.close()
|
||||||
#log.info("Result from sha1sum: %s" % res)
|
|
||||||
|
|
||||||
# return the .discinfo file
|
# return the .discinfo file
|
||||||
shutil.move(os.path.join(self.config.get('default', 'destdir'), '.discinfo-%s' % self.config.get('default', 'arch')), discinfofile)
|
shutil.move(os.path.join(self.config.get('default', 'destdir'), '.discinfo-%s' % self.config.get('default', 'arch')), discinfofile)
|
||||||
@ -420,8 +423,7 @@ class Pungi:
|
|||||||
rescue.append(self.config.get('default', 'product_path'))
|
rescue.append(self.config.get('default', 'product_path'))
|
||||||
|
|
||||||
# run the command
|
# run the command
|
||||||
subprocess.check_call(rescue)
|
self._doRunCommand(rescue)
|
||||||
#log.info("Result from mk-resueimage: %s" % res)
|
|
||||||
|
|
||||||
# write the iso
|
# write the iso
|
||||||
extraargs = []
|
extraargs = []
|
||||||
@ -444,14 +446,13 @@ class Pungi:
|
|||||||
extraargs.append(os.path.join(self.workdir, "%s-rescueimage" % self.config.get('default', 'arch')))
|
extraargs.append(os.path.join(self.workdir, "%s-rescueimage" % self.config.get('default', 'arch')))
|
||||||
|
|
||||||
# run the command
|
# run the command
|
||||||
subprocess.check_call(mkisofs + extraargs)
|
self._doRunCommand(mkisofs + extraargs)
|
||||||
#log.info("Result from Rescue mkisofs: %s" % res)
|
#log.info("Result from Rescue mkisofs: %s" % res)
|
||||||
|
|
||||||
# shove the sha1sum into a file
|
# shove the sha1sum into a file
|
||||||
sha1file = open(os.path.join(self.isodir, 'SHA1SUM'), 'a')
|
sha1file = open(os.path.join(self.isodir, 'SHA1SUM'), 'a')
|
||||||
subprocess.check_call(['/usr/bin/sha1sum', isoname], cwd=self.isodir, stdout=sha1file)
|
self._doRunCommand(['/usr/bin/sha1sum', isoname], rundir=self.isodir, output=sha1file)
|
||||||
sha1file.close()
|
sha1file.close()
|
||||||
#log.info("Result from sha1sum: %s" % res)
|
|
||||||
|
|
||||||
# Do some clean up
|
# Do some clean up
|
||||||
dirs = os.listdir(self.archdir)
|
dirs = os.listdir(self.archdir)
|
||||||
|
Loading…
Reference in New Issue
Block a user