From ddd183386c4696b218cb7b7e18f7e812d61d4491 Mon Sep 17 00:00:00 2001 From: "jkeating@localhost.localdomain" <> Date: Wed, 14 Feb 2007 17:33:07 -0500 Subject: [PATCH] Logging patch from jbowes --- Authors | 3 ++- Changelog | 3 +++ pypungi/gather.py | 12 ++++++++++- pypungi/pungi.py | 53 ++++++++++++++++++++++++++++++----------------- 4 files changed, 50 insertions(+), 21 deletions(-) diff --git a/Authors b/Authors index 5aad5f54..57ac8abe 100644 --- a/Authors +++ b/Authors @@ -5,4 +5,5 @@ Jesse Keating Contributors: Will Woods -sien Ita Essien +Essien Ita Essien +James Bowes diff --git a/Changelog b/Changelog index 3c9fee42..eb366178 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,6 @@ +* Wed Feb 14 2007 Jesse Keating +- Add logging patch from jbowes + * Tue Feb 13 2007 Jesse Keating - Fix part of the patch from Essien - Add Contributors to the Authors file diff --git a/pypungi/gather.py b/pypungi/gather.py index 8a66a2a2..43710800 100755 --- a/pypungi/gather.py +++ b/pypungi/gather.py @@ -21,6 +21,7 @@ class Gather(yum.YumBase): def __init__(self, config, pkglist): # Create a yum object to use yum.YumBase.__init__(self) + self.config = config self.doConfigSetup(fn=config.get('default', 'yumconf'), debuglevel=6, errorlevel=6, root="/tmp") self.cleanMetadata() # clean metadata that might be in the cache from previous runs self.cleanSqlite() # clean metadata that might be in the cache from previous runs @@ -39,12 +40,21 @@ class Gather(yum.YumBase): self.doSackSetup(arches) self.doSackFilelistPopulate() self.logger = yum.logging.getLogger("yum.verbose.pungi") - self.config = config self.pkglist = pkglist self.polist = [] self.srpmlist = [] self.resolved_deps = {} # list the deps we've already resolved, short circuit. + def doLoggingSetup(self, debuglevel, errorlevel): + logdir = os.path.join(self.config.get('default', 'destdir'), 'logs') + if not os.path.exists(logdir): + os.makedirs(logdir) + logfile = os.path.join(logdir, 'log.txt') + yum.logging.basicConfig(level=yum.logging.INFO, filename=logfile) + + def doFileLogSetup(self, uid, logfile): + pass + def _provideToPkg(self, req): #this is stolen from Anaconda bestlist = None (r, f, v) = req diff --git a/pypungi/pungi.py b/pypungi/pungi.py index 0395a543..a9475a0e 100755 --- a/pypungi/pungi.py +++ b/pypungi/pungi.py @@ -12,6 +12,8 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +import commands +import logging import os import sys sys.path.append('/usr/lib/anaconda-runtime') @@ -19,6 +21,8 @@ import splittree import shutil import re +log = logging.getLogger("pypungi.pungi") + class Pungi: def __init__(self, config): self.config = config @@ -67,13 +71,15 @@ class Pungi: self.config.get('default', 'version'), '%s %s' % (self.config.get('default', 'product_name'), self.config.get('default', 'version')), self.config.get('default', 'product_path'), bugurl, self.topdir) - os.system('/usr/lib/anaconda-runtime/buildinstall %s' % args) + res = commands.getoutput('/usr/lib/anaconda-runtime/buildinstall %s' % args) + log.info("Result from buildinstall %s: %s" % (args, res)) self.writeinfo('tree: %s' % self.mkrelative(self.topdir)) def doPackageorder(self): - os.system('/usr/lib/anaconda-runtime/pkgorder %s %s %s > %s' % (self.topdir, self.config.get('default', 'arch'), + res = commands.getoutput('/usr/lib/anaconda-runtime/pkgorder %s %s %s > %s' % (self.topdir, self.config.get('default', 'arch'), self.config.get('default', 'product_path'), os.path.join(self.workdir, 'pkgorder-%s' % self.config.get('default', 'arch')))) + log.info("Result from pkgorder: %s" % res) def doGetRelnotes(self): docsdir = os.path.join(self.workdir, 'docs') @@ -96,10 +102,10 @@ class Pungi: pkgname = pkg.rsplit('-', 2)[0] for relnoterpm in relnoterpms: if pkgname == relnoterpm: - output = os.system("pushd %s; rpm2cpio %s |cpio -imud; popd" % + res = commands.getoutput("pushd %s; rpm2cpio %s |cpio -imud; popd" % (docsdir, os.path.join(self.topdir, self.config.get('default', 'product_path'), pkg))) - + log.info("Result from rpm2cpio: %s" % res) # Walk the tree for our files for dirpath, dirname, filelist in os.walk(docsdir): for filename in filelist: @@ -174,7 +180,8 @@ class Pungi: mediaid = discinfo[0].rstrip('\n') args = '-g %s --baseurl=media://%s --outputdir=%s-disc1 --basedir=%s-disc1 --split %s-disc?' % \ (os.path.join(self.topdir, 'repodata', 'comps.xml'), mediaid, self.topdir, self.topdir, self.topdir) - os.system('/usr/bin/createrepo %s' % args) + res = commands.getoutput('/usr/bin/createrepo %s' % args) + log.info("Result from createrepo %s: %s" %(args, res)) def doCreateIsos(self): anaruntime = '/usr/lib/anaconda-runtime/boot' @@ -202,16 +209,19 @@ class Pungi: bootargs = '' # clear out any existing bootargs isofile = os.path.join(self.isodir, isoname) - os.system('mkisofs %s %s %s -o %s %s' % (mkisofsargs, + res = commands.getoutput('mkisofs %s %s %s -o %s %s' % (mkisofsargs, volname, bootargs, isofile, os.path.join('%s-disc%s' % (self.topdir, disc)))) + log.info("Result from mkisofs: %s" % res) # implant md5 for mediacheck on all but source arches if not self.config.get('default', 'arch') == 'source': - os.system('/usr/lib/anaconda-runtime/implantisomd5 %s' % isofile) + res = commands.getoutput('/usr/lib/anaconda-runtime/implantisomd5 %s' % isofile) + log.info("Result from implantisomd5: %s" % res) # shove the sha1sum into a file - os.system('cd %s; sha1sum %s >> SHA1SUM' % (self.isodir, isoname)) + res = commands.getoutput('cd %s; sha1sum %s >> SHA1SUM' % (self.isodir, isoname)) + log.info("Result from sha1sum: %s" % res) # keep track of the CD images we've written isolist.append(self.mkrelative(isofile)) # Write out a line describing the CD set @@ -247,13 +257,16 @@ class Pungi: bootargs = '' # clear out any existing bootargs isofile = os.path.join(self.isodir, isoname) - os.system('mkisofs %s %s %s -o %s %s' % (mkisofsargs, + res = commands.getoutput('mkisofs %s %s %s -o %s %s' % (mkisofsargs, volname, bootargs, isofile, self.topdir)) - os.system('cd %s; sha1sum %s >> SHA1SUM' % (self.isodir, isoname)) - os.system('/usr/lib/anaconda-runtime/implantisomd5 %s' % isofile) + log.info("Result from mkisofs: %s" % res) + res = commands.getoutput('cd %s; sha1sum %s >> SHA1SUM' % (self.isodir, isoname)) + log.info("Result from sha1sum: %s" % res) + res = commands.getoutput('/usr/lib/anaconda-runtime/implantisomd5 %s' % isofile) + log.info("Result from implantisomd5: %s" % res) shutil.move(os.path.join(self.config.get('default', 'destdir'), '.discinfo-%s' % self.config.get('default', 'arch')), discinfofile) @@ -268,12 +281,13 @@ class Pungi: # Now make rescue images if not self.config.get('default', 'arch') == 'source': - os.system('/usr/lib/anaconda-runtime/mk-rescueimage.%s %s %s %s %s' % ( + res = commands.getoutput('/usr/lib/anaconda-runtime/mk-rescueimage.%s %s %s %s %s' % ( self.config.get('default', 'arch'), self.topdir, self.workdir, self.config.get('default', 'iso_basename'), self.config.get('default', 'product_path'))) + log.info("Result from mk-resueimage: %s" % res) # write the iso volname = '"%s %s %s Rescue"' % (self.config.get('default', 'product_name'), self.config.get('default', 'version'), @@ -289,14 +303,15 @@ class Pungi: else: bootargs = '' # clear out any existing bootargs - os.system('mkisofs %s %s %s -o %s/%s %s' % (mkisofsargs, - volname, - bootargs, - self.isodir, - isoname, - os.path.join(self.workdir, "%s-rescueimage" % self.config.get('default', 'arch')))) + res = commands.getoutput('mkisofs %s %s %s -o %s/%s %s' + % (mkisofsargs, volname, bootargs, self.isodir, isoname, + os.path.join(self.workdir, "%s-rescueimage" + % self.config.get('default', 'arch')))) + log.info("Result from mkisofs: %s" % res) - os.system('cd %s; sha1sum %s >> SHA1SUM' % (self.isodir, isoname)) + res = commands.getoutput('cd %s; sha1sum %s >> SHA1SUM' + % (self.isodir, isoname)) + log.info("Result from sha1sum: %s" % res) # Do some clean up dirs = os.listdir(self.archdir)