refine code with SAM check 76/237676/5
authorbiao716.wang <biao716.wang@samsung.com>
Thu, 2 Jul 2020 09:40:52 +0000 (18:40 +0900)
committerbiao716.wang <biao716.wang@samsung.com>
Fri, 3 Jul 2020 05:17:26 +0000 (14:17 +0900)
Change-Id: Id28233d710f227697a93672f2ea5e614dc1c7d4f
Signed-off-by: biao716.wang <biao716.wang@samsung.com>
mic/utils/misc.py
plugins/backend/zypppkgmgr.py

index fa8a50d..64bda2d 100755 (executable)
@@ -715,26 +715,25 @@ def get_package(pkg, repometadata, arch = None):
             ns = root.getroot().tag
             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 in arches:
-                        if repo["priority"] != None:
-                            tmpprior = int(repo["priority"])
-                            if tmpprior < priority:
-                                priority = tmpprior
-                                location = elm.find("%slocation" % ns)
-                                pkgpath = "%s" % location.attrib['href']
-                                target_repo = repo
-                                break
-                            elif tmpprior > priority:
-                                break
-                        version = elm.find("%sversion" % ns)
-                        tmpver = "%s-%s" % (version.attrib['ver'], version.attrib['rel'])
-                        if tmpver > ver:
-                            ver = tmpver
+                if elm.find("%sname" % ns).text == pkg and elm.find("%sarch" % ns).text in arches:
+                    if repo["priority"] != None:
+                        tmpprior = int(repo["priority"])
+                        if tmpprior < priority:
+                            priority = tmpprior
                             location = elm.find("%slocation" % ns)
                             pkgpath = "%s" % location.attrib['href']
                             target_repo = repo
-                        break
+                            break
+                        elif tmpprior > priority:
+                            break
+                    version = elm.find("%sversion" % ns)
+                    tmpver = "%s-%s" % (version.attrib['ver'], version.attrib['rel'])
+                    if tmpver > ver:
+                        ver = tmpver
+                        location = elm.find("%slocation" % ns)
+                        pkgpath = "%s" % location.attrib['href']
+                        target_repo = repo
+                    break
         if repo["primary"].endswith(".sqlite"):
             con = sqlite.connect(repo["primary"])
             if arch:
@@ -898,18 +897,7 @@ def get_pkglist_in_comps(group, comps):
 def is_statically_linked(binary):
     return ", statically linked, " in runner.outs(['file', binary])
 
-def setup_qemu_emulator(rootdir, arch):
-    qemu_emulators = []
-    # mount binfmt_misc if it doesn't exist
-    if not os.path.exists("/proc/sys/fs/binfmt_misc"):
-        modprobecmd = find_binary_path("modprobe")
-        runner.show([modprobecmd, "binfmt_misc"])
-    if not os.path.exists("/proc/sys/fs/binfmt_misc/register"):
-        mountcmd = find_binary_path("mount")
-        runner.show([mountcmd, "-t", "binfmt_misc", "none", "/proc/sys/fs/binfmt_misc"])
-
-    # qemu_emulator is a special case, we can't use find_binary_path
-    # qemu emulator should be a statically-linked executable file
+def get_qemu_arm_binary(arch):
     if arch == "aarch64":
         node = "/proc/sys/fs/binfmt_misc/aarch64"
         if os.path.exists("/usr/bin/qemu-arm64") and is_statically_linked("/usr/bin/qemu-arm64"):
@@ -937,6 +925,21 @@ def setup_qemu_emulator(rootdir, arch):
         if not os.path.exists("/usr/bin/%s" % arm_binary):
             raise CreatorError("Please install a statically-linked %s" % arm_binary)
 
+    return (arm_binary, node)
+
+def setup_qemu_emulator(rootdir, arch):
+    qemu_emulators = []
+    # mount binfmt_misc if it doesn't exist
+    if not os.path.exists("/proc/sys/fs/binfmt_misc"):
+        modprobecmd = find_binary_path("modprobe")
+        runner.show([modprobecmd, "binfmt_misc"])
+    if not os.path.exists("/proc/sys/fs/binfmt_misc/register"):
+        mountcmd = find_binary_path("mount")
+        runner.show([mountcmd, "-t", "binfmt_misc", "none", "/proc/sys/fs/binfmt_misc"])
+
+    # qemu_emulator is a special case, we can't use find_binary_path
+    # qemu emulator should be a statically-linked executable file
+    arm_binary, node = get_qemu_arm_binary(arch)
     qemu_emulator = "/usr/bin/%s" % arm_binary
 
     if not os.path.exists(rootdir + "/usr/bin"):
index 51bd673..1c0a9df 100644 (file)
@@ -835,6 +835,26 @@ class Zypp(BackendPlugin):
                 for e in errors:
                     msger.warning(e[0])
                 raise RepoError('Could not run transaction.')
+    def show_unresolved_dependencies_msg(self, unresolved_dependencies):
+        for pkg, need, needflags, sense, key in unresolved_dependencies:
+
+            package = '-'.join(pkg)
+
+            if needflags == rpm.RPMSENSE_LESS:
+                deppkg = ' < '.join(need)
+            elif needflags == rpm.RPMSENSE_EQUAL:
+                deppkg = ' = '.join(need)
+            elif needflags == rpm.RPMSENSE_GREATER:
+                deppkg = ' > '.join(need)
+            else:
+                deppkg = '-'.join(need)
+
+            if sense == rpm.RPMDEP_SENSE_REQUIRES:
+                msger.warning("[%s] Requires [%s], which is not provided" \
+                              % (package, deppkg))
+
+            elif sense == rpm.RPMDEP_SENSE_CONFLICTS:
+                msger.warning("[%s] Conflicts with [%s]" % (package, deppkg))
 
     def installPkgs(self, package_objects):
         if not self.ts:
@@ -906,25 +926,7 @@ class Zypp(BackendPlugin):
                     raise RepoError('Could not run transaction.')
 
         else:
-            for pkg, need, needflags, sense, key in unresolved_dependencies:
-                package = '-'.join(pkg)
-
-                if needflags == rpm.RPMSENSE_LESS:
-                    deppkg = ' < '.join(need)
-                elif needflags == rpm.RPMSENSE_EQUAL:
-                    deppkg = ' = '.join(need)
-                elif needflags == rpm.RPMSENSE_GREATER:
-                    deppkg = ' > '.join(need)
-                else:
-                    deppkg = '-'.join(need)
-
-                if sense == rpm.RPMDEP_SENSE_REQUIRES:
-                    msger.warning("[%s] Requires [%s], which is not provided" \
-                                  % (package, deppkg))
-
-                elif sense == rpm.RPMDEP_SENSE_CONFLICTS:
-                    msger.warning("[%s] Conflicts with [%s]" % (package, deppkg))
-
+            self.show_unresolved_dependencies_msg(unresolved_dependencies)
             raise RepoError("Unresolved dependencies, transaction failed.")
 
     def __initialize_transaction(self):