From a3b7305ecd4454d9924abbc4ac055d571214b017 Mon Sep 17 00:00:00 2001 From: Gui Chen Date: Tue, 21 Aug 2012 14:52:35 +0800 Subject: [PATCH] correct arch support in misc.get_package and bootstrap Signed-off-by: Gui Chen --- mic/bootstrap.py | 26 ++++++++++++++++---------- mic/rt_util.py | 4 ++-- mic/utils/misc.py | 21 +++++++++++++++++---- 3 files changed, 35 insertions(+), 16 deletions(-) diff --git a/mic/bootstrap.py b/mic/bootstrap.py index 2916870..959516e 100644 --- a/mic/bootstrap.py +++ b/mic/bootstrap.py @@ -27,18 +27,22 @@ from mic.utils import errors, proxy, misc 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 = {} @@ -87,7 +91,7 @@ class MiniBackend(object): 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) @@ -139,14 +143,15 @@ class MiniBackend(object): 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 @@ -165,6 +170,7 @@ class Bootstrap(object): def create(self, repomd, pkglist): try: pkgmgr = MiniBackend(self.get_rootdir()) + pkgmgr.arch = self.arch pkgmgr.repomd = repomd map(pkgmgr.selectPackage, pkglist) pkgmgr.runInstall() diff --git a/mic/rt_util.py b/mic/rt_util.py index 3193c99..f8022a4 100644 --- a/mic/rt_util.py +++ b/mic/rt_util.py @@ -56,7 +56,7 @@ def bootstrap_mic(argv=None): 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) @@ -73,7 +73,7 @@ def bootstrap_mic(argv=None): 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() diff --git a/mic/utils/misc.py b/mic/utils/misc.py index f4e5e4d..854f648 100644 --- a/mic/utils/misc.py +++ b/mic/utils/misc.py @@ -645,6 +645,14 @@ def get_arch(repometadata): 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"]) @@ -652,7 +660,7 @@ def get_package(pkg, repometadata, arch = None): 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: @@ -663,15 +671,20 @@ def get_package(pkg, repometadata, arch = None): 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] -- 2.7.4