summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pym/portage/env/config.py55
-rw-r--r--pym/portage/tests/env/config/test_PackageKeywordsFile.py14
-rw-r--r--pym/portage/tests/env/config/test_PackageMaskFile.py30
-rw-r--r--pym/portage/tests/env/config/test_PackageUseFile.py14
4 files changed, 101 insertions, 12 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
diff --git a/pym/portage/tests/env/config/test_PackageKeywordsFile.py b/pym/portage/tests/env/config/test_PackageKeywordsFile.py
index 6c5475881..1d72504b9 100644
--- a/pym/portage/tests/env/config/test_PackageKeywordsFile.py
+++ b/pym/portage/tests/env/config/test_PackageKeywordsFile.py
@@ -18,12 +18,14 @@ class PackageKeywordsFileTestCase(TestCase):
"""
self.BuildFile()
- f = PackageKeywordsFile(self.fname)
- f.load(recursive=False)
- for cpv, keyword in f.iteritems():
- self.assertEqual( cpv, self.cpv )
- [k for k in keyword if self.assertTrue(k in self.keywords)]
- self.NukeFile()
+ try:
+ f = PackageKeywordsFile(self.fname)
+ f.load(recursive=False)
+ for cpv, keyword in f.iteritems():
+ self.assertEqual( cpv, self.cpv )
+ [k for k in keyword if self.assertTrue(k in self.keywords)]
+ finally;
+ self.NukeFile()
def BuildFile(self):
f = open(self.fname, 'wb')
diff --git a/pym/portage/tests/env/config/test_PackageMaskFile.py b/pym/portage/tests/env/config/test_PackageMaskFile.py
new file mode 100644
index 000000000..f17eaf021
--- /dev/null
+++ b/pym/portage/tests/env/config/test_PackageMaskFile.py
@@ -0,0 +1,30 @@
+# test_PackageMaskFile.py -- Portage Unit Testing Functionality
+# Copyright 2007 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Id: test_PackageMaskFile.py 6182 2007-03-06 07:35:22Z antarus $
+
+from portage.env.config import PackageMaskFile
+from portage.tests import TestCase
+
+class PackageMaskFileTestCase(TestCase):
+
+ fname = 'package.mask'
+ atoms = ['sys-apps/portage','dev-util/diffball','not@va1id@t0m']
+
+ def testPackageMaskLoad(self):
+ self.BuildFile()
+ try:
+ f = PackageMaskFile(self.fname)
+ f.load(recursive=False)
+ [atom for atom in f.iterkeys() if self.assertTrue(atom in self.atoms)]
+ finally:
+ self.NukeFile()
+
+ def BuildFile(self):
+ f = open(self.fname, 'wb')
+ f.write("\n".join(atoms))
+ f.close()
+
+ def NukeFile(self):
+ import os
+ os.unlink(self.fname)
diff --git a/pym/portage/tests/env/config/test_PackageUseFile.py b/pym/portage/tests/env/config/test_PackageUseFile.py
index 6dd76eeca..4638923df 100644
--- a/pym/portage/tests/env/config/test_PackageUseFile.py
+++ b/pym/portage/tests/env/config/test_PackageUseFile.py
@@ -17,12 +17,14 @@ class PackageUseFileTestCase(TestCase):
A simple test to ensure the load works properly
"""
self.BuildFile()
- f = PackageUseFile(self.fname)
- f.load(recursive=False)
- for cpv, use in f.iteritems():
- self.assertEqual( cpv, self.cpv )
- [flag for flag in use if self.assertTrue(flag in self.useflags)]
- self.NukeFile()
+ try:
+ f = PackageUseFile(self.fname)
+ f.load(recursive=False)
+ for cpv, use in f.iteritems():
+ self.assertEqual( cpv, self.cpv )
+ [flag for flag in use if self.assertTrue(flag in self.useflags)]
+ finally:
+ self.NukeFile()
def BuildFile(self):
f = open(self.fname, 'wb')