collect the coupling stuff together
authorJF Ding <jian-feng.ding@intel.com>
Wed, 8 Feb 2012 12:31:11 +0000 (20:31 +0800)
committerJF Ding <jian-feng.ding@intel.com>
Wed, 8 Feb 2012 12:31:11 +0000 (20:31 +0800)
mic/utils/misc.py
plugins/backend/yumpkgmgr.py
plugins/backend/zypppkgmgr.py

index 27d2ea388dc33922bea86755d8b6f3a691d7d072..e47b3bbbf79e0cc3c7a4dc6d09800b9857f3df56 100644 (file)
@@ -49,6 +49,10 @@ import runner
 
 from mic import msger
 
+RPM_RE  = re.compile("(.*)\.(.*) (.*)-(.*)")
+RPM_FMT = "%(name)s.%(arch)s %(ver_rel)s"
+SRPM_RE = re.compile("(.*)-(\d+.*)-(\d+\.\d+).src.rpm")
+
 def get_md5sum(fpath):
     blksize = 65536 # should be optimized enough
 
@@ -477,13 +481,13 @@ def get_package(pkg, repometadata, arch = None):
 def get_source_name(pkg, repometadata):
 
     def get_bin_name(pkg):
-        m = re.match("(.*)\.(.*) (.*)-(.*)", pkg)
+        m = RPM_RE.match(pkg)
         if m:
             return m.group(1)
         return None
 
     def get_src_name(srpm):
-        m = re.match("(.*)-(\d+.*)-(\d+\.\d+).src.rpm", srpm)
+        m = SRPM_RE.match(srpm)
         if m:
             return m.group(1)
         return None
@@ -664,7 +668,7 @@ def SrcpkgsDownload(pkgs, repometadata, instroot, cachedir):
         return None
 
     def get_src_name(srpm):
-        m = re.match("(.*)-(\d+.*)-(\d+\.\d+).src.rpm", srpm)
+        m = SRPM_RE.match(srpm)
         if m:
             return m.group(1)
         return None
index f5804f83b2c43f877553693bcf73194da21f911f..67fa6dd4e1c9d2cd4048e89562b247807771744c 100644 (file)
@@ -325,7 +325,11 @@ class Yum(BackendPlugin, yum.YumBase):
 
         # record all pkg and the content
         for pkg in dlpkgs:
-            pkg_long_name = "%s.%s %s" % (pkg.name, pkg.arch, pkg.printVer())
+            pkg_long_name = misc.RPM_FMT % {
+                                'name': pkg.name,
+                                'arch': pkg.arch,
+                                'ver_rel': pkg.printVer(),
+                            }
             self.__pkgs_content[pkg_long_name] = pkg.files
             license = pkg.license
             if license in self.__pkgs_license.keys():
index a4015a406c214cafcfcc7130fe69fb46be22d5b6..02a922cefc1a04c86edac93a475d8e19fe538d2b 100644 (file)
@@ -386,18 +386,20 @@ class Zypp(BackendPlugin):
             license = ''
             if pkg.name() in localpkgs:
                 hdr = rpmmisc.readRpmHeader(self.ts, self.localpkgs[pkg.name()])
-                pkg_long_name = "%s.%s %s-%s" \
-                                % (hdr['name'],
-                                   hdr['arch'],
-                                   hdr['version'],
-                                   hdr['release'])
+                pkg_long_name = misc.RPM_FMT % {
+                                    'name': hdr['name'],
+                                    'arch': hdr['arch'],
+                                    'ver_rel': '%s-%s' % (hdr['version'],
+                                                          hdr['release']),
+                                }
                 license = hdr['license']
 
             else:
-                pkg_long_name = "%s.%s %s" \
-                                % (pkg.name(),
-                                   pkg.arch(),
-                                   pkg.edition())
+                pkg_long_name = misc.RPM_FMT % {
+                                    'name': pkg.name(),
+                                    'arch': pkg.arch(),
+                                    'ver_rel': pkg.edition(),
+                                }
 
                 package = zypp.asKindPackage(pkg)
                 license = package.license()