From: Zac Medico Date: Sat, 23 Aug 2008 09:18:22 +0000 (-0000) Subject: Add a new filter_protected command which is similar to is_protected but X-Git-Tag: v2.2_rc9~58 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=8855bd5b21fffd8b39607b1bea4b2ef2aa18fdcd;p=portage.git 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 --- 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): + """ + Read filenames from stdin and write them to stdout if they are protected. + All filenames are delimited by \\n and must begin with . + """ + 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 !\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): """ []+ Returns category/package-version (without .ebuild).