1 |
Author: zmedico |
2 |
Date: 2008-08-23 09:18:22 +0000 (Sat, 23 Aug 2008) |
3 |
New Revision: 11456 |
4 |
|
5 |
Modified: |
6 |
main/trunk/bin/portageq |
7 |
Log: |
8 |
Add a new filter_protected command which is similar to is_protected but |
9 |
works by reading filenames from stdin and writing to stdout only the |
10 |
filenames that are protected. This allows an unlimited number of files |
11 |
to be checked via a single portageq call. |
12 |
|
13 |
|
14 |
Modified: main/trunk/bin/portageq |
15 |
=================================================================== |
16 |
--- main/trunk/bin/portageq 2008-08-23 05:43:12 UTC (rev 11455) |
17 |
+++ main/trunk/bin/portageq 2008-08-23 09:18:22 UTC (rev 11456) |
18 |
@@ -261,6 +261,63 @@ |
19 |
|
20 |
is_protected.uses_root = True |
21 |
|
22 |
+def filter_protected(argv): |
23 |
+ """<root> |
24 |
+ Read filenames from stdin and write them to stdout if they are protected. |
25 |
+ All filenames are delimited by \\n and must begin with <root>. |
26 |
+ """ |
27 |
+ if len(argv) != 1: |
28 |
+ sys.stderr.write("ERROR: expeced 1 parameters, got %d!\n" % len(argv)) |
29 |
+ sys.stderr.flush() |
30 |
+ return 2 |
31 |
+ |
32 |
+ root, = argv |
33 |
+ out = sys.stdout |
34 |
+ err = sys.stderr |
35 |
+ cwd = None |
36 |
+ try: |
37 |
+ cwd = os.getcwd() |
38 |
+ except OSError: |
39 |
+ pass |
40 |
+ |
41 |
+ import shlex |
42 |
+ from portage.util import ConfigProtect |
43 |
+ |
44 |
+ settings = portage.settings |
45 |
+ protect = shlex.split(settings.get("CONFIG_PROTECT", "")) |
46 |
+ protect_mask = shlex.split(settings.get("CONFIG_PROTECT_MASK", "")) |
47 |
+ protect_obj = ConfigProtect(root, protect, protect_mask) |
48 |
+ |
49 |
+ protected = 0 |
50 |
+ errors = 0 |
51 |
+ |
52 |
+ for line in sys.stdin: |
53 |
+ filename = line.rstrip("\n") |
54 |
+ f = portage.normalize_path(filename) |
55 |
+ if not f.startswith(os.path.sep): |
56 |
+ if cwd is None: |
57 |
+ err.write("ERROR: cwd does not exist!\n") |
58 |
+ err.flush() |
59 |
+ errors += 1 |
60 |
+ f = os.path.join(cwd, f) |
61 |
+ f = portage.normalize_path(f) |
62 |
+ |
63 |
+ if not f.startswith(root): |
64 |
+ err.write("ERROR: file paths must begin with <root>!\n") |
65 |
+ err.flush() |
66 |
+ errors += 1 |
67 |
+ |
68 |
+ if protect_obj.isprotected(f): |
69 |
+ protected += 1 |
70 |
+ out.write("%s\n" % filename) |
71 |
+ |
72 |
+ if errors: |
73 |
+ return 2 |
74 |
+ |
75 |
+ return 0 |
76 |
+ |
77 |
+filter_protected.uses_root = True |
78 |
+ |
79 |
def best_visible(argv): |
80 |
"""<root> [<category/package>]+ |
81 |
Returns category/package-version (without .ebuild). |