[PATCH 6/8] Create dicts to map between source and binary packages.

Bill Nottingham notting at redhat.com
Fri Apr 3 19:53:57 UTC 2009


This avoids repeating the operation many times later if we do it
on demand each time.

Signed-off-by: Bill Nottingham <notting at redhat.com>
---
 src/pypungi/__init__.py |   32 ++++++++++++++++++++++++++------
 1 files changed, 26 insertions(+), 6 deletions(-)

diff --git a/src/pypungi/__init__.py b/src/pypungi/__init__.py
index bd57bf8..1d2734c 100644
--- a/src/pypungi/__init__.py
+++ b/src/pypungi/__init__.py
@@ -135,6 +135,9 @@ class Pungi(pypungi.PungiBase):
         self.polist = []
         self.srpmpolist = []
         self.debuginfolist = []
+        self.srpms_build = []
+        self.srpms_fulltree = []
+        self.last_po = 0
         self.resolved_deps = {} # list the deps we've already resolved, short circuit.
 
     def _inityum(self):
@@ -409,33 +412,50 @@ class Pungi(pypungi.PungiBase):
             print >> sys.stderr, "Error: Cannot find a source rpm for %s" % srpm
             sys.exit(1)
 
+    def createSourceHashes(self):
+        """Create two dicts - one that maps binary POs to source POs, and
+           one that maps a single source PO to all binary POs it produces.
+           Requires yum still configured."""
+        self.src_by_bin = {}
+        self.bin_by_src = {}
+        self.logger.info("Generating source <-> binary package mappings")
+        (dummy1, everything, dummy2) = yum.packages.parsePackages(self.ayum.pkgSack.returnPackages(), ['*'])
+        for po in everything:
+            if po.arch == 'src':
+                continue
+            srpmpo = self.getSRPMPo(po)
+            self.src_by_bin[po] = srpmpo
+            if self.bin_by_src.has_key(srpmpo):
+                self.bin_by_src[srpmpo].append(po)
+            else:
+                self.bin_by_src[srpmpo] = [po]
+
     def getSRPMList(self):
         """Cycle through the list of package objects and
            find the sourcerpm for them.  Requires yum still
            configured and a list of package objects"""
- 
-        for po in self.polist:
-            srpmpo = self.getSRPMPo(po)
+        for po in self.polist[self.last_po:]:
+            srpmpo = self.src_by_bin[po]
             if not srpmpo in self.srpmpolist:
                 self.logger.info("Adding source package %s.%s" % (srpmpo.name, srpmpo.arch))
                 self.srpmpolist.append(srpmpo)
+        self.last_po = len(self.polist)
 
     def resolvePackageBuildDeps(self):
         """Make the package lists self hosting. Requires yum
            still configured, a list of package objects, and a
            a list of source rpms."""
         deppass = 1
-        checked_srpms = []
         while 1:
             self.logger.info("Resolving build dependencies, pass %d" % (deppass))
             prev = list(self.ayum.tsInfo.getMembers())
-            for srpm in self.srpmpolist[len(checked_srpms):]:
+            for srpm in self.srpmpolist[len(self.srpms_build):]:
                 self.getPackageDeps(srpm)
             for txmbr in self.ayum.tsInfo:
                 if txmbr.po.arch != 'src' and txmbr.po not in self.polist:
                     self.polist.append(txmbr.po)
+            self.srpms_build = list(self.srpmpolist)
             # Now that we've resolved deps, refresh the source rpm list
-            checked_srpms = list(self.srpmpolist)
             self.getSRPMList()
             deppass = deppass + 1
             if len(prev) == len(self.ayum.tsInfo.getMembers()):
-- 
1.6.2




More information about the Fedora-buildsys-list mailing list