layout.conf: rename cache_format to cache_formats
authorZac Medico <zmedico@gentoo.org>
Tue, 25 Oct 2011 22:52:59 +0000 (15:52 -0700)
committerZac Medico <zmedico@gentoo.org>
Tue, 25 Oct 2011 22:52:59 +0000 (15:52 -0700)
We read layout.conf cache-formats from left to right and use the first
supported type that's found. This will allow support for multiple
formats in parallel, providing for smooth transitions between formats.

bin/egencache
pym/portage/repository/config.py

index 0d07cdb1b43ed249c38a8097159e654a7bac644b..dec10b1e0a35ad486c43462a3734d4260a8293e3 100755 (executable)
@@ -218,7 +218,8 @@ class GenCache(object):
                self._trg_cache = conf.get_pregenerated_cache(portage.auxdbkeys[:],
                        force=True, readonly=False)
                if self._trg_cache is None:
-                       raise Exception("cache format %s isn't supported" % (conf.cache_format,))
+                       raise Exception("cache formats '%s' aren't supported" %
+                               (" ".join(conf.cache_formats),))
                if rsync:
                        self._trg_cache.raise_stat_collision = True
                try:
index 377ba4733e5b5d3893a9ba2a525a5d1fb6d15003..9b4a76f59c0a219e2dbe659e2c3969705404d7ae 100644 (file)
@@ -44,7 +44,7 @@ class RepoConfig(object):
        """Stores config of one repository"""
 
        __slots__ = ('aliases', 'allow_missing_manifest',
-               'cache_format', 'create_manifest', 'disable_manifest',
+               'cache_formats', 'create_manifest', 'disable_manifest',
                'eclass_overrides', 'eclass_locations', 'format', 'location',
                'main_repo', 'manifest_hashes', 'masters', 'missing_repo_name',
                'name', 'priority', 'sign_manifest', 'sync', 'thin_manifest',
@@ -128,22 +128,32 @@ class RepoConfig(object):
                self.disable_manifest = False
                self.manifest_hashes = None
                self.update_changelog = False
-               self.cache_format = None
+               self.cache_formats = None
                self.portage1_profiles = True
                self.portage1_profiles_compat = False
 
        def get_pregenerated_cache(self, auxdbkeys, readonly=True, force=False):
-               format = self.cache_format
-               if format is None:
+               """
+               Reads layout.conf cache-formats from left to right and returns a
+               cache instance for the first supported type that's found. If no
+               cache-formats are specified in layout.conf, 'pms' type is assumed
+               if the metadata/cache directory exists or force is True.
+               """
+               formats = self.cache_formats
+               if not formats:
                        if not force:
                                return None
-                       format = 'pms'
-               if format == 'pms':
-                       from portage.cache.metadata import database
-                       name = 'metadata/cache'
-               elif format == 'md5-dict':
-                       from portage.cache.flat_hash import md5_database as database
-                       name = 'metadata/md5-cache'
+                       formats = ('pms',)
+
+               for fmt in formats:
+                       if fmt == 'pms':
+                               from portage.cache.metadata import database
+                               name = 'metadata/cache'
+                               break
+                       elif fmt == 'md5-dict':
+                               from portage.cache.flat_hash import md5_database as database
+                               name = 'metadata/md5-cache'
+                               break
                else:
                        return None
                return database(self.location, name,
@@ -379,7 +389,7 @@ class RepoConfigLoader(object):
                                repo.aliases = tuple(aliases) + layout_data['aliases']
 
                        for value in ('sign-manifest', 'thin-manifest', 'allow-missing-manifest',
-                               'create-manifest', 'disable-manifest', 'cache-format', 'manifest-hashes',
+                               'create-manifest', 'disable-manifest', 'cache-formats', 'manifest-hashes',
                                'update-changelog'):
                                setattr(repo, value.lower().replace("-", "_"), layout_data[value])
 
@@ -387,6 +397,8 @@ class RepoConfigLoader(object):
                                for x in layout_data['profile-formats'])
                        repo.portage1_profiles_compat = layout_data['profile-formats'] == ('portage-1-compat',)
 
+                       repo.cache_formats = layout_data['cache-formats']
+
                #Take aliases into account.
                new_prepos = {}
                for repo_name, repo in prepos.items():
@@ -608,11 +620,11 @@ def parse_layout_conf(repo_location, repo_name=None):
 
        # for compatibility w/ PMS, fallback to pms; but also check if the
        # cache exists or not.
-       cache_format = layout_data.get('cache-format', 'pms').lower()
-       if cache_format == 'pms' and not os.path.isdir(
+       cache_formats = layout_data.get('cache-formats', 'pms').lower().split()
+       if 'pms' in cache_formats and not os.path.isdir(
                os.path.join(repo_location, 'metadata', 'cache')):
-               cache_format = None
-       data['cache-format'] = cache_format
+               cache_formats.remove('pms')
+       data['cache-formats'] = tuple(cache_formats)
 
        manifest_hashes = layout_data.get('manifest-hashes')
        if manifest_hashes is not None: