From: Fabian Groffen Date: Sun, 24 Aug 2008 13:26:44 +0000 (-0000) Subject: Merged from trunk -r11455:11460 X-Git-Url: http://git.tremily.us/gitweb.cgi?a=commitdiff_plain;h=bef2e1144311e31fd6ff8623b335b8ecf94cf46a;p=portage.git Merged from trunk -r11455:11460 | 11456 | Add a new filter_protected command which is similar to | | zmedico | 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. | | 11457 | Flush stdout after the loop inside filter_protected() | | zmedico | completes. | | 11458 | Fix the loop in filter_protected() to continue when | | zmedico | necessary due to an error. | | 11459 | Fix spelling typos in error messages. | | zmedico | | | 11460 | Fix grammar. Thanks to ABCD. | | zmedico | | svn path=/main/branches/prefix/; revision=11463 --- diff --git a/bin/portageq b/bin/portageq index 7fe52b3da..2c87ac704 100755 --- a/bin/portageq +++ b/bin/portageq @@ -220,7 +220,7 @@ def is_protected(argv): The filename must begin with . """ if len(argv) != 2: - sys.stderr.write("ERROR: expeced 2 parameters, got %d!\n" % len(argv)) + sys.stderr.write("ERROR: expected 2 parameters, got %d!\n" % len(argv)) sys.stderr.flush() return 2 @@ -261,6 +261,66 @@ 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: expected 1 parameter, 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 + continue + 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 + continue + + if protect_obj.isprotected(f): + protected += 1 + out.write("%s\n" % filename) + out.flush() + + if errors: + return 2 + + return 0 + +filter_protected.uses_root = True + def best_visible(argv): """ []+ Returns category/package-version (without .ebuild).