Add qpkg --dups functionality to equery list command
authorfuzzyray <fuzzyray@gentoo.org>
Fri, 14 Oct 2005 05:20:38 +0000 (05:20 -0000)
committerfuzzyray <fuzzyray@gentoo.org>
Fri, 14 Oct 2005 05:20:38 +0000 (05:20 -0000)
svn path=/; revision=246

trunk/src/equery/equery
trunk/src/equery/equery.1
trunk/src/gentoolkit/package.py

index 7e10225d2226c82d74fc598ec04abf7103176dd1..cde8cd04a259769531ece163003295f6e4ca7eee 100755 (executable)
@@ -1123,7 +1123,8 @@ class CmdListPackages(Command):
                        "includePortTree": 0,
                        "includeOverlayTree": 0,
                        "includeMasked": 1,
-                       "regex": 0
+                       "regex": 0,
+                       "duplicates": 0
                        }
 
        def parseArgs(self, args):
@@ -1155,9 +1156,17 @@ class CmdListPackages(Command):
                                opts["includeMasked"] = 0
                        elif x in ["-f", "--full-regex"]:
                                opts["regex"] = 1
+                       elif x in ["-d", "--duplicates"]:
+                               opts["duplicates"] = 1
                        else:
                                query = x
 
+               # Only search installed packages when listing duplicated packages
+               if opts["duplicates"]:
+                       opts["includeInstalled"] = 1
+                       opts["includePortTree"] = 0
+                       opts["includeOverlayTree"] = 0
+
                if need_help:
                        print_info(0, self.longHelp())
                        sys.exit(-1)
@@ -1215,6 +1224,23 @@ class CmdListPackages(Command):
                        filter_fn = lambda x: True
                        matches = package_finder(filter_fn)
 
+               # Find duplicate packages
+               if opts["duplicates"]:
+                       dups = {}
+                       newmatches = []
+                       for pkg in matches:
+                               pkgname = pkg.get_name()
+                               if dups.has_key(pkgname):
+                                       dups[pkgname].append(pkg)
+                               else:
+                                       dups[pkgname] = [pkg]
+
+                       for pkgname in dups.keys():
+                               if len(dups[pkgname]) > 1:
+                                       newmatches += dups[pkgname]
+
+                       matches = newmatches
+
                matches = gentoolkit.sort_package_list(matches)
 
                # If no version supplied, fix regular expression
@@ -1297,7 +1323,8 @@ class CmdListPackages(Command):
                           "  " + pp.localoption("-I, --exclude-installed") + " - do not search installed packages\n" + \
                           "  " + pp.localoption("-p, --portage-tree") + "      - also search in portage tree (" + gentoolkit.settings["PORTDIR"] + ")\n" + \
                           "  " + pp.localoption("-o, --overlay-tree") + "      - also search in overlay tree (" + gentoolkit.settings["PORTDIR_OVERLAY"] + ")\n" + \
-                          "  " + pp.localoption("-f, --full-regex") + "        - query is a regular expression\n"
+                          "  " + pp.localoption("-f, --full-regex") + "        - query is a regular expression\n" + \
+                          "  " + pp.localoption("-d, --duplicates") + "        - list only installed duplicate packages\n"
 
 class CmdFindUSEs(Command):
        """Find all packages with a particular USE flag."""
index 05cb0af30f40ac00da80666a9ec29fa26f2c9a2c..17565ff894feb4527171448281ff25f886f81e4e 100644 (file)
@@ -176,7 +176,7 @@ This command lists packages matching pkgspec in a user\-specified combination
 of installed packages, packages which are not installed, the portage tree, and
 the portage overlay tree.
 
-<local\-opts> must not include only \-I;
+<local\-opts> \-I cannot be used by itself;
 if \-I is used, \-p and/or \-o must be also be present.  By default, only installed
 packages are searched.  \-o searches only the overlay tree [and possibly
 installed packages],
@@ -197,6 +197,9 @@ also search in overlay tree (/usr/local/portage)
 .br 
 .B \-f, \-\-full\-regex
 query is a regular expression
+.br 
+.B \-d, \-\-duplicates
+only list installed duplicate packages
 .PP 
 .TP 
 .B size <local\-opts> pkgspec
index e1d0a0ddb8a6aaf0978af3256cb63aa1f06bf74a..2bf27fc2435e9e1572a29e261a5a67b798a004dc 100644 (file)
@@ -163,9 +163,15 @@ class Package:
                """Compares this package's version to another's CPV; returns -1, 0, 1"""
                v1 = self._scpv
                v2 = portage.catpkgsplit(other.get_cpv())
-               if v1[0] != v2[0] or v1[1] != v2[1]:
-                       return 0
-               return portage.pkgcmp(v1[1:],v2[1:])
+               # if category is different
+               if v1[0] != v2[0]:
+                       return cmp(v1[0],v2[0])
+               # if name is different
+               elif v1[1] != v2[1]:
+                       return cmp(v1[1],v2[1])
+               # Compaare versions
+               else:
+                       return portage.pkgcmp(v1[1:],v2[1:])
 
        def size(self):
                """Estimates the installed size of the contents of this package, if possible.