correct arch support in misc.get_package and bootstrap
authorGui Chen <gui.chen@intel.com>
Tue, 21 Aug 2012 06:52:35 +0000 (14:52 +0800)
committerGui Chen <gui.chen@intel.com>
Tue, 21 Aug 2012 15:33:05 +0000 (23:33 +0800)
Signed-off-by: Gui Chen <gui.chen@intel.com>
mic/bootstrap.py
mic/rt_util.py
mic/utils/misc.py

index 2916870..959516e 100644 (file)
@@ -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()
index 3193c99..f8022a4 100644 (file)
@@ -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()
 
index f4e5e4d..854f648 100644 (file)
@@ -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]