Add support to `portageq owners` for querying paths matching a given basename.
authorZac Medico <zmedico@gentoo.org>
Wed, 24 Jun 2009 07:12:40 +0000 (07:12 -0000)
committerZac Medico <zmedico@gentoo.org>
Wed, 24 Jun 2009 07:12:40 +0000 (07:12 -0000)
It is natural to support this since the vartree already maintains a basename
-> owner index anyway. There are plans for the packagekit backend is to
support this type of search.

svn path=/main/trunk/; revision=13681

bin/portageq
pym/portage/dbapi/vartree.py

index 89d5b64442fbd8f7827c80d063f99bb088009d31..c21c783c174f2638eb911436f4c8c999d75aa26c 100755 (executable)
@@ -161,8 +161,8 @@ def owners(argv):
        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.
+       paths must either start with <root> or be a basename alone.
+       Returns 1 if no owners could be found, and 0 otherwise.
        """
        if len(argv) < 2:
                sys.stderr.write("ERROR: insufficient parameters!\n")
@@ -183,18 +183,22 @@ def owners(argv):
        files = []
        for f in argv[1:]:
                f = portage.normalize_path(f)
-               if not f.startswith(os.path.sep):
+               is_basename = os.sep not in f
+               if not is_basename and f[:1] != os.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):
+               if not is_basename and 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):])
+               if is_basename:
+                       files.append(f)
+               else:
+                       files.append(f[len(root):])
 
        owners = vardb._owners.get_owners(files)
 
index 139259177525aaff43e3f5bae635954d28436d42..5b6f54a6a09f3f0df8d01e391894f64502251b52 100644 (file)
@@ -1527,7 +1527,12 @@ class vardbapi(dbapi):
                                return x
 
                        for path in path_iter:
-                               name = os.path.basename(path.rstrip(os.path.sep))
+                               is_basename = os.sep != path[:1]
+                               if is_basename:
+                                       name = path
+                               else:
+                                       name = os.path.basename(path.rstrip(os.path.sep))
+
                                if not name:
                                        continue
 
@@ -1548,8 +1553,14 @@ class vardbapi(dbapi):
 
                                                if current_hash != hash_value:
                                                        continue
-                                               if dblink(cpv).isowner(path, root):
-                                                       yield dblink(cpv), path
+
+                                               if is_basename:
+                                                       for p in dblink(cpv).getcontents():
+                                                               if os.path.basename(p) == name:
+                                                                       yield dblink(cpv), p[len(root):]
+                                               else:
+                                                       if dblink(cpv).isowner(path, root):
+                                                               yield dblink(cpv), path
 
 class vartree(object):
        "this tree will scan a var/db/pkg database located at root (passed to init)"