Gentoo Archives: gentoo-commits

From: "Fabian Groffen (grobian)" <grobian@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] portage r11463 - main/branches/prefix/bin
Date: Sun, 24 Aug 2008 13:26:48
Message-Id: E1KXFcD-0006CD-LM@stork.gentoo.org
1 Author: grobian
2 Date: 2008-08-24 13:26:44 +0000 (Sun, 24 Aug 2008)
3 New Revision: 11463
4
5 Modified:
6 main/branches/prefix/bin/portageq
7 Log:
8 Merged from trunk -r11455:11460
9
10 | 11456 | Add a new filter_protected command which is similar to |
11 | zmedico | is_protected but works by reading filenames from stdin and |
12 | | writing to stdout only the filenames that are protected. |
13 | | This allows an unlimited number of files to be checked via a |
14 | | single portageq call. |
15
16 | 11457 | Flush stdout after the loop inside filter_protected() |
17 | zmedico | completes. |
18
19 | 11458 | Fix the loop in filter_protected() to continue when |
20 | zmedico | necessary due to an error. |
21
22 | 11459 | Fix spelling typos in error messages. |
23 | zmedico | |
24
25 | 11460 | Fix grammar. Thanks to ABCD. |
26 | zmedico | |
27
28
29 Modified: main/branches/prefix/bin/portageq
30 ===================================================================
31 --- main/branches/prefix/bin/portageq 2008-08-24 13:21:34 UTC (rev 11462)
32 +++ main/branches/prefix/bin/portageq 2008-08-24 13:26:44 UTC (rev 11463)
33 @@ -220,7 +220,7 @@
34 The filename must begin with <root>.
35 """
36 if len(argv) != 2:
37 - sys.stderr.write("ERROR: expeced 2 parameters, got %d!\n" % len(argv))
38 + sys.stderr.write("ERROR: expected 2 parameters, got %d!\n" % len(argv))
39 sys.stderr.flush()
40 return 2
41
42 @@ -261,6 +261,66 @@
43
44 is_protected.uses_root = True
45
46 +def filter_protected(argv):
47 + """<root>
48 + Read filenames from stdin and write them to stdout if they are protected.
49 + All filenames are delimited by \\n and must begin with <root>.
50 + """
51 + if len(argv) != 1:
52 + sys.stderr.write("ERROR: expected 1 parameter, got %d!\n" % len(argv))
53 + sys.stderr.flush()
54 + return 2
55 +
56 + root, = argv
57 + out = sys.stdout
58 + err = sys.stderr
59 + cwd = None
60 + try:
61 + cwd = os.getcwd()
62 + except OSError:
63 + pass
64 +
65 + import shlex
66 + from portage.util import ConfigProtect
67 +
68 + settings = portage.settings
69 + protect = shlex.split(settings.get("CONFIG_PROTECT", ""))
70 + protect_mask = shlex.split(settings.get("CONFIG_PROTECT_MASK", ""))
71 + protect_obj = ConfigProtect(root, protect, protect_mask)
72 +
73 + protected = 0
74 + errors = 0
75 +
76 + for line in sys.stdin:
77 + filename = line.rstrip("\n")
78 + f = portage.normalize_path(filename)
79 + if not f.startswith(os.path.sep):
80 + if cwd is None:
81 + err.write("ERROR: cwd does not exist!\n")
82 + err.flush()
83 + errors += 1
84 + continue
85 + f = os.path.join(cwd, f)
86 + f = portage.normalize_path(f)
87 +
88 + if not f.startswith(root):
89 + err.write("ERROR: file paths must begin with <root>!\n")
90 + err.flush()
91 + errors += 1
92 + continue
93 +
94 + if protect_obj.isprotected(f):
95 + protected += 1
96 + out.write("%s\n" % filename)
97 + out.flush()
98 +
99 + if errors:
100 + return 2
101 +
102 + return 0
103 +
104 +filter_protected.uses_root = True
105 +
106 def best_visible(argv):
107 """<root> [<category/package>]+
108 Returns category/package-version (without .ebuild).