diff options
author | Zac Medico <zmedico@gentoo.org> | 2007-10-17 02:59:48 +0000 |
---|---|---|
committer | Zac Medico <zmedico@gentoo.org> | 2007-10-17 02:59:48 +0000 |
commit | e3152c3c017a0ed2fe4288746c9f47dfde4aa255 (patch) | |
tree | 206e5162394f8520fb6db0de9b02400e31091691 /bin/portageq | |
parent | 25077a85b6b171fba9ddeadd3730f1e686718bbc (diff) | |
download | portage-e3152c3c017a0ed2fe4288746c9f47dfde4aa255.tar.gz portage-e3152c3c017a0ed2fe4288746c9f47dfde4aa255.tar.bz2 portage-e3152c3c017a0ed2fe4288746c9f47dfde4aa255.zip |
Bug #196043 - Implement a `portageq owners <root> [<filename>]+`
command that is suitable for identifying all packages that own
one or more files when a file collision has occurred. This uses
dblink.isowner() so that the query works properly even when
paths are ambiguous due to symlinked directories. (trunk r8154)
svn path=/main/branches/2.1.2/; revision=8159
Diffstat (limited to 'bin/portageq')
-rwxr-xr-x | bin/portageq | 67 |
1 files changed, 66 insertions, 1 deletions
diff --git a/bin/portageq b/bin/portageq index 4b9ad9473..536492fbc 100755 --- a/bin/portageq +++ b/bin/portageq @@ -124,6 +124,69 @@ def metadata(argv): metadata.uses_root = True +def owners(argv): + """<root> [<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 start with <root>. Returns 1 if no owners could be found, + and 0 otherwise. + """ + if len(argv) < 2: + sys.stderr.write("ERROR: insufficient parameters!\n") + sys.stderr.flush() + return 2 + + from portage import catsplit, dblink + settings = portage.settings + root = settings["ROOT"] + vardb = portage.db[root]["vartree"].dbapi + + cwd = None + try: + cwd = os.getcwd() + except OSError: + pass + + files = [] + for f in argv[1:]: + f = portage.normalize_path(f) + if not f.startswith(os.path.sep): + if cwd is None: + sys.stderr.write("ERROR: cwd does not exist!\n") + sys.stderr.flush() + return 2 + f = os.path.join(cwd, f) + f = portage.normalize_path(f) + if not f.startswith(root): + sys.stderr.write("ERROR: file paths must begin with <root>!\n") + sys.stderr.flush() + return 2 + files.append(f[len(root):]) + + found_owner = False + for cpv in vardb.cpv_all(): + cat, pkg = catsplit(cpv) + mylink = dblink(cat, pkg, root, settings, vartree=vardb.vartree) + myfiles = [] + for f in files: + if mylink.isowner(f, root): + myfiles.append(f) + if myfiles: + found_owner = True + sys.stdout.write("%s\n" % cpv) + for f in myfiles: + sys.stdout.write("\t%s\n" % \ + os.path.join(root, f.lstrip(os.path.sep))) + sys.stdout.flush() + if not found_owner: + sys.stderr.write("None of the installed packages claim the file(s).\n") + sys.stderr.flush() + return 1 + return 0 + +owners.uses_root = True + def best_visible(argv): """<root> [<category/package>]+ Returns category/package-version (without .ebuild). @@ -334,7 +397,9 @@ def main(): import portage if uses_root: sys.argv[2] = portage.root - function(sys.argv[2:]) + retval = function(sys.argv[2:]) + if retval: + sys.exit(retval) except KeyError: usage(sys.argv) sys.exit(os.EX_USAGE) |