diff options
Diffstat (limited to 'portage_with_autodep/bin/portageq')
-rwxr-xr-x | portage_with_autodep/bin/portageq | 257 |
1 files changed, 172 insertions, 85 deletions
diff --git a/portage_with_autodep/bin/portageq b/portage_with_autodep/bin/portageq index 57a7c39..280fe94 100755 --- a/portage_with_autodep/bin/portageq +++ b/portage_with_autodep/bin/portageq @@ -1,5 +1,5 @@ #!/usr/bin/python -O -# Copyright 1999-2011 Gentoo Foundation +# Copyright 1999-2012 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 from __future__ import print_function @@ -42,12 +42,15 @@ except ImportError: del pym_path from portage import os +from portage.eapi import eapi_has_repo_deps from portage.util import writemsg, writemsg_stdout +from portage.output import colormap portage.proxy.lazyimport.lazyimport(globals(), 'subprocess', '_emerge.Package:Package', '_emerge.RootConfig:RootConfig', 'portage.dbapi._expand_new_virt:expand_new_virt', + 'portage._sets.base:InternalPackageSet', ) def eval_atom_use(atom): @@ -78,17 +81,18 @@ def eval_atom_use(atom): # def has_version(argv): - """<root> <category/package> + """<eroot> <category/package> Return code 0 if it's available, 1 otherwise. """ if (len(argv) < 2): print("ERROR: insufficient parameters!") - sys.exit(2) + return 2 warnings = [] + allow_repo = atom_validate_strict is False or eapi_has_repo_deps(eapi) try: - atom = portage.dep.Atom(argv[1]) + atom = portage.dep.Atom(argv[1], allow_repo=allow_repo) except portage.exception.InvalidAtom: if atom_validate_strict: portage.writemsg("ERROR: Invalid atom: '%s'\n" % argv[1], @@ -99,7 +103,7 @@ def has_version(argv): else: if atom_validate_strict: try: - atom = portage.dep.Atom(argv[1], eapi=eapi) + atom = portage.dep.Atom(argv[1], allow_repo=allow_repo, eapi=eapi) except portage.exception.InvalidAtom as e: warnings.append( portage._unicode_decode("QA Notice: %s: %s") % \ @@ -112,11 +116,11 @@ def has_version(argv): try: mylist = portage.db[argv[0]]["vartree"].dbapi.match(atom) if mylist: - sys.exit(0) + return 0 else: - sys.exit(1) + return 1 except KeyError: - sys.exit(1) + return 1 except portage.exception.InvalidAtom: portage.writemsg("ERROR: Invalid atom: '%s'\n" % argv[1], noiselevel=-1) @@ -125,17 +129,18 @@ has_version.uses_root = True def best_version(argv): - """<root> <category/package> + """<eroot> <category/package> Returns category/package-version (without .ebuild). """ if (len(argv) < 2): print("ERROR: insufficient parameters!") - sys.exit(2) + return 2 warnings = [] + allow_repo = atom_validate_strict is False or eapi_has_repo_deps(eapi) try: - atom = portage.dep.Atom(argv[1]) + atom = portage.dep.Atom(argv[1], allow_repo=allow_repo) except portage.exception.InvalidAtom: if atom_validate_strict: portage.writemsg("ERROR: Invalid atom: '%s'\n" % argv[1], @@ -146,7 +151,7 @@ def best_version(argv): else: if atom_validate_strict: try: - atom = portage.dep.Atom(argv[1], eapi=eapi) + atom = portage.dep.Atom(argv[1], allow_repo=allow_repo, eapi=eapi) except portage.exception.InvalidAtom as e: warnings.append( portage._unicode_decode("QA Notice: %s: %s") % \ @@ -160,31 +165,31 @@ def best_version(argv): mylist = portage.db[argv[0]]["vartree"].dbapi.match(atom) print(portage.best(mylist)) except KeyError: - sys.exit(1) + return 1 best_version.uses_root = True def mass_best_version(argv): - """<root> [<category/package>]+ + """<eroot> [<category/package>]+ Returns category/package-version (without .ebuild). """ if (len(argv) < 2): print("ERROR: insufficient parameters!") - sys.exit(2) + return 2 try: for pack in argv[1:]: mylist=portage.db[argv[0]]["vartree"].dbapi.match(pack) print(pack+":"+portage.best(mylist)) except KeyError: - sys.exit(1) + return 1 mass_best_version.uses_root = True def metadata(argv): if (len(argv) < 4): print("ERROR: insufficient parameters!", file=sys.stderr) - sys.exit(2) + return 2 - root, pkgtype, pkgspec = argv[0:3] + eroot, pkgtype, pkgspec = argv[0:3] metakeys = argv[3:] type_map = { "ebuild":"porttree", @@ -192,20 +197,20 @@ def metadata(argv): "installed":"vartree"} if pkgtype not in type_map: print("Unrecognized package type: '%s'" % pkgtype, file=sys.stderr) - sys.exit(1) + return 1 trees = portage.db - if os.path.realpath(root) == os.path.realpath(portage.settings["ROOT"]): - root = portage.settings["ROOT"] # contains the normalized $ROOT + repo = portage.dep.dep_getrepo(pkgspec) + pkgspec = portage.dep.remove_slot(pkgspec) try: - values = trees[root][type_map[pkgtype]].dbapi.aux_get( - pkgspec, metakeys) + values = trees[eroot][type_map[pkgtype]].dbapi.aux_get( + pkgspec, metakeys, myrepo=repo) writemsg_stdout(''.join('%s\n' % x for x in values), noiselevel=-1) except KeyError: print("Package not found: '%s'" % pkgspec, file=sys.stderr) - sys.exit(1) + return 1 metadata.__doc__ = """ -<root> <pkgtype> <category/package> [<key>]+ +<eroot> <pkgtype> <category/package> [<key>]+ Returns metadata values for the specified package. Available keys: %s """ % ','.join(sorted(x for x in portage.auxdbkeys \ @@ -214,10 +219,10 @@ if not x.startswith('UNUSED_'))) metadata.uses_root = True def contents(argv): - """<root> <category/package> + """<eroot> <category/package> List the files that are installed for a given package, with one file listed on each line. All file names will begin with - <root>. + <eroot>. """ if len(argv) != 2: print("ERROR: expected 2 parameters, got %d!" % len(argv)) @@ -236,11 +241,11 @@ def contents(argv): contents.uses_root = True def owners(argv): - """<root> [<filename>]+ + """<eroot> [<filename>]+ Given a list of files, print the packages that own the files and which files belong to each package. Files owned by a package are listed on the lines below it, indented by a single tab character (\\t). All file - paths must either start with <root> or be a basename alone. + paths must either start with <eroot> or be a basename alone. Returns 1 if no owners could be found, and 0 otherwise. """ if len(argv) < 2: @@ -249,9 +254,9 @@ def owners(argv): return 2 from portage import catsplit, dblink - settings = portage.settings - root = settings["ROOT"] - vardb = portage.db[root]["vartree"].dbapi + eroot = argv[0] + vardb = portage.db[eroot]["vartree"].dbapi + root = portage.settings['ROOT'] cwd = None try: @@ -272,8 +277,8 @@ def owners(argv): return 2 f = os.path.join(cwd, f) f = portage.normalize_path(f) - if not is_basename and not f.startswith(root): - sys.stderr.write("ERROR: file paths must begin with <root>!\n") + if not is_basename and not f.startswith(eroot): + sys.stderr.write("ERROR: file paths must begin with <eroot>!\n") sys.stderr.flush() return 2 if is_basename: @@ -317,9 +322,9 @@ def owners(argv): owners.uses_root = True def is_protected(argv): - """<root> <filename> + """<eroot> <filename> Given a single filename, return code 0 if it's protected, 1 otherwise. - The filename must begin with <root>. + The filename must begin with <eroot>. """ if len(argv) != 2: sys.stderr.write("ERROR: expected 2 parameters, got %d!\n" % len(argv)) @@ -345,7 +350,7 @@ def is_protected(argv): f = portage.normalize_path(f) if not f.startswith(root): - err.write("ERROR: file paths must begin with <root>!\n") + err.write("ERROR: file paths must begin with <eroot>!\n") err.flush() return 2 @@ -364,9 +369,9 @@ def is_protected(argv): is_protected.uses_root = True def filter_protected(argv): - """<root> + """<eroot> Read filenames from stdin and write them to stdout if they are protected. - All filenames are delimited by \\n and must begin with <root>. + All filenames are delimited by \\n and must begin with <eroot>. """ if len(argv) != 1: sys.stderr.write("ERROR: expected 1 parameter, got %d!\n" % len(argv)) @@ -406,7 +411,7 @@ def filter_protected(argv): f = portage.normalize_path(f) if not f.startswith(root): - err.write("ERROR: file paths must begin with <root>!\n") + err.write("ERROR: file paths must begin with <eroot>!\n") err.flush() errors += 1 continue @@ -424,7 +429,7 @@ def filter_protected(argv): filter_protected.uses_root = True def best_visible(argv): - """<root> [pkgtype] <atom> + """<eroot> [pkgtype] <atom> Returns category/package-version (without .ebuild). The pkgtype argument defaults to "ebuild" if unspecified, otherwise it must be one of ebuild, binary, or installed. @@ -450,7 +455,8 @@ def best_visible(argv): noiselevel=-1) return 2 - db = portage.db[portage.settings["ROOT"]][type_map[pkgtype]].dbapi + eroot = argv[0] + db = portage.db[eroot][type_map[pkgtype]].dbapi try: atom = portage.dep_expand(atom, mydb=db, settings=portage.settings) @@ -460,43 +466,80 @@ def best_visible(argv): return 2 root_config = RootConfig(portage.settings, - portage.db[portage.settings["ROOT"]], None) + portage.db[eroot], None) - try: + if hasattr(db, "xmatch"): + cpv_list = db.xmatch("match-all-cpv-only", atom) + else: + cpv_list = db.match(atom) + + if cpv_list: # reversed, for descending order - for cpv in reversed(db.match(atom)): - metadata = dict(zip(Package.metadata_keys, - db.aux_get(cpv, Package.metadata_keys, myrepo=atom.repo))) - pkg = Package(built=(pkgtype != "ebuild"), cpv=cpv, - installed=(pkgtype=="installed"), metadata=metadata, - root_config=root_config, type_name=pkgtype) - if pkg.visible: - writemsg_stdout("%s\n" % (pkg.cpv,), noiselevel=-1) - return os.EX_OK - except KeyError: - pass + cpv_list.reverse() + # verify match, since the atom may match the package + # for a given cpv from one repo but not another, and + # we can use match-all-cpv-only to avoid redundant + # metadata access. + atom_set = InternalPackageSet(initial_atoms=(atom,)) + + if atom.repo is None and hasattr(db, "getRepositories"): + repo_list = db.getRepositories() + else: + repo_list = [atom.repo] + + for cpv in cpv_list: + for repo in repo_list: + try: + metadata = dict(zip(Package.metadata_keys, + db.aux_get(cpv, Package.metadata_keys, myrepo=repo))) + except KeyError: + continue + pkg = Package(built=(pkgtype != "ebuild"), cpv=cpv, + installed=(pkgtype=="installed"), metadata=metadata, + root_config=root_config, type_name=pkgtype) + if not atom_set.findAtomForPackage(pkg): + continue + + if pkg.visible: + writemsg_stdout("%s\n" % (pkg.cpv,), noiselevel=-1) + return os.EX_OK + + # No package found, write out an empty line. + writemsg_stdout("\n", noiselevel=-1) + return 1 best_visible.uses_root = True def mass_best_visible(argv): - """<root> [<category/package>]+ + """<root> [<type>] [<category/package>]+ Returns category/package-version (without .ebuild). + The pkgtype argument defaults to "ebuild" if unspecified, + otherwise it must be one of ebuild, binary, or installed. """ + type_map = { + "ebuild":"porttree", + "binary":"bintree", + "installed":"vartree"} + if (len(argv) < 2): print("ERROR: insufficient parameters!") - sys.exit(2) + return 2 try: - for pack in argv[1:]: - mylist=portage.db[argv[0]]["porttree"].dbapi.match(pack) - print(pack+":"+portage.best(mylist)) + root = argv.pop(0) + pkgtype = "ebuild" + if argv[0] in type_map: + pkgtype = argv.pop(0) + for pack in argv: + writemsg_stdout("%s:" % pack, noiselevel=-1) + best_visible([root, pkgtype, pack]) except KeyError: - sys.exit(1) + return 1 mass_best_visible.uses_root = True def all_best_visible(argv): - """<root> + """<eroot> Returns all best_visible packages (without .ebuild). """ if len(argv) < 1: @@ -513,30 +556,57 @@ all_best_visible.uses_root = True def match(argv): - """<root> <atom> + """<eroot> <atom> Returns a \\n separated list of category/package-version. When given an empty string, all installed packages will be listed. """ if len(argv) != 2: print("ERROR: expected 2 parameters, got %d!" % len(argv)) - sys.exit(2) + return 2 root, atom = argv - if atom: - if atom_validate_strict and not portage.isvalidatom(atom): - portage.writemsg("ERROR: Invalid atom: '%s'\n" % atom, - noiselevel=-1) - return 2 - results = portage.db[root]["vartree"].dbapi.match(atom) - else: - results = portage.db[root]["vartree"].dbapi.cpv_all() + if not atom: + atom = "*/*" + + vardb = portage.db[root]["vartree"].dbapi + try: + atom = portage.dep.Atom(atom, allow_wildcard=True, allow_repo=True) + except portage.exception.InvalidAtom: + # maybe it's valid but missing category + atom = portage.dep_expand(atom, mydb=vardb, settings=vardb.settings) + + if atom.extended_syntax: + if atom == "*/*": + results = vardb.cpv_all() + else: + results = [] + require_metadata = atom.slot or atom.repo + for cpv in vardb.cpv_all(): + + if not portage.dep.extended_cp_match( + atom.cp, portage.cpv_getkey(cpv)): + continue + + if require_metadata: + slot, repo = vardb.aux_get(cpv, ["SLOT", "repository"]) + + if atom.slot is not None and atom.slot != slot: + continue + + if atom.repo is not None and atom.repo != repo: + continue + + results.append(cpv) + results.sort() + else: + results = vardb.match(atom) for cpv in results: print(cpv) match.uses_root = True def expand_virtual(argv): - """<root> <atom> + """<eroot> <atom> Returns a \\n separated list of atoms expanded from a given virtual atom (GLEP 37 virtuals only), excluding blocker atoms. Satisfied @@ -630,6 +700,13 @@ def distdir(argv): print(portage.settings["DISTDIR"]) +def colormap(argv): + """ + Display the color.map as environment variables. + """ + print(portage.output.colormap()) + + def envvar(argv): """<variable>+ Returns a specific environment variable as exists prior to ebuild.sh. @@ -641,7 +718,7 @@ def envvar(argv): if len(argv) == 0: print("ERROR: insufficient parameters!") - sys.exit(2) + return 2 for arg in argv: if verbose: @@ -650,29 +727,33 @@ def envvar(argv): print(portage.settings[arg]) def get_repos(argv): - """<root> - Returns all repos with names (repo_name file) argv[0] = $ROOT + """<eroot> + Returns all repos with names (repo_name file) argv[0] = $EROOT """ if len(argv) < 1: print("ERROR: insufficient parameters!") - sys.exit(2) + return 2 print(" ".join(portage.db[argv[0]]["porttree"].dbapi.getRepositories())) +get_repos.uses_root = True + def get_repo_path(argv): - """<root> <repo_id>+ - Returns the path to the repo named argv[1], argv[0] = $ROOT + """<eroot> <repo_id>+ + Returns the path to the repo named argv[1], argv[0] = $EROOT """ if len(argv) < 2: print("ERROR: insufficient parameters!") - sys.exit(2) + return 2 for arg in argv[1:]: path = portage.db[argv[0]]["porttree"].dbapi.getRepositoryPath(arg) if path is None: path = "" print(path) +get_repo_path.uses_root = True + def list_preserved_libs(argv): - """<root> + """<eroot> Print a list of libraries preserved during a package update in the form package: path. Returns 1 if no preserved libraries could be found, 0 otherwise. @@ -680,7 +761,7 @@ def list_preserved_libs(argv): if len(argv) != 1: print("ERROR: wrong number of arguments") - sys.exit(2) + return 2 mylibs = portage.db[argv[0]]["vartree"].dbapi._plib_registry.getPreservedLibs() rValue = 1 msg = [] @@ -788,16 +869,22 @@ def main(): sys.stderr.write("Run portageq with --help for info\n") sys.stderr.flush() sys.exit(os.EX_USAGE) - os.environ["ROOT"] = sys.argv[2] + eprefix = portage.const.EPREFIX + eroot = portage.util.normalize_path(sys.argv[2]) + if eprefix: + root = eroot[:1-len(eprefix)] + else: + root = eroot + os.environ["ROOT"] = root args = sys.argv[2:] - if args and sys.hexversion < 0x3000000 and not isinstance(args[0], unicode): + if args and isinstance(args[0], bytes): for i in range(len(args)): args[i] = portage._unicode_decode(args[i]) try: if uses_root: - args[0] = portage.settings["ROOT"] + args[0] = portage.settings['EROOT'] retval = function(args) if retval: sys.exit(retval) |