summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2008-08-23 09:18:22 +0000
committerZac Medico <zmedico@gentoo.org>2008-08-23 09:18:22 +0000
commit8855bd5b21fffd8b39607b1bea4b2ef2aa18fdcd (patch)
tree49541a65bef66a3d7a61c12da84a7f653b2165e1 /bin
parent8dbe5a1b6505a89ebad4cf85ca7068a59811d21b (diff)
downloadportage-8855bd5b21fffd8b39607b1bea4b2ef2aa18fdcd.tar.gz
portage-8855bd5b21fffd8b39607b1bea4b2ef2aa18fdcd.tar.bz2
portage-8855bd5b21fffd8b39607b1bea4b2ef2aa18fdcd.zip
Add a new filter_protected command which is similar to is_protected but
works by reading filenames from stdin and writing to stdout only the filenames that are protected. This allows an unlimited number of files to be checked via a single portageq call. svn path=/main/trunk/; revision=11456
Diffstat (limited to 'bin')
-rwxr-xr-xbin/portageq57
1 files changed, 57 insertions, 0 deletions
diff --git a/bin/portageq b/bin/portageq
index ef898154f..7f804c960 100755
--- a/bin/portageq
+++ b/bin/portageq
@@ -261,6 +261,63 @@ def is_protected(argv):
is_protected.uses_root = True
+def filter_protected(argv):
+ """<root>
+ Read filenames from stdin and write them to stdout if they are protected.
+ All filenames are delimited by \\n and must begin with <root>.
+ """
+ if len(argv) != 1:
+ sys.stderr.write("ERROR: expeced 1 parameters, got %d!\n" % len(argv))
+ sys.stderr.flush()
+ return 2
+
+ root, = argv
+ out = sys.stdout
+ err = sys.stderr
+ cwd = None
+ try:
+ cwd = os.getcwd()
+ except OSError:
+ pass
+
+ import shlex
+ from portage.util import ConfigProtect
+
+ settings = portage.settings
+ protect = shlex.split(settings.get("CONFIG_PROTECT", ""))
+ protect_mask = shlex.split(settings.get("CONFIG_PROTECT_MASK", ""))
+ protect_obj = ConfigProtect(root, protect, protect_mask)
+
+ protected = 0
+ errors = 0
+
+ for line in sys.stdin:
+ filename = line.rstrip("\n")
+ f = portage.normalize_path(filename)
+ if not f.startswith(os.path.sep):
+ if cwd is None:
+ err.write("ERROR: cwd does not exist!\n")
+ err.flush()
+ errors += 1
+ f = os.path.join(cwd, f)
+ f = portage.normalize_path(f)
+
+ if not f.startswith(root):
+ err.write("ERROR: file paths must begin with <root>!\n")
+ err.flush()
+ errors += 1
+
+ if protect_obj.isprotected(f):
+ protected += 1
+ out.write("%s\n" % filename)
+
+ if errors:
+ return 2
+
+ return 0
+
+filter_protected.uses_root = True
+
def best_visible(argv):
"""<root> [<category/package>]+
Returns category/package-version (without .ebuild).