summaryrefslogtreecommitdiffstats
path: root/pym/portage_util.py
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2006-07-16 02:36:40 +0000
committerZac Medico <zmedico@gentoo.org>2006-07-16 02:36:40 +0000
commitd480d8123e91b7fe0580520cd6ea365fb9e7492f (patch)
tree5acb96143e753dada00d515aa0acdb3587d87c75 /pym/portage_util.py
parent18c988584852c55001c5ce07a3a32addbbdbb5c0 (diff)
downloadportage-d480d8123e91b7fe0580520cd6ea365fb9e7492f.tar.gz
portage-d480d8123e91b7fe0580520cd6ea365fb9e7492f.tar.bz2
portage-d480d8123e91b7fe0580520cd6ea365fb9e7492f.zip
Move the ConfigProtect class to the portage_util module.
svn path=/main/trunk/; revision=3895
Diffstat (limited to 'pym/portage_util.py')
-rw-r--r--pym/portage_util.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/pym/portage_util.py b/pym/portage_util.py
index 0449b614f..0002dc090 100644
--- a/pym/portage_util.py
+++ b/pym/portage_util.py
@@ -813,3 +813,42 @@ class LazyItemsDict(dict):
if item_key in self.lazy_items:
del self.lazy_items[item_key]
dict.__delitem__(self, item_key)
+
+class ConfigProtect(object):
+ def __init__(self, myroot, protect_list, mask_list):
+ self.myroot = myroot
+ self.protect_list = protect_list
+ self.mask_list = mask_list
+ self.updateprotect()
+
+ def updateprotect(self):
+ #do some config file management prep
+ self.protect = []
+ for x in self.protect_list:
+ ppath = normalize_path(
+ os.path.join(self.myroot, x.lstrip(os.path.sep))) + os.path.sep
+ if os.path.isdir(ppath):
+ self.protect.append(ppath)
+
+ self.protectmask = []
+ for x in self.mask_list:
+ ppath = normalize_path(
+ os.path.join(self.myroot, x.lstrip(os.path.sep))) + os.path.sep
+ if os.path.isdir(ppath):
+ self.protectmask.append(ppath)
+ #if it doesn't exist, silently skip it
+
+ def isprotected(self, obj):
+ """Checks if obj is in the current protect/mask directories. Returns
+ 0 on unprotected/masked, and 1 on protected."""
+ masked = 0
+ protected = 0
+ for ppath in self.protect:
+ if len(ppath) > masked and obj.startswith(ppath):
+ protected = len(ppath)
+ #config file management
+ for pmpath in self.protectmask:
+ if len(pmpath) >= protected and obj.startswith(pmpath):
+ #skip, it's in the mask
+ masked = len(pmpath)
+ return protected > masked