summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2008-08-22 23:53:22 +0000
committerZac Medico <zmedico@gentoo.org>2008-08-22 23:53:22 +0000
commitc47730c0f2b6c9270382357d20f4a47322ad5da5 (patch)
tree2268e33383254c72033b4507539fe344e216c280 /bin/portageq
parentFix isprotected() call in dblink._collision_protect() to properly account (diff)
downloadportage-multirepo-c47730c0f2b6c9270382357d20f4a47322ad5da5.tar.gz
portage-multirepo-c47730c0f2b6c9270382357d20f4a47322ad5da5.tar.bz2
portage-multirepo-c47730c0f2b6c9270382357d20f4a47322ad5da5.zip
Add a new is_protected command which queries whether or not CONFIG_PROTECT
applies to a given file, using logic identical to the merge code. svn path=/main/trunk/; revision=11453
Diffstat (limited to 'bin/portageq')
-rwxr-xr-xbin/portageq47
1 files changed, 47 insertions, 0 deletions
diff --git a/bin/portageq b/bin/portageq
index 61cba4ab..ef898154 100755
--- a/bin/portageq
+++ b/bin/portageq
@@ -214,6 +214,53 @@ def owners(argv):
owners.uses_root = True
+def is_protected(argv):
+ """<root> <filename>
+ Given a single filename, return code 0 if it's protected, 1 otherwise.
+ The filename must begin with <root>.
+ """
+ if len(argv) != 2:
+ sys.stderr.write("ERROR: expeced 2 parameters, got %d!\n" % len(argv))
+ sys.stderr.flush()
+ return 2
+
+ root, filename = argv
+
+ err = sys.stderr
+ cwd = None
+ try:
+ cwd = os.getcwd()
+ except OSError:
+ pass
+
+ 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()
+ return 2
+ 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()
+ return 2
+
+ 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)
+
+ if protect_obj.isprotected(f):
+ return 0
+ return 1
+
+is_protected.uses_root = True
+
def best_visible(argv):
"""<root> [<category/package>]+
Returns category/package-version (without .ebuild).