Fixes #53432.
authorkarltk <karltk@gentoo.org>
Sun, 10 Oct 2004 00:28:37 +0000 (00:28 -0000)
committerkarltk <karltk@gentoo.org>
Sun, 10 Oct 2004 00:28:37 +0000 (00:28 -0000)
svn path=/; revision=151

trunk/src/equery/ChangeLog
trunk/src/equery/equery
trunk/src/gentoolkit/ChangeLog
trunk/src/gentoolkit/gentoolkit.py

index 8531a70dd3a376e55f45bff88706760ba0801be0..96dac7b4123c19aa8a08e720e787b5db136d90a1 100644 (file)
@@ -1,5 +1,6 @@
 2004-10-10 Karl Trygve Kalleberg <karltk@gentoo.org>
        * Added unit tests for all supported commands
+       * Fixed printing order and recognition of overlay, #53432.
 
 2004-09-30 Karl Trygve Kalleberg <karltk@gentoo.org>
        * Added unit tests for --help
index e31fc707ea05b1ea1d7447734cfab5871515abb6..dea4d7bc8de03743c6b9490a073d2a80450cf8d1 100755 (executable)
@@ -1074,50 +1074,71 @@ class CmdListPackages(Command):
             if name == ".*":
                 sname = "all packages"
             if not Config["piping"]:
-                print_info(1, "Searching for " + pp.cpv(sname) + " in " + pp.cpv(scat) + " among:")
-                if opts["includeInstalled"]:
-                    print_info(1, pp.section(" *") + " installed packages")
-                if opts["includePortTree"]:
-                    print_info(1, pp.section(" *") + " Portage tree (" + pp.path(gentoolkit.settings["PORTDIR"]) + ")")
-                if opts["includeOverlayTree"]:
-                    print_info(1, pp.section(" *") + " overlay tree (" + pp.path(gentoolkit.settings["PORTDIR_OVERLAY"]) + ")")
-        
-        matches = package_finder(filter_fn)
+                print_info(1, "[ Searching for " + pp.cpv(sname) + " in " + pp.cpv(scat) + " among: ]")
+
 
         rx = re.compile(cat + "/" + name + "-" + ver + "(-" + rev + ")?")
+
+        matches = package_finder(filter_fn)
+
+        if opts["includeInstalled"]:
+            self._print_installed(matches, rx)
+        
+        if opts["includePortTree"]:
+            self._print_porttree(matches, rx)
+        
+        if opts["includeOverlayTree"]:
+            self._print_overlay(matches, rx)
+
+    def _get_mask_status(self, pkg):
+        pkgmask = 0
+        if pkg.is_masked():
+            pkgmask = pkgmask + 3
+        keywords = pkg.get_env_var("KEYWORDS").split()
+        if "~" + gentoolkit.settings["ARCH"] in keywords:
+            pkgmask = pkgmask + 1
+        elif "-*" in keywords or "-" + gentoolkit.settings["ARCH"] in keywords:
+            pkgmask = pkgmask + 2
+        return pkgmask
+
+    def _generic_print(self, header, exclude, matches, rx, status):
+        print_info(1, header)
+
         pfxmodes = [ "---", "I--", "-P-", "--O" ]
         maskmodes = [ "  ", " ~", " -", "M ", "M~", "M-" ]
-        for pkg in matches:
-            status = 0
-            if pkg.is_installed():
-                status = 1
-            elif pkg.is_overlay():
-                status = 3
-            else:
-                status = 2
 
-            # Determining mask status
-            pkgmask = 0
-            if pkg.is_masked():
-                pkgmask = pkgmask + 3
-            keywords = pkg.get_env_var("KEYWORDS").split()
-            if "~" + gentoolkit.settings["ARCH"] in keywords:
-                pkgmask = pkgmask + 1
-            elif "-*" in keywords or "-" + gentoolkit.settings["ARCH"] in keywords:
-                pkgmask = pkgmask + 2
+        for pkg in matches:
+            if exclude(pkg):
+                continue
 
-            # Determining SLOT value
+            pkgmask = self._get_mask_status(pkg)
+            
             slot = pkg.get_env_var("SLOT")
 
-            if (status == 1 and opts["includeInstalled"]) or \
-               (status == 2 and opts["includePortTree"]) or \
-               (status == 3 and opts["includeOverlayTree"]):
-                if rx.search(pkg.get_cpv()):
-                    if Config["piping"]:
-                        print_info(0, pkg.get_cpv())
-                    else:
-                        print_info(0, "[" + pp.installedflag(pfxmodes[status]) + "] [" + pp.maskflag(maskmodes[pkgmask]) + "] " + pp.cpv(pkg.get_cpv()) + " (" + pp.slot(slot) + ")")
-                    
+            if rx.search(pkg.get_cpv()):
+                if Config["piping"]:
+                    print_info(0, pkg.get_cpv())
+                else:
+                    print_info(0, "[" + pp.installedflag(pfxmodes[status]) + "] [" + pp.maskflag(maskmodes[pkgmask]) + "] " + pp.cpv(pkg.get_cpv()) + " (" + pp.slot(slot) + ")")
+
+    def _print_overlay(self, matches, rx):
+        self._generic_print(
+            pp.section(" *") + " overlay tree (" + pp.path(gentoolkit.settings["PORTDIR_OVERLAY"]) + ")",
+            lambda x: not x.is_overlay(),
+            matches, rx, 3)
+            
+    def _print_porttree(self, matches, rx):
+        self._generic_print(
+            pp.section(" *") + " Portage tree (" + pp.path(gentoolkit.settings["PORTDIR"]) + ")",
+            lambda x: x.is_overlay() or x.is_installed(),
+            matches, rx, 2)
+                
+    def _print_installed(self, matches, rx):
+        self._generic_print(
+            pp.section(" *") + " installed packages",
+            lambda x: not x.is_installed(),
+            matches, rx, 1)
+
     def shortHelp(self):
         return pp.localoption("<local-opts> ") + pp.pkgquery("pkgspec") + " - list all packages matching " + pp.pkgquery("pkgspec")
     def longHelp(self):
index 5ea8ae42181bea5fa69f66b0d260d7db6357e279..72b05fe6ff277bcd444231660aad74adfc90bf4c 100644 (file)
@@ -1,3 +1,6 @@
+2004-10-10: Karl Trygve Kalleberg <karltk@gentoo.org>
+       * Fixed is_overlay() to report properly, #53432.
+
 2004-09-27: Karl Trygve Kalleberg <karltk@gentoo.org>
        * Added find_installed_packages
 
index 50aad813a3bc7b0e57d0b3a5116c0f5337bc3cc1..07eea39bac1d5efb5ccd2f3101aeaf9a461a7cac 100644 (file)
@@ -118,7 +118,7 @@ class Package:
                return os.path.exists(self._db.getpath())
        def is_overlay(self):
                dir,ovl=portage.portdb.findname2(self._cpv)
-               return ovl
+               return ovl != settings["PORTDIR"]
        def is_masked(self):
                """Returns true if this package is masked against installation. Note: We blindly assume that
                the package actually exists on disk somewhere."""