Redirected the error messages output from yum; Improved the links copy

function;
This commit is contained in:
Martin Gracik 2009-08-26 17:16:46 +02:00
parent 1324551367
commit 4910deac71
5 changed files with 38 additions and 34 deletions

View File

@ -110,10 +110,10 @@ class Lorax(object):
self.create_initrd()
print("%sCreating the install.img%s" % bold)
self.create_installimg()
#self.create_installimg()
print("%sCreating the boot.iso%s" % bold)
self.create_bootiso()
#self.create_bootiso()
if self.conf.cleanup:
print("%sCleaning up%s" % bold)
@ -202,8 +202,12 @@ class Lorax(object):
self.conf.addAttr('yumconf')
self.conf.set(yumconf=yumconf)
# create the yum err file path
err_file = os.path.join(self.conf.tempdir, 'yum.errors')
# create the Yum object
self.yum = Yum(yumconf=self.conf.yumconf, installroot=self.conf.treedir)
self.yum = Yum(yumconf=self.conf.yumconf, installroot=self.conf.treedir,
err_file=err_file)
# remove not needed attributes
self.conf.delAttr(['repo', 'extrarepos', 'mirrorlist', 'cachedir'])
@ -873,30 +877,23 @@ class Lorax(object):
# calculate the size of the dosfs
cmd = 'du -kcs %s | tail -n1 | awk \'{print $1}\'' % self.conf.efitreedir
size = int(commands.getoutput(cmd)) + 100
print('Size of the efiboot.img is %d' % size)
efiimage = os.path.join(self.conf.outdir, 'images', 'efiboot.img')
cmd = 'mkdosfs -n ANACONDA -C %s %s > /dev/null' % (efiimage, size)
print cmd
out = commands.getoutput(cmd)
print(out)
tempdir = os.path.join(self.conf.tempdir, 'efiimage')
if not os.path.isdir(tempdir):
os.makedirs(tempdir)
cmd = 'mount -o loop,shortname=winnt,umask=0777 -t vfat %s %s' % \
(efiimage, tempdir)
print cmd
out = commands.getoutput(cmd)
print(out)
src = os.path.join(self.conf.efitreedir, '*')
cp(src, tempdir)
cmd = 'umount %s' % tempdir
print(cmd)
out = commands.getoutput(cmd)
print(out)
# copy efi to cd
if not kernelfile and not initrd:
@ -952,36 +949,24 @@ class Lorax(object):
partsize = int(commands.getoutput(cmd))
disksize = 17408 + partsize + 17408
disksize = disksize + (disksize % 512)
print partsize
print disksize
efidiskimg = os.path.join(self.conf.imagesdir, 'efidisk.img')
touch(efidiskimg)
cmd = 'dd if=/dev/zero of=%s count=1 bs=%s' % (efidiskimg, disksize)
print(cmd)
out = commands.getoutput(cmd)
print(out)
cmd = 'losetup -v -f %s | awk \'{print $4}\'' % efidiskimg
print(cmd)
loop = commands.getoutput(cmd)
print(loop)
cmd = 'dmsetup create efiboot --table "0 %s linear %s 0"' % (disksize / 512, loop)
print(cmd)
out = commands.getoutput(cmd)
print(out)
cmd = 'parted --script /dev/mapper/efiboot mklabel gpt unit b mkpart \'"EFI System Partition"\' fat32 17408 %s set 1 boot on' % (partsize + 17408)
print(cmd)
out = commands.getoutput(cmd)
print(out)
cmd = 'dd if=%s of=/dev/mapper/efibootp1' % efiimage
print(cmd)
out = commands.getoutput(cmd)
print(out)
cmd = 'dmsetup remove /dev/mapper/efibootp1'
out = commands.getoutput(cmd)
@ -1000,6 +985,7 @@ class Lorax(object):
# XEN
if self.conf.buildarch in ('i386',):
print('Installing the XEN kernel')
self.yum.addPackages('kernel-PAE')
self.yum.install()
@ -1069,13 +1055,11 @@ class Lorax(object):
mkisocmd = 'mkisofs -v -o %s %s %s -R -J -V %s -T -graft-points isolinux=%s images=%s %s' % (os.path.join(self.conf.imagesdir, 'boot.iso'), biosargs, efiargs, self.conf.product, self.conf.isolinuxdir, self.conf.imagesdir, efigraft)
out = commands.getoutput(mkisocmd)
print(out)
hybrid = os.path.join(os.sep, 'usr', 'bin', 'isohybrid')
if os.path.exists(hybrid):
cmd = '%s %s' % (hybrid, os.path.join(self.conf.imagesdir, 'boot.iso'))
out = commands.getoutput(cmd)
print(out)
def clean_up(self, trash=[]):
for item in trash:

View File

@ -160,7 +160,6 @@ class InitRD(object):
m = re.match(r'^.*/(?P<name>.*)\.ko$', dep)
if m.group('name') not in modules:
changed = True
print('Adding module dependency %s' % m.group('name'))
modules.add(m.group('name'))
srcdir = os.path.join(self.conf.treedir, 'lib', 'modules', self.kernelver)

View File

@ -55,6 +55,21 @@ def __copy(src, dst, verbose=False, remove=False):
if os.path.isdir(dst):
basename = os.path.basename(src)
dst = os.path.join(dst, basename)
if os.path.islink(src):
print('Got link %s' % src)
target = os.readlink(src)
if os.path.exists(dst):
os.unlink(dst)
os.symlink(target, dst)
if remove:
if verbose:
print("removing '%s'" % src)
os.unlink(src)
return True
if os.path.isdir(src):
if os.path.isfile(dst):

View File

@ -2,10 +2,6 @@ import sys
import os
import commands
import logging
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger('pylorax')
def genmodinfo(path, output):
mods = {}
@ -24,7 +20,7 @@ def genmodinfo(path, output):
filename = os.path.join(path, 'modules.%s' % file)
f = open(filename, 'r')
except IOError:
logger.error('cannot open file %s', filename)
sys.stderr.write('cannot open file %s\n', filename)
continue
else:
lines = f.readlines()
@ -35,14 +31,11 @@ def genmodinfo(path, output):
if line in mods:
modname, ext = os.path.splitext(line)
if modname in blacklist:
logger.info('skipping %s', modname)
continue
outtext = commands.getoutput('modinfo -F description %s' % mods[line])
desc = outtext.split('\n')[0]
desc = desc.strip()
# XXX why we need to do this?
desc = desc[:65]
if not desc:

View File

@ -69,7 +69,7 @@ class Callback(yum.rpmtrans.SimpleCliCallBack):
class Yum(object):
def __init__(self, yumconf='/etc/yum/yum.conf', installroot='/'):
def __init__(self, yumconf='/etc/yum/yum.conf', installroot='/', err_file='/dev/null'):
self.yb = yum.YumBase()
self.yumconf = os.path.abspath(yumconf)
@ -112,7 +112,20 @@ class Yum(object):
cb = yum.callbacks.ProcessTransBaseCallback()
rpmcb = Callback()
# XXX ugly error output hack
# we redirect the error output from rpm to err_file,
# so it does not show up in our "nice" output :)
# we should put the errors to some file,
# which we can parse later for serious errors
standard_err = os.dup(2)
my_err = open(err_file, 'w')
os.dup2(my_err.fileno(), 2)
# now process the transactions without errors showing up
self.yb.processTransaction(callback=cb, rpmDisplay=rpmcb)
# and put the standard error output back
os.dup2(standard_err, 2)
my_err.close()
self.yb.closeRpmDB()
self.yb.close()