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