from mic.utils.rpmmisc import readRpmHeader, RPMInstallCallback
from mic.chroot import cleanup_mounts, setup_chrootenv, cleanup_chrootenv
-RPMTRANS_FLAGS = [rpm.RPMTRANS_FLAG_ALLFILES,
- rpm.RPMTRANS_FLAG_NOSCRIPTS,
- rpm.RPMTRANS_FLAG_NOTRIGGERS,
- rpm.RPMTRANS_FLAG_NODOCS]
+RPMTRANS_FLAGS = [
+ rpm.RPMTRANS_FLAG_ALLFILES,
+ rpm.RPMTRANS_FLAG_NOSCRIPTS,
+ rpm.RPMTRANS_FLAG_NOTRIGGERS,
+ ]
-RPMVSF_FLAGS = [rpm._RPMVSF_NOSIGNATURES,
- rpm._RPMVSF_NODIGESTS]
+RPMVSF_FLAGS = [
+ rpm._RPMVSF_NOSIGNATURES,
+ rpm._RPMVSF_NODIGESTS
+ ]
class MiniBackend(object):
- def __init__(self, rootdir, repomd=None):
+ def __init__(self, rootdir, arch=None, repomd=None):
self._ts = None
self.rootdir = os.path.abspath(rootdir)
+ self.arch = arch
self.repomd = repomd
self.dlpkgs = []
self.localpkgs = {}
nonexist = []
for pkg in self.dlpkgs:
try:
- localpth = misc.get_package(pkg, self.repomd, None)
+ localpth = misc.get_package(pkg, self.repomd, self.arch)
if not localpth:
# skip non-existent rpm
nonexist.append(pkg)
script_fp = os.path.join('/tmp', os.path.basename(tmpfp))
subprocess.call([prog, script_fp, arg], preexec_fn=mychroot)
except (OSError, IOError), err:
- raise RuntimeError(err)
+ msger.warning(str(err))
finally:
os.unlink(tmpfp)
class Bootstrap(object):
- def __init__(self, rootdir, distro):
+ def __init__(self, rootdir, distro, arch=None):
self.rootdir = rootdir
self.distro = distro
+ self.arch = arch
self.pkgslist = []
self.repomd = None
def create(self, repomd, pkglist):
try:
pkgmgr = MiniBackend(self.get_rootdir())
+ pkgmgr.arch = self.arch
pkgmgr.repomd = repomd
map(pkgmgr.selectPackage, pkglist)
pkgmgr.runInstall()
cwd = os.getcwd()
# create bootstrap and run mic in bootstrap
- bsenv = bootstrap.Bootstrap(rootdir, distro)
+ bsenv = bootstrap.Bootstrap(rootdir, distro, cropts['arch'])
try:
msger.info("Creating %s bootstrap ..." % distro)
bsenv.create(cropts['repomd'], pkglist)
else:
raise errors.BootstrapError("Failed to create bootstrap: %s" % err)
except RuntimeError, err:
- raise errors.BootstrapError("Failed to create bootstrap: %s" % err)
+ raise errors.BootstrapError("Failed to run in bootstrap: %s" % err)
finally:
bsenv.cleanup()
def get_package(pkg, repometadata, arch = None):
ver = ""
target_repo = None
+ if not arch:
+ arches = []
+ elif arch not in rpmmisc.archPolicies:
+ arches = [arch]
+ else:
+ arches = rpmmisc.archPolicies[arch].split(':')
+ arches.append('noarch')
+
for repo in repometadata:
if repo["primary"].endswith(".xml"):
root = xmlparse(repo["primary"])
ns = ns[0:ns.rindex("}")+1]
for elm in root.getiterator("%spackage" % ns):
if elm.find("%sname" % ns).text == pkg:
- if elm.find("%sarch" % ns).text != "src":
+ if elm.find("%sarch" % ns).text in arches:
version = elm.find("%sversion" % ns)
tmpver = "%s-%s" % (version.attrib['ver'], version.attrib['rel'])
if tmpver > ver:
break
if repo["primary"].endswith(".sqlite"):
con = sqlite.connect(repo["primary"])
- if not arch:
- for row in con.execute("select version, release,location_href from packages where name = \"%s\" and arch != \"src\"" % pkg):
+ if arch:
+ sql = 'select version, release, location_href from packages ' \
+ 'where name = "%s" and arch IN ("%s")' % \
+ (pkg, '","'.join(arches))
+ for row in con.execute(sql):
tmpver = "%s-%s" % (row[0], row[1])
if tmpver > ver:
pkgpath = "%s" % row[2]
target_repo = repo
break
else:
- for row in con.execute("select version, release,location_href from packages where name = \"%s\"" % pkg):
+ sql = 'select version, release, location_href from packages ' \
+ 'where name = "%s"' % pkg
+ for row in con.execute(sql):
tmpver = "%s-%s" % (row[0], row[1])
if tmpver > ver:
pkgpath = "%s" % row[2]