summaryrefslogtreecommitdiffstats
path: root/pym
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2006-06-25 08:30:28 +0000
committerZac Medico <zmedico@gentoo.org>2006-06-25 08:30:28 +0000
commitca03c699e0be55a72d40d01c364fb0b3577edb19 (patch)
tree4512b0e952f7c6d628d17cb1564e618edb6df136 /pym
parentd873e9542597a551cf15aaabba1fca4fcd1bb852 (diff)
downloadportage-ca03c699e0be55a72d40d01c364fb0b3577edb19.tar.gz
portage-ca03c699e0be55a72d40d01c364fb0b3577edb19.tar.bz2
portage-ca03c699e0be55a72d40d01c364fb0b3577edb19.zip
Split the config protect functionality from the dblink class to a new class and use it in portage.update_config_files() (dblink requires a vartree and that's not needed here).
svn path=/main/trunk/; revision=3652
Diffstat (limited to 'pym')
-rw-r--r--pym/portage.py81
1 files changed, 48 insertions, 33 deletions
diff --git a/pym/portage.py b/pym/portage.py
index 9804b574c..962ef7ba5 100644
--- a/pym/portage.py
+++ b/pym/portage.py
@@ -5700,6 +5700,45 @@ class binarytree(packagetree):
pass
return myslot
+class config_protect(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[0:len(ppath)]==ppath):
+ protected=len(ppath)
+ #config file management
+ for pmpath in self.protectmask:
+ if (len(pmpath) >= protected) and (obj[0:len(pmpath)]==pmpath):
+ #skip, it's in the mask
+ masked=len(pmpath)
+ return (protected > masked)
+
class dblink:
"this class provides an interface to the standard text package database"
def __init__(self, cat, pkg, myroot, mysettings, treetype=None,
@@ -5730,7 +5769,11 @@ class dblink:
raise ValueError
self.myroot=myroot
- self.updateprotect()
+ protect_obj = config_protect(myroot,
+ mysettings.get("CONFIG_PROTECT","").split(),
+ mysettings.get("CONFIG_PROTECT_MASK","").split())
+ self.updateprotect = protect_obj.updateprotect
+ self.isprotected = protect_obj.isprotected
self.contentscache=[]
def lockdb(self):
@@ -5834,36 +5877,6 @@ class dblink:
self.contentscache=pkgfiles
return pkgfiles
- def updateprotect(self):
- #do some config file management prep
- self.protect=[]
- for x in string.split(self.settings["CONFIG_PROTECT"]):
- ppath=normalize_path(self.myroot+x)+"/"
- if os.path.isdir(ppath):
- self.protect.append(ppath)
-
- self.protectmask=[]
- for x in string.split(self.settings["CONFIG_PROTECT_MASK"]):
- ppath=normalize_path(self.myroot+x)+"/"
- 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[0:len(ppath)]==ppath):
- protected=len(ppath)
- #config file management
- for pmpath in self.protectmask:
- if (len(pmpath) >= protected) and (obj[0:len(pmpath)]==pmpath):
- #skip, it's in the mask
- masked=len(pmpath)
- return (protected > masked)
-
def unmerge(self,pkgfiles=None,trimworld=1,cleanup=1):
global db, dircache
dircache={}
@@ -6895,10 +6908,12 @@ def update_config_files(config_root, mysettings, update_iter):
write_atomic(os.path.join(config_root, WORLD_FILE), "\n".join(worldlist))
+ protect_obj = config_protect(config_root,
+ mysettings.get("CONFIG_PROTECT","").split(),
+ mysettings.get("CONFIG_PROTECT_MASK","").split())
for x in update_files:
- mydblink = dblink('', '', config_root, mysettings)
updating_file = os.path.join(abs_user_config, x)
- if mydblink.isprotected(updating_file):
+ if protect_obj.isprotected(updating_file):
updating_file = new_protect_filename(updating_file)[0]
try:
write_atomic(updating_file, "".join(file_contents[x]))