portageq: fix visiblity filter with no atoms
authorZac Medico <zmedico@gentoo.org>
Mon, 18 Mar 2013 12:01:24 +0000 (05:01 -0700)
committerZac Medico <zmedico@gentoo.org>
Mon, 18 Mar 2013 12:01:24 +0000 (05:01 -0700)
bin/portageq

index a691a56c7fb4c48105a444434df5c998fb2fed8b..f76a96729838b0e69018bcb218a02425a973e4e7 100755 (executable)
@@ -903,6 +903,20 @@ def pquery(parser, pquery_option_groups, opts, args):
        root_config = RootConfig(portdb.settings,
                portage.db[portage.root], None)
 
+       def _pkg(cpv, repo_name):
+               try:
+                       metadata = dict(zip(
+                               Package.metadata_keys,
+                               portdb.aux_get(cpv,
+                               Package.metadata_keys,
+                               myrepo=repo_name)))
+               except KeyError:
+                       raise portage.exception.PackageNotFound(cpv)
+               return Package(built=False, cpv=cpv,
+                       installed=False, metadata=metadata,
+                       root_config=root_config,
+                       type_name="ebuild")
+
        need_metadata = False
        atoms = []
        for arg in args:
@@ -1020,17 +1034,9 @@ def pquery(parser, pquery_option_groups, opts, args):
                                                        if need_metadata:
                                                                if pkg is None:
                                                                        try:
-                                                                               metadata = dict(zip(
-                                                                                       Package.metadata_keys,
-                                                                                       portdb.aux_get(cpv,
-                                                                                       Package.metadata_keys,
-                                                                                       myrepo=repo.name)))
-                                                                       except KeyError:
+                                                                               pkg = _pkg(cpv, repo.name)
+                                                                       except portage.exception.PackageNotFound:
                                                                                continue
-                                                                       pkg = Package(built=False, cpv=cpv,
-                                                                               installed=False, metadata=metadata,
-                                                                               root_config=root_config,
-                                                                               type_name="ebuild")
 
                                                                if not (opts.no_filters or pkg.visible):
                                                                        continue
@@ -1038,8 +1044,17 @@ def pquery(parser, pquery_option_groups, opts, args):
                                                                        continue
                                                        matches.append(cpv)
                                                        break
-                               else:
+                               elif opts.no_filters:
                                        matches.extend(cpv_list)
+                               else:
+                                       for cpv in cpv_list:
+                                               try:
+                                                       pkg = _pkg(cpv, repo.name)
+                                               except portage.exception.PackageNotFound:
+                                                       continue
+                                               else:
+                                                       if pkg.visible:
+                                                               matches.append(cpv)
 
                        if not matches:
                                continue