Fixed variable replacements in template.
Reordered some functions calls to call yum.install() only once.
This commit is contained in:
parent
b0b696d66d
commit
2908d5a3c4
@ -125,19 +125,24 @@ class Lorax(object):
|
||||
os.makedirs(self.conf.outdir, mode=0755)
|
||||
|
||||
treedir = os.path.join(self.conf.tempdir, 'treedir', 'install')
|
||||
os.makedirs(treedir)
|
||||
cachedir = os.path.join(self.conf.tempdir, 'yumcache')
|
||||
os.makedirs(cachedir)
|
||||
initrddir = os.path.join(self.conf.tempdir, 'initrd')
|
||||
os.makedirs(initrddir)
|
||||
|
||||
print('Working directories:')
|
||||
print(' tempdir = %s' % self.conf.tempdir)
|
||||
print(' treedir = %s' % treedir)
|
||||
print(' cachedir = %s' % cachedir)
|
||||
print(' initrddir = %s' % initrddir)
|
||||
|
||||
self.conf.addAttr(['treedir', 'cachedir'])
|
||||
self.conf.set(treedir=treedir, cachedir=cachedir)
|
||||
self.conf.addAttr(['treedir', 'cachedir', 'initrddir'])
|
||||
self.conf.set(treedir=treedir, cachedir=cachedir, initrddir=initrddir)
|
||||
|
||||
def initYum(self):
|
||||
yumconf = os.path.join(self.conf.tempdir, 'yum.conf')
|
||||
|
||||
|
||||
try:
|
||||
f = open(yumconf, 'w')
|
||||
except IOError:
|
||||
|
@ -15,14 +15,6 @@ COMMANDS = { 'copy': 'Copy',
|
||||
'replace': 'Replace' }
|
||||
|
||||
|
||||
def getFileName(string):
|
||||
m = re.match(r'@instroot@(?P<file>.*)', string)
|
||||
if m:
|
||||
return m.group('file')
|
||||
else:
|
||||
return None
|
||||
|
||||
|
||||
class Copy(LoraxAction):
|
||||
|
||||
REGEX = r'^(?P<src>.*?)\sto\s(?P<dst>.*?)(\smode\s(?P<mode>.*?))?$'
|
||||
@ -33,11 +25,11 @@ class Copy(LoraxAction):
|
||||
self._attrs['dst'] = kwargs.get('dst')
|
||||
self._attrs['mode'] = kwargs.get('mode')
|
||||
|
||||
file = getFileName(self._attrs['src'])
|
||||
if file:
|
||||
self._attrs['install'] = file
|
||||
|
||||
def execute(self, verbose=False):
|
||||
dst_dir = os.path.dirname(self.dst)
|
||||
if not os.path.isdir(dst_dir):
|
||||
os.makedirs(dst_dir)
|
||||
|
||||
cp(src=self.src, dst=self.dst, mode=self.mode, verbose=verbose)
|
||||
self._attrs['success'] = True
|
||||
|
||||
@ -58,7 +50,7 @@ class Copy(LoraxAction):
|
||||
|
||||
@property
|
||||
def install(self):
|
||||
return self._attrs.get('install')
|
||||
return self._attrs.get('src')
|
||||
|
||||
|
||||
class Move(Copy):
|
||||
|
@ -1,9 +1,9 @@
|
||||
# pylorax/config.py
|
||||
|
||||
import sys
|
||||
import re
|
||||
|
||||
from base import seq
|
||||
import re
|
||||
|
||||
from exceptions import TemplateError
|
||||
|
||||
@ -77,7 +77,7 @@ class Template(object):
|
||||
def __init__(self):
|
||||
self._actions = []
|
||||
|
||||
def parse(self, filename, supported_actions):
|
||||
def parse(self, filename, supported_actions, vars):
|
||||
try:
|
||||
f = open(filename, 'r')
|
||||
except IOError:
|
||||
@ -95,6 +95,9 @@ class Template(object):
|
||||
if not line or line.startswith('#'):
|
||||
continue
|
||||
|
||||
for var, value in vars.items():
|
||||
line = re.sub(r'(.*)%s(.*)' % var, '\g<1>%s\g<2>' % value, line)
|
||||
|
||||
if in_action and not line.startswith(':'):
|
||||
# create the action object
|
||||
regex = supported_actions[active_action].REGEX
|
||||
@ -117,7 +120,7 @@ class Template(object):
|
||||
else:
|
||||
in_action = True
|
||||
continue
|
||||
|
||||
|
||||
return True
|
||||
|
||||
@property
|
||||
|
@ -25,16 +25,13 @@ class Images(object):
|
||||
def run(self):
|
||||
self.prepareBootTree()
|
||||
|
||||
def __makeinitrd(self, dst, size=8192, loader='loader'):
|
||||
i = initrd.InitRD(self.conf, self.yum)
|
||||
i.prepare()
|
||||
i.processActions()
|
||||
i.create(dst)
|
||||
i.cleanUp()
|
||||
|
||||
def prepareBootTree(self):
|
||||
i = initrd.InitRD(self.conf, self.yum)
|
||||
pkgs = i.getPkgs()
|
||||
|
||||
# install needed packages
|
||||
self.yum.addPackages(['anaconda', 'anaconda-runtime', 'kernel', 'syslinux', 'memtest'])
|
||||
self.yum.addPackages(pkgs)
|
||||
self.yum.install()
|
||||
|
||||
# create the destination directories
|
||||
@ -77,10 +74,10 @@ class Images(object):
|
||||
if os.path.exists(self.isodir):
|
||||
rm(self.isodir)
|
||||
os.makedirs(self.isodir)
|
||||
|
||||
|
||||
# copy the isolinux.bin to isolinux dir
|
||||
cp(isolinuxbin, self.isodir)
|
||||
|
||||
|
||||
# copy the syslinux.cfg to isolinux/isolinux.cfg
|
||||
isolinuxcfg = os.path.join(self.isodir, 'isolinux.cfg')
|
||||
cp(os.path.join(bootdiskdir, 'syslinux.cfg'), isolinuxcfg)
|
||||
@ -88,14 +85,16 @@ class Images(object):
|
||||
# set the product and version in isolinux.cfg
|
||||
replace(isolinuxcfg, r'@PRODUCT@', self.conf.product)
|
||||
replace(isolinuxcfg, r'@VERSION@', self.conf.version)
|
||||
|
||||
|
||||
# copy the grub.conf to isolinux dir
|
||||
cp(os.path.join(bootdiskdir, 'grub.conf'), self.isodir)
|
||||
|
||||
# create the initrd in isolinux dir
|
||||
initrd = os.path.join(self.isodir, 'initrd.img')
|
||||
self.__makeinitrd(initrd)
|
||||
|
||||
i.getDeps()
|
||||
i.processActions()
|
||||
i.create(os.path.join(self.isodir, 'initrd.img'))
|
||||
i.cleanUp()
|
||||
|
||||
# copy the vmlinuz to isolinux dir
|
||||
vmlinuz = os.path.join(self.conf.treedir, 'boot', 'vmlinuz-*')
|
||||
cp(vmlinuz, os.path.join(self.isodir, 'vmlinuz'))
|
||||
|
@ -14,8 +14,8 @@ class InitRD(object):
|
||||
self.conf = config
|
||||
self.yum = yum
|
||||
|
||||
self.initrddir = os.path.join(self.conf.tempdir, 'initrd')
|
||||
os.makedirs(self.initrddir)
|
||||
if not os.path.isdir(self.conf.initrddir):
|
||||
os.makedirs(self.conf.initrddir)
|
||||
|
||||
# get supported actions
|
||||
supported_actions = actions.getActions()
|
||||
@ -25,27 +25,32 @@ class InitRD(object):
|
||||
initrd_templates.append(os.path.join(self.conf.confdir, 'templates', self.conf.buildarch,
|
||||
'initrd'))
|
||||
|
||||
vars = { '@instroot@': self.conf.treedir,
|
||||
'@initrd@': self.conf.initrddir }
|
||||
self.template = Template()
|
||||
for file in initrd_templates:
|
||||
if os.path.isfile(file):
|
||||
self.template.parse(file, supported_actions)
|
||||
self.template.parse(file, supported_actions, vars)
|
||||
|
||||
self.actions = []
|
||||
|
||||
def prepare(self):
|
||||
# install needed packages
|
||||
def getPkgs(self):
|
||||
# get needed packages
|
||||
pkgs = []
|
||||
for action in filter(lambda action: hasattr(action, 'install'), self.template.actions):
|
||||
self.yum.addPackages(action.install)
|
||||
m = re.match(r'%s(.*)' % self.conf.treedir, action.install)
|
||||
if m:
|
||||
pkgs.append(m.group(1))
|
||||
|
||||
self.yum.install()
|
||||
return pkgs
|
||||
|
||||
def getDeps(self):
|
||||
# get needed dependencies
|
||||
ldd = LDD(libroot=os.path.join(self.conf.treedir, self.conf.libdir))
|
||||
for action in filter(lambda action: hasattr(action, 'getDeps'), self.template.actions):
|
||||
file = re.sub(r'@instroot@(?P<file>.*)', '%s\g<file>' % self.conf.treedir,
|
||||
action.getDeps())
|
||||
file = action.getDeps()
|
||||
ldd.getDeps(file)
|
||||
|
||||
|
||||
# resolve symlinks
|
||||
ldd.getLinks()
|
||||
|
||||
@ -54,7 +59,7 @@ class InitRD(object):
|
||||
kwargs = {}
|
||||
kwargs['src'] = dep
|
||||
kwargs['dst'] = re.sub(r'%s(?P<file>.*)' % self.conf.treedir,
|
||||
'%s\g<file>' % self.initrddir,
|
||||
'%s\g<file>' % self.conf.initrddir,
|
||||
dep)
|
||||
|
||||
new_action = actions.fileactions.Copy(**kwargs)
|
||||
@ -68,7 +73,7 @@ class InitRD(object):
|
||||
action.execute()
|
||||
|
||||
def create(self, dst):
|
||||
os.system('find %s | cpio --quiet -c -o | gzip -9 > %s' % (self.initrddir, dst))
|
||||
os.system('find %s | cpio --quiet -c -o | gzip -9 > %s' % (self.conf.initrddir, dst))
|
||||
|
||||
def cleanUp(self):
|
||||
rm(self.initrddir)
|
||||
rm(self.conf.initrddir)
|
||||
|
@ -72,12 +72,6 @@ class Yum(object):
|
||||
pl = self.yb.doPackageLists(patterns=seq(patterns))
|
||||
return pl.installed, pl.available
|
||||
|
||||
def isInstalled(self, pattern):
|
||||
print('searching for package matching %s' % pattern)
|
||||
pl = self.yb.doPackageLists(pkgnarrow='installed', patterns=[pattern])
|
||||
print('found %s' % pl.installed)
|
||||
return pl.installed
|
||||
|
||||
def download(self, packages):
|
||||
for package in seq(packages):
|
||||
print('Downloading package %s...' % package)
|
||||
@ -87,13 +81,7 @@ class Yum(object):
|
||||
return os.path.join(self.installroot, os.path.basename(fn))
|
||||
|
||||
def addPackages(self, patterns):
|
||||
# FIXME don't add packages already installed
|
||||
for pattern in seq(patterns):
|
||||
installed = self.isInstalled(pattern)
|
||||
if installed:
|
||||
print 'Package %s already installed' % installed
|
||||
return
|
||||
|
||||
print('Adding package matching %s...' % pattern)
|
||||
try:
|
||||
self.yb.install(name=pattern)
|
||||
@ -111,6 +99,9 @@ class Yum(object):
|
||||
rpmcb = Callback()
|
||||
self.yb.processTransaction(callback=cb, rpmDisplay=rpmcb)
|
||||
|
||||
self.yb.closeRpmDB()
|
||||
self.yb.close()
|
||||
|
||||
|
||||
def extract_rpm(rpmfile, destdir):
|
||||
if not os.path.isdir(destdir):
|
||||
|
Loading…
Reference in New Issue
Block a user