[yum-commits] 4 commits - repoquery.py

James Antill james at osuosl.org
Thu Jun 3 05:59:04 UTC 2010


 repoquery.py |   59 ++++++++++++++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 48 insertions(+), 11 deletions(-)

New commits:
commit f14a30d10895f75d55172eb4d1b5e48ddffe4032
Author: James Antill <james at and.org>
Date:   Thu Jun 3 01:55:44 2010 -0400

    Sort the packages, when we have plain pkgs, basically free!

diff --git a/repoquery.py b/repoquery.py
index 0e2d393..8dd6fb7 100755
--- a/repoquery.py
+++ b/repoquery.py
@@ -544,6 +544,7 @@ class YumBaseQuery(yum.YumBase):
             iq = None
             rq = None
             qf = self.options.queryformat or std_qf["nevra"]
+            pkgs = sorted(pkgs)
         for pkg in pkgs:
             if plain_pkgs:
                 if isinstance(pkg, yum.packages.YumInstalledPackage):
commit fa8b6ca764cc44e125c46ca935d2d348bf4dcf95
Author: James Antill <james at and.org>
Date:   Thu Jun 3 01:39:05 2010 -0400

    Don't match '*' against each pkg. for all, just get all of them

diff --git a/repoquery.py b/repoquery.py
index 4445cf4..0e2d393 100755
--- a/repoquery.py
+++ b/repoquery.py
@@ -449,6 +449,10 @@ class YumBaseQuery(yum.YumBase):
 
     def returnPkgList(self, **kwargs):
         pkgs = []
+        if 'patterns' in kwargs:
+            if len(kwargs['patterns']) == 1 and kwargs['patterns'][0] == '*':
+                kwargs['patterns'] = None
+
         if self.options.pkgnarrow == "repos":
             # self.pkgSack is a yum.packageSack.MetaSack
             if self.conf.showdupesfromrepos:
commit 2486fa64cfb677f22e180c47bdf34f3df78625bb
Author: James Antill <james at and.org>
Date:   Thu Jun 3 01:38:14 2010 -0400

    Don't convert the user qf for each package, when we can now do it once.

diff --git a/repoquery.py b/repoquery.py
index f92b72e..4445cf4 100755
--- a/repoquery.py
+++ b/repoquery.py
@@ -134,11 +134,15 @@ class pkgQuery:
         self.qf = qf
         self.name = pkg.name
         self.classname = None
+        self._translated_qf = None
     
     def __getitem__(self, item):
         item = item.lower()
         if hasattr(self, "fmt_%s" % item):
             return getattr(self, "fmt_%s" % item)()
+        if hasattr(self.pkg, item):
+            return getattr(self.pkg, item)
+
         res = None
         convert = None
 
@@ -195,15 +199,17 @@ class pkgQuery:
     def fmt_queryformat(self):
 
         if not self.qf:
-            qf = std_qf["nevra"]
-        else:
+            return self.fmt_nevra()
+
+        if self._translated_qf is None:
             qf = self.qf
 
-        qf = qf.replace("\\n", "\n")
-        qf = qf.replace("\\t", "\t")
-        pattern = re.compile('%([-\d]*?){([:\.\w]*?)}')
-        fmt = re.sub(pattern, r'%(\2)\1s', qf)
-        return fmt % self
+            qf = qf.replace("\\n", "\n")
+            qf = qf.replace("\\t", "\t")
+            pattern = re.compile('%([-\d]*?){([:\.\w]*?)}')
+            fmt = re.sub(pattern, r'%(\2)\1s', qf)
+            self._translated_qf = fmt
+        return self._translated_qf % self
 
     def fmt_requires(self, **kw):
         return "\n".join(self.prco('requires'))
commit 47a104eaa80d399b771302523a4a7509da680441
Author: James Antill <james at and.org>
Date:   Thu Jun 3 01:12:29 2010 -0400

    Don't create N PkgQuery objects, when we can reuse them.

diff --git a/repoquery.py b/repoquery.py
index 2d053a6..f92b72e 100755
--- a/repoquery.py
+++ b/repoquery.py
@@ -400,7 +400,7 @@ class YumBaseQuery(yum.YumBase):
         self.pkgops = pkgops
         self.sackops = sackops
 
-    def queryPkgFactory(self, pkgs):
+    def queryPkgFactory(self, pkgs, plain_pkgs=False):
         """
         For each given package, create a query.
 
@@ -414,6 +414,12 @@ class YumBaseQuery(yum.YumBase):
             if isinstance(pkg, yum.packages.YumInstalledPackage):
                 if self.options.pkgnarrow not in ('all', 'installed', 'extras'):
                     continue
+
+            if plain_pkgs:
+                qpkgs.append(pkg)
+                continue
+
+            if isinstance(pkg, yum.packages.YumInstalledPackage):
                 qpkg = instPkgQuery(pkg, qf)
             else:
                 qpkg = repoPkgQuery(pkg, qf)
@@ -489,9 +495,9 @@ class YumBaseQuery(yum.YumBase):
                     grps.append(grp)
         return grps
                     
-    def matchPkgs(self, items):
+    def matchPkgs(self, items, plain_pkgs=False):
         pkgs = self.returnPkgList(patterns=items)
-        return self.queryPkgFactory(pkgs)
+        return self.queryPkgFactory(pkgs, plain_pkgs)
 
     def matchSrcPkgs(self, items):
         srpms = []
@@ -504,6 +510,7 @@ class YumBaseQuery(yum.YumBase):
         return srpms
     
     def runQuery(self, items):
+        plain_pkgs = False
         if self.options.group:
             pkgs = self.matchGroups(items)
         else:
@@ -511,7 +518,9 @@ class YumBaseQuery(yum.YumBase):
                 pkgs = self.matchSrcPkgs(items)
 
             else:
-                pkgs = self.matchPkgs(items)
+                if not self.sackops:
+                    plain_pkgs = True
+                pkgs = self.matchPkgs(items, plain_pkgs=plain_pkgs)
                 for prco in items:
                     for oper in self.sackops:
                         try:
@@ -521,7 +530,24 @@ class YumBaseQuery(yum.YumBase):
                         except queryError, e:
                             self.logger.error( e.msg)
 
+        if plain_pkgs:
+            iq = None
+            rq = None
+            qf = self.options.queryformat or std_qf["nevra"]
         for pkg in pkgs:
+            if plain_pkgs:
+                if isinstance(pkg, yum.packages.YumInstalledPackage):
+                    if iq is None:
+                        iq = instPkgQuery(pkg, qf)
+                    iq.pkg = pkg
+                    iq.name = pkg.name
+                    pkg = iq
+                else:
+                    if rq is None:
+                        rq = instPkgQuery(pkg, qf)
+                    rq.pkg = pkg
+                    rq.name = pkg.name
+                    pkg = rq
             if not self.pkgops:
                 print to_unicode(pkg)
             for oper in self.pkgops:


More information about the Yum-commits mailing list