1 |
Author: zmedico |
2 |
Date: 2009-06-24 07:12:40 +0000 (Wed, 24 Jun 2009) |
3 |
New Revision: 13681 |
4 |
|
5 |
Modified: |
6 |
main/trunk/bin/portageq |
7 |
main/trunk/pym/portage/dbapi/vartree.py |
8 |
Log: |
9 |
Add support to `portageq owners` for querying paths matching a given basename. |
10 |
It is natural to support this since the vartree already maintains a basename |
11 |
-> owner index anyway. There are plans for the packagekit backend is to |
12 |
support this type of search. |
13 |
|
14 |
|
15 |
Modified: main/trunk/bin/portageq |
16 |
=================================================================== |
17 |
--- main/trunk/bin/portageq 2009-06-24 06:47:57 UTC (rev 13680) |
18 |
+++ main/trunk/bin/portageq 2009-06-24 07:12:40 UTC (rev 13681) |
19 |
@@ -161,8 +161,8 @@ |
20 |
Given a list of files, print the packages that own the files and which |
21 |
files belong to each package. Files owned by a package are listed on |
22 |
the lines below it, indented by a single tab character (\\t). All file |
23 |
- paths must start with <root>. Returns 1 if no owners could be found, |
24 |
- and 0 otherwise. |
25 |
+ paths must either start with <root> or be a basename alone. |
26 |
+ Returns 1 if no owners could be found, and 0 otherwise. |
27 |
""" |
28 |
if len(argv) < 2: |
29 |
sys.stderr.write("ERROR: insufficient parameters!\n") |
30 |
@@ -183,18 +183,22 @@ |
31 |
files = [] |
32 |
for f in argv[1:]: |
33 |
f = portage.normalize_path(f) |
34 |
- if not f.startswith(os.path.sep): |
35 |
+ is_basename = os.sep not in f |
36 |
+ if not is_basename and f[:1] != os.sep: |
37 |
if cwd is None: |
38 |
sys.stderr.write("ERROR: cwd does not exist!\n") |
39 |
sys.stderr.flush() |
40 |
return 2 |
41 |
f = os.path.join(cwd, f) |
42 |
f = portage.normalize_path(f) |
43 |
- if not f.startswith(root): |
44 |
+ if not is_basename and not f.startswith(root): |
45 |
sys.stderr.write("ERROR: file paths must begin with <root>!\n") |
46 |
sys.stderr.flush() |
47 |
return 2 |
48 |
- files.append(f[len(root):]) |
49 |
+ if is_basename: |
50 |
+ files.append(f) |
51 |
+ else: |
52 |
+ files.append(f[len(root):]) |
53 |
|
54 |
owners = vardb._owners.get_owners(files) |
55 |
|
56 |
|
57 |
Modified: main/trunk/pym/portage/dbapi/vartree.py |
58 |
=================================================================== |
59 |
--- main/trunk/pym/portage/dbapi/vartree.py 2009-06-24 06:47:57 UTC (rev 13680) |
60 |
+++ main/trunk/pym/portage/dbapi/vartree.py 2009-06-24 07:12:40 UTC (rev 13681) |
61 |
@@ -1527,7 +1527,12 @@ |
62 |
return x |
63 |
|
64 |
for path in path_iter: |
65 |
- name = os.path.basename(path.rstrip(os.path.sep)) |
66 |
+ is_basename = os.sep != path[:1] |
67 |
+ if is_basename: |
68 |
+ name = path |
69 |
+ else: |
70 |
+ name = os.path.basename(path.rstrip(os.path.sep)) |
71 |
+ |
72 |
if not name: |
73 |
continue |
74 |
|
75 |
@@ -1548,9 +1553,15 @@ |
76 |
|
77 |
if current_hash != hash_value: |
78 |
continue |
79 |
- if dblink(cpv).isowner(path, root): |
80 |
- yield dblink(cpv), path |
81 |
|
82 |
+ if is_basename: |
83 |
+ for p in dblink(cpv).getcontents(): |
84 |
+ if os.path.basename(p) == name: |
85 |
+ yield dblink(cpv), p[len(root):] |
86 |
+ else: |
87 |
+ if dblink(cpv).isowner(path, root): |
88 |
+ yield dblink(cpv), path |
89 |
+ |
90 |
class vartree(object): |
91 |
"this tree will scan a var/db/pkg database located at root (passed to init)" |
92 |
def __init__(self, root="/", virtual=None, clone=None, categories=None, |