After talking to marienz, decide that 1 class is better than 4, also realize that...
authorAlec Warner <antarus@gentoo.org>
Sat, 31 Mar 2007 19:42:35 +0000 (19:42 -0000)
committerAlec Warner <antarus@gentoo.org>
Sat, 31 Mar 2007 19:42:35 +0000 (19:42 -0000)
svn path=/main/trunk/; revision=6328

pym/portage/env/config.py
pym/portage/env/loaders.py

index 3bac9a3a505a9e7d76dcc3b1becc64218454e6d4..ca533286fbf29c3b9f6836d10ac4206d2e7e7b69 100644 (file)
 from UserDict import UserDict
 from portage.env.loaders import KeyListFileLoader, KeyValuePairFileLoader, AtomFileLoader
 
-class PackageKeywords(UserDict):
+class UserConfigKlass(UserDict,object):
        """
-       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':['keyword1','keyword2','keyword3'...]
+       A base class stub for things to inherit from.
+       Users may want a non-file backend.
        """
        
        data = {}
        
        def __init__(self, loader):
+               """
+               @param loader: A class that has a load() that returns two dicts
+                       the first being a data dict, the second being a dict of errors.
+               """
                self._loader = loader
 
        def load(self):
+               """
+               Load the data from the loader.
+
+               @throws LoaderError:
+               """
+
                self.data, self.errors = self._loader.load()
 
-       def iteritems(self):
-               return self.data.iteritems()
-       
-       def keys(self):
-               return self.data.keys()
-       
-       def __contains__(self, other):
-               return other in self.data
-       
-       def __hash__( self ):
-               return self.data.__hash__()
-       
-class PackageKeywordsFile(PackageKeywords):
+class PackageKeywordsFile(UserConfigKlass):
        """
-       Inherits from PackageKeywords; implements a file-based backend.  Doesn't handle recursion yet.
+       Inherits from UserConfigKlass; implements a file-based backend.
        """
 
        default_loader = KeyListFileLoader
 
        def __init__(self, filename):
-               PackageKeywords.__init__(self, self.default_loader(filename))
-       
-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 = {}
+               super(PackageKeywordsFile,self).__init__(self.default_loader(filename))
        
-       def __init__(self, loader):
-               self._loader = loader
-
-       def load( self):
-               self.data, self.errors = self._loader.load()
-
-       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):
+class PackageUseFile(UserConfigKlass):
        """
        Inherits from PackageUse; implements a file-based backend.  Doesn't handle recursion yet.
        """
 
        default_loader = KeyListFileLoader
        def __init__(self, filename):
-               PackageUse.__init__(self, self.default_loader(filename))
-       
-class PackageMask(UserDict):
-       """
-       A base class for Package.mask functionality
-       """
-       data = {}
+               super(PackageUseFile,self).__init__(self.default_loader(filename))
        
-       def __init__(self, loader):
-               self._loader = loader
-       
-       def load(self):
-               self.data, self.errors = self._loader.load()
-               
-       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):
+class PackageMaskFile(UserConfigKlass):
        """
        A class that implements a file-based package.mask
        
@@ -123,37 +64,9 @@ class PackageMaskFile(PackageMask):
        default_loader = AtomFileLoader
 
        def __init__(self, filename):
-               PackageMask.__init__(self, self.default_loader(filename))
-
-class PortageModules(UserDict):
-       """
-       Base Class for user level module over-rides
-       """
-       
-       data = {}
-
-       def __init__(self, loader):
-               self._loader = loader
-
-       def load(self):
-               self.data, self.errors = self._loader.load()
-
-       def iteritems(self):
-               return self.data.iteritems()
-       
-       def __hash__(self):
-               return self.data.__hash__()
-
-       def __contains__(self, key):
-               return key in self.data
-
-       def keys(self):
-               return self.data.keys()
-       
-       def iterkeys(self):
-               return self.data.iterkeys()
+               super(PackageMaskFile,self).__init__(self.default_loader(filename))
 
-class PortageModulesFile(PortageModules):
+class PortageModulesFile(UserConfigKlass):
        """
        File Class for /etc/portage/modules
        """
@@ -161,4 +74,4 @@ class PortageModulesFile(PortageModules):
        default_loader = KeyValuePairFileLoader
        
        def __init__(self, filename):
-               PortageModules.__init__(self, self.default_loader(filename))
+               super(PortageModulesFile,self).__init__(self.default_loader(filename))
index 33a8c3d4f78f33f32d85bd208efee3891430fb84..18acd457c581f059f71f667e65df679e1dd52e3f 100644 (file)
@@ -5,6 +5,22 @@
 
 import os
 
+class LoaderError(Exception):
+       
+       def __init__(self, resource, error_msg):
+               """
+               @param resource: Resource that failed to load (file/sql/etc)
+               @type resource: String
+               @param error_msg: Error from underlying Loader system
+               @type error_msg: String
+               """
+
+               self.resource
+       
+       def __str__(self):
+               return "Failed while loading resource: %s, error was: %s" % (
+                       resource, error_msg)
+
 def RecursiveFileLoader(filename):
        """
        If filename is of type file, return [filename]
@@ -164,3 +180,4 @@ class KeyValuePairFileLoader(DataLoader):
                                else:
                                        data[key] = value
                return (data,errors)
+