diff options
author | Alec Warner <antarus@gentoo.org> | 2007-03-08 07:10:40 +0000 |
---|---|---|
committer | Alec Warner <antarus@gentoo.org> | 2007-03-08 07:10:40 +0000 |
commit | e61f3e1258dbbd74b5a85e4555b68ac8ff7e3908 (patch) | |
tree | 8c1034777b0214dc3e42566ba911703ed0a83b33 /pym/portage/env | |
parent | 934a71d5ddeb42dba7dd35ab129760a3482c416f (diff) | |
download | portage-e61f3e1258dbbd74b5a85e4555b68ac8ff7e3908.tar.gz portage-e61f3e1258dbbd74b5a85e4555b68ac8ff7e3908.tar.bz2 portage-e61f3e1258dbbd74b5a85e4555b68ac8ff7e3908.zip |
add PackageMask{File} classes, change unit tests to use try/finally, makes sure the tempfile gets destroyed even if something weird happens
svn path=/main/trunk/; revision=6193
Diffstat (limited to 'pym/portage/env')
-rw-r--r-- | pym/portage/env/config.py | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/pym/portage/env/config.py b/pym/portage/env/config.py index eccd35e08..e3898c539 100644 --- a/pym/portage/env/config.py +++ b/pym/portage/env/config.py @@ -112,3 +112,58 @@ class PackageUseFile(PackageUse): self.data[key].append(items) else: self.data[key] = items + +class PackageMask(UserDIct): + """ + A base class for Package.mask functionality + """ + 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() + + def iterkeys(self): + return self.data.iterkeys() + +class PackageMaskFile(PackageMask): + """ + A class that implements a file-based package.mask + + Entires in package.mask are of the form: + atom1 + atom2 + or optionally + -atom3 + to revert a previous mask; this only works when masking files are stacked + """ + + 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): + atom = split[0] # This is an extra assignment, but I think it makes the code more explicit in what goes into the dict + self.data[atom] = None # we only care about keys in the dict, basically abusing it as a list |