LocationsManager: extensible _profile_node object
authorZac Medico <zmedico@gentoo.org>
Thu, 27 Oct 2011 20:49:40 +0000 (13:49 -0700)
committerZac Medico <zmedico@gentoo.org>
Thu, 27 Oct 2011 20:49:40 +0000 (13:49 -0700)
Use immutable object attrubutes instead of tuples, for extensibility.

pym/portage/package/ebuild/_config/KeywordsManager.py
pym/portage/package/ebuild/_config/LocationsManager.py
pym/portage/package/ebuild/_config/MaskManager.py
pym/portage/package/ebuild/_config/UseManager.py
pym/portage/package/ebuild/config.py

index 704ddca70f4944b1854a8e18e848c3ef9063a1c1..2f9f7b30557324450155008f4351d5340f24d2e9 100644 (file)
@@ -20,7 +20,8 @@ class KeywordsManager(object):
                                global_accept_keywords=""):
                self._pkeywords_list = []
                rawpkeywords = [grabdict_package(
-                       os.path.join(x[0], "package.keywords"), recursive=x[1],
+                       os.path.join(x.location, "package.keywords"),
+                       recursive=x.portage1_directories,
                        verify_eapi=True) \
                        for x in profiles]
                for pkeyworddict in rawpkeywords:
@@ -35,7 +36,8 @@ class KeywordsManager(object):
 
                self._p_accept_keywords = []
                raw_p_accept_keywords = [grabdict_package(
-                       os.path.join(x[0], "package.accept_keywords"), recursive=x[1],
+                       os.path.join(x.location, "package.accept_keywords"),
+                       recursive=x.portage1_directories,
                        verify_eapi=True) \
                        for x in profiles]
                for d in raw_p_accept_keywords:
index d793625429562c5b8cd9f893ccb5b77d55a0fc4c..ec3f0035fa392b1609894e8880b10b9ab5b532e1 100644 (file)
@@ -23,6 +23,18 @@ _PORTAGE1_DIRECTORIES = frozenset([
        'package.use', 'package.use.mask', 'package.use.force',
        'use.mask', 'use.force'])
 
+class _profile_node(object):
+
+       __slots__ = ('location', 'portage1_directories')
+
+       def __init__(self, location, portage1_directories):
+               object.__setattr__(self, 'location', location)
+               object.__setattr__(self, 'portage1_directories', portage1_directories)
+
+       def __setattr__(self, name, value):
+               raise AttributeError("_profile_node instances are immutable",
+                       self.__class__, name, value)
+
 class LocationsManager(object):
 
        def __init__(self, config_root=None, eprefix=None, config_profile_path=None, local_config=True, \
@@ -92,7 +104,7 @@ class LocationsManager(object):
                        if os.path.exists(custom_prof):
                                self.user_profile_dir = custom_prof
                                self.profiles.append(custom_prof)
-                               self.profiles_complex.append((custom_prof, True))
+                               self.profiles_complex.append(_profile_node(custom_prof, True))
                        del custom_prof
 
                self.profiles = tuple(self.profiles)
@@ -177,7 +189,8 @@ class LocationsManager(object):
                                                (parentPath, parentsFile))
 
                self.profiles.append(currentPath)
-               self.profiles_complex.append((currentPath, allow_directories))
+               self.profiles_complex.append(
+                       _profile_node(currentPath, allow_directories))
 
        def set_root_override(self, root_overwrite=None):
                # Allow ROOT setting to come from make.conf if it's not overridden
index a2bfb19b190b0abefc19eeb98fd7d0608c43e45e..6b0f1c32a60b9683ca03119705fcc7c0db466c65 100644 (file)
@@ -115,12 +115,16 @@ class MaskManager(object):
                #to allow profiles to override masks from their parent profiles.
                profile_pkgmasklines = []
                profile_pkgunmasklines = []
-               for x, portage1_mode in profiles:
+               for x in profiles:
                        profile_pkgmasklines.append(grabfile_package(
-                               os.path.join(x, "package.mask"), recursive=portage1_mode, remember_source_file=True, verify_eapi=True))
-                       if portage1_mode:
+                               os.path.join(x.location, "package.mask"),
+                               recursive=x.portage1_directories,
+                               remember_source_file=True, verify_eapi=True))
+                       if x.portage1_directories:
                                profile_pkgunmasklines.append(grabfile_package(
-                                       os.path.join(x, "package.unmask"), recursive=1, remember_source_file=True, verify_eapi=True))
+                                       os.path.join(x.location, "package.unmask"),
+                                       recursive=x.portage1_directories,
+                                       remember_source_file=True, verify_eapi=True))
                profile_pkgmasklines = stack_lists(profile_pkgmasklines, incremental=1, \
                        remember_source_file=True, warn_for_unmatched_removal=True,
                        strict_warn_for_unmatched_removal=strict_umatched_removal)
index bf06bd79da225ac63ea8cf57fe87b9bba4823c55..0506af019948ad2612cb3962a76240877a6dde40 100644 (file)
@@ -132,11 +132,15 @@ class UseManager(object):
                return ret
 
        def _parse_profile_files_to_tuple_of_tuples(self, file_name, locations):
-               return tuple(self._parse_file_to_tuple(os.path.join(profile[0], file_name), recursive=profile[1])
+               return tuple(self._parse_file_to_tuple(
+                       os.path.join(profile.location, file_name),
+                       recursive=profile.portage1_directories)
                        for profile in locations)
 
        def _parse_profile_files_to_tuple_of_dicts(self, file_name, locations, juststrings=False):
-               return tuple(self._parse_file_to_dict(os.path.join(profile[0], file_name), juststrings, recursive=profile[1])
+               return tuple(self._parse_file_to_dict(
+                       os.path.join(profile.location, file_name), juststrings,
+                       recursive=profile.portage1_directories)
                        for profile in locations)
 
        def getUseMask(self, pkg=None):
index 34a326e498d93b659bfbc50fe49f8cacfce08b95..47ea7f8285b460146f176fc9f9b683b7f3e9d01f 100644 (file)
@@ -637,8 +637,10 @@ class config(object):
                        archlist = stack_lists(archlist, incremental=1)
                        self.configdict["conf"]["PORTAGE_ARCHLIST"] = " ".join(archlist)
 
-                       pkgprovidedlines = [grabfile(os.path.join(loc, "package.provided"), recursive=recursive)
-                               for loc, recursive in self.profiles_complex]
+                       pkgprovidedlines = [grabfile(
+                               os.path.join(x.location, "package.provided"),
+                               recursive=x.portage1_directories)
+                               for x in self.profiles_complex]
                        pkgprovidedlines = stack_lists(pkgprovidedlines, incremental=1)
                        has_invalid_data = False
                        for x in range(len(pkgprovidedlines)-1, -1, -1):