Call lorax as a process not a library

Doing this allows lorax to move to DNF (and Python3) without needing to
wait for pungi to be updated.
This commit is contained in:
Brian C. Lane 2015-02-11 16:13:22 -08:00 committed by Dennis Gilmore
parent 9947c7e0cd
commit 13526d1c49
2 changed files with 49 additions and 43 deletions

View File

@ -20,7 +20,6 @@ import os
import re import re
import shutil import shutil
import sys import sys
import gzip
import pungi.util import pungi.util
import pprint import pprint
import lockfile import lockfile
@ -29,7 +28,6 @@ import urlgrabber.progress
import subprocess import subprocess
import createrepo import createrepo
import ConfigParser import ConfigParser
import pylorax
from fnmatch import fnmatch from fnmatch import fnmatch
import arch as arch_module import arch as arch_module
@ -1371,59 +1369,67 @@ class Pungi(PungiBase):
def doBuildinstall(self): def doBuildinstall(self):
"""Run lorax on the tree.""" """Run lorax on the tree."""
# the old ayum object has transaction data that confuse lorax, reinit. cmd = ["lorax"]
self._inityum() cmd.extend(["--workdir", self.workdir])
cmd.extend(["--logfile", os.path.join(self.config.get('pungi', 'destdir'), 'logs/lorax.log')])
try:
# Convert url method to a repo
self.ksparser.handler.repo.methodToRepo()
except:
pass
for repo in self.ksparser.handler.repo.repoList:
if repo.mirrorlist:
# The not bool() thing is because pykickstart is yes/no on
# whether to ignore groups, but yum is a yes/no on whether to
# include groups. Awkward.
cmd.extend(["--mirrorlist", repo.mirrorlist])
else:
cmd.extend(["--source", repo.baseurl])
# Add the repo in the destdir to our yum object # Add the repo in the destdir to our yum object
self._add_yum_repo('ourtree', cmd.extend(["--source", "file://%s" % self.topdir])
'file://%s' % self.topdir, cmd.extend(["--product", self.config.get('pungi', 'family')])
cost=10) cmd.extend(["--version", self.config.get('pungi', 'version')])
cmd.extend(["--release", "%s %s" % (self.config.get('pungi', 'family'), self.config.get('pungi', 'version'))])
product = self.config.get('pungi', 'family') if self.config.get('pungi', 'variant'):
version = self.config.get('pungi', 'version') cmd.extend(["--variant", self.config.get('pungi', 'variant')])
release = '%s %s' % (self.config.get('pungi', 'family'), self.config.get('pungi', 'version')) cmd.extend(["--bugurl", self.config.get('pungi', 'bugurl')])
if self.config.get('pungi', 'isfinal'):
variant = self.config.get('pungi', 'variant') cmd.append("--isfinal")
bugurl = self.config.get('pungi', 'bugurl') cmd.extend(["--volid", self._shortenVolID()])
isfinal = self.config.get('pungi', 'isfinal')
volid = self._shortenVolID()
workdir = self.workdir
outputdir = self.topdir
# on ppc64 we need to tell lorax to only use ppc64 packages so that the media will run on all 64 bit ppc boxes # on ppc64 we need to tell lorax to only use ppc64 packages so that the media will run on all 64 bit ppc boxes
if self.tree_arch == 'ppc64': if self.tree_arch == 'ppc64':
self.ayum.arch.setup_arch('ppc64') cmd.extend(["--buildarch", "ppc64"])
self.ayum.compatarch = 'ppc64'
elif self.tree_arch == 'ppc64le': elif self.tree_arch == 'ppc64le':
self.ayum.arch.setup_arch('ppc64le') cmd.extend(["--buildarch", "ppc64le"])
self.ayum.compatarch = 'ppc64le'
# Only supported mac hardware is x86 make sure we only enable mac support on arches that need it # Only supported mac hardware is x86 make sure we only enable mac support on arches that need it
if self.tree_arch in ['x86_64']: if self.tree_arch in ['x86_64'] and not self.config.getboolean('pungi','nomacboot'):
if self.config.getboolean('pungi','nomacboot'): cmd.append("--macboot")
domacboot = False
else:
domacboot = True
else: else:
domacboot = False cmd.append("--nomacboot")
# run the command
lorax = pylorax.Lorax()
try:
conf_file = self.config.get('lorax', 'conf_file')
lorax.configure(conf_file=conf_file)
except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
lorax.configure()
try: try:
installpkgs = self.config.get('lorax', 'installpkgs').split(" ") cmd.extend(["--conf", self.config.get('lorax', 'conf_file')])
except (ConfigParser.NoSectionError, ConfigParser.NoOptionError): except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
installpkgs = None pass
lorax.run(self.ayum, product=product, version=version, release=release, try:
variant=variant, bugurl=bugurl, isfinal=isfinal, domacboot=domacboot, cmd.extend(["--installpkgs", self.config.get('lorax', 'installpkgs')])
workdir=workdir, outputdir=outputdir, volid=volid, installpkgs=installpkgs) except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
pass
# Allow the output directory to exist.
cmd.append("--force")
# MUST be last in the list
cmd.append(self.topdir)
self.logger.info(" ".join(cmd))
pypungi.util._doRunCommand(cmd, self.logger)
# 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))

View File

@ -44,7 +44,7 @@ def _doRunCommand(command, logger, rundir='/tmp', output=subprocess.PIPE, error=
if p1.returncode != 0: if p1.returncode != 0:
logger.error("Got an error from %s" % command[0]) logger.error("Got an error from %s" % command[0])
logger.error(err) logger.error(err)
raise OSError, "Got an error from %s: %s" % (command[0], err) raise OSError, "Got an error (%d) from %s: %s" % (p1.returncode, command[0], err)
def _link(local, target, logger, force=False): def _link(local, target, logger, force=False):
"""Simple function to link or copy a package, removing target optionally.""" """Simple function to link or copy a package, removing target optionally."""