From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pigeon.gentoo.org ([208.92.234.80] helo=lists.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.60) (envelope-from ) id 1Qp5RA-0004ZV-07 for garchives@archives.gentoo.org; Thu, 04 Aug 2011 21:26:47 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id A87C821C058; Thu, 4 Aug 2011 21:26:31 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id 74B5021C058 for ; Thu, 4 Aug 2011 21:26:31 +0000 (UTC) Received: from pelican.gentoo.org (unknown [66.219.59.40]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id EAEC82AC018 for ; Thu, 4 Aug 2011 21:26:30 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by pelican.gentoo.org (Postfix) with ESMTP id 4B60980040 for ; Thu, 4 Aug 2011 21:26:30 +0000 (UTC) From: "Zac Medico" To: gentoo-commits@lists.gentoo.org Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Zac Medico" Message-ID: <03066476a2b3693467cd3ea00bf321c878a6c00f.zmedico@gentoo> Subject: [gentoo-commits] proj/portage:master commit in: bin/ X-VCS-Repository: proj/portage X-VCS-Files: bin/portageq X-VCS-Directories: bin/ X-VCS-Committer: zmedico X-VCS-Committer-Name: Zac Medico X-VCS-Revision: 03066476a2b3693467cd3ea00bf321c878a6c00f Date: Thu, 4 Aug 2011 21:26:30 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: quoted-printable X-Archives-Salt: X-Archives-Hash: 82e5f77c431666906104d505bbd6990d commit: 03066476a2b3693467cd3ea00bf321c878a6c00f Author: Zac Medico gentoo org> AuthorDate: Thu Aug 4 21:26:12 2011 +0000 Commit: Zac Medico gentoo org> CommitDate: Thu Aug 4 21:26:12 2011 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/portage.git;a= =3Dcommit;h=3D03066476 portageq best_visible: support optional pkgtype --- bin/portageq | 60 +++++++++++++++++++++++++++++++++++++++++++++++-----= ----- 1 files changed, 49 insertions(+), 11 deletions(-) diff --git a/bin/portageq b/bin/portageq index f614517..fa3a0d0 100755 --- a/bin/portageq +++ b/bin/portageq @@ -45,6 +45,8 @@ from portage import os from portage.util import writemsg, writemsg_stdout portage.proxy.lazyimport.lazyimport(globals(), 'subprocess', + '_emerge.Package:Package', + '_emerge.RootConfig:RootConfig', 'portage.dbapi._expand_new_virt:expand_new_virt', ) =20 @@ -422,22 +424,58 @@ def filter_protected(argv): filter_protected.uses_root =3D True =20 def best_visible(argv): - """ []+ + """ [pkgtype] Returns category/package-version (without .ebuild). + The pkgtype argument defaults to "ebuild" if unspecified, + otherwise it must be one of ebuild, binary, or installed. """ if (len(argv) < 2): - print("ERROR: insufficient parameters!") - sys.exit(2) + writemsg("ERROR: insufficient parameters!\n", noiselevel=3D-1) + return 2 + + pkgtype =3D "ebuild" + if len(argv) > 2: + pkgtype =3D argv[1] + atom =3D argv[2] + else: + atom =3D argv[1] + + type_map =3D { + "ebuild":"porttree", + "binary":"bintree", + "installed":"vartree"} + + if pkgtype not in type_map: + writemsg("Unrecognized package type: '%s'\n" % pkgtype, + noiselevel=3D-1) + return 2 + + db =3D portage.db[portage.settings["ROOT"]][type_map[pkgtype]].dbapi + try: - mylist=3Dportage.db[argv[0]]["porttree"].dbapi.match(argv[1]) - visible=3Dportage.best(mylist) - if visible: - print(visible) - sys.exit(0) - else: - sys.exit(1) + atom =3D portage.dep_expand(atom, mydb=3Ddb, settings=3Dportage.settin= gs) + except portage.exception.InvalidAtom: + writemsg("ERROR: Invalid atom: '%s'\n" % atom, + noiselevel=3D-1) + return 2 + + root_config =3D RootConfig(portage.settings, + portage.db[portage.settings["ROOT"]], None) + + try: + # reversed, for descending order + for cpv in reversed(db.match(atom)): + metadata =3D dict(zip(Package.metadata_keys, + db.aux_get(cpv, Package.metadata_keys, myrepo=3Datom.repo))) + pkg =3D Package(built=3D(pkgtype !=3D "ebuild"), cpv=3Dcpv, + installed=3D(pkgtype=3D=3D"installed"), metadata=3Dmetadata, + root_config=3Droot_config, type_name=3Dpkgtype) + if pkg.visible: + writemsg_stdout("%s\n" % (pkg.cpv,), noiselevel=3D-1) + return os.EX_OK except KeyError: - sys.exit(1) + pass + return 1 best_visible.uses_root =3D True =20 =20