summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlec Warner <antarus@gentoo.org>2007-03-08 06:44:06 +0000
committerAlec Warner <antarus@gentoo.org>2007-03-08 06:44:06 +0000
commit934a71d5ddeb42dba7dd35ab129760a3482c416f (patch)
tree368d4f3505d0a00122486d2a1f39f1b7b6d1f128 /pym/portage/env
parentPart of my attempt now involves cleaning up config; this means for me; removi... (diff)
downloadportage-multirepo-934a71d5ddeb42dba7dd35ab129760a3482c416f.tar.gz
portage-multirepo-934a71d5ddeb42dba7dd35ab129760a3482c416f.tar.bz2
portage-multirepo-934a71d5ddeb42dba7dd35ab129760a3482c416f.zip
Change load() to have no default arguments, makes caller specifiy explicitly...I think assuming a default arg is bad here. Also add PackageUse and PackageUseFile, change up the comments a bit. I've started to notice code re-use here; these are basically the same code. I think I will write up the rest of the package* classes and then perform code merges to save LOC and memory and whatnot
svn path=/main/trunk/; revision=6192
Diffstat (limited to 'pym/portage/env')
-rw-r--r--pym/portage/env/config.py58
1 files changed, 56 insertions, 2 deletions
diff --git a/pym/portage/env/config.py b/pym/portage/env/config.py
index 05bb4927..eccd35e0 100644
--- a/pym/portage/env/config.py
+++ b/pym/portage/env/config.py
@@ -11,7 +11,7 @@ class PackageKeywords(UserDict):
A base class stub for things to inherit from; some people may want a database based package.keywords or something
Internally dict has pairs of the form
- {'cpv':['key1','key2','key3'...]
+ {'cpv':['keyword1','keyword2','keyword3'...]
"""
data = {}
@@ -35,7 +35,7 @@ class PackageKeywordsFile(PackageKeywords):
def __init__( self, filename ):
self.fname = filename
- def load(self, recursive=False):
+ def load(self, recursive):
"""
Package.keywords files have comments that begin with #.
The entries are of the form:
@@ -58,3 +58,57 @@ class PackageKeywordsFile(PackageKeywords):
self.data[key].append(items)
else:
self.data[key] = items
+
+class PackageUse(UserDict):
+ """
+ A base class stub for things to inherit from; some people may want a database based package.keywords or something
+
+ Internally dict has pairs of the form
+ {'cpv':['flag1','flag22','flag3'...]
+ """
+
+ data = {}
+
+ def iteritems(self):
+ return self.data.iteritems()
+
+ def __hash__(self):
+ return hash(self.data)
+
+ def __contains__(self, other):
+ return other in self.data
+
+ def keys(self):
+ return self.data.keys()
+
+class PackageUseFile(PackageUse):
+ """
+ Inherits from PackageUse; implements a file-based backend. Doesn't handle recursion yet.
+ """
+ def __init__(self, filename):
+ self.fname = filename
+
+ def load(self, recursive):
+ """
+ Package.keywords files have comments that begin with #.
+ The entries are of the form:
+ >>> atom useflag1 useflag2 useflag3..
+ useflags may optionally be negative with a minus sign (-)
+ >>> atom useflag1 -useflag2 useflag3
+ """
+
+ if os.path.exists( self.fname ):
+ f = open(self.fname, 'rb')
+ for line in f:
+ if line.startswith('#'):
+ continue
+ split = line.split()
+ if len(split):
+ # Surprisingly this works for iterables of length 1
+ # fex ['sys-apps/portage','foo','bar'] becomes {'sys-apps/portage':['foo','bar']}
+ key, items = split[0],split[1:]
+ # if they specify the same cpv twice; stack the values (append) instead of overwriting.
+ if key in self.data:
+ self.data[key].append(items)
+ else:
+ self.data[key] = items