layout.conf: make the pregenerated cache format controllable
authorBrian Harring <ferringb@chromium.org>
Thu, 13 Oct 2011 23:26:03 +0000 (16:26 -0700)
committerZac Medico <zmedico@gentoo.org>
Fri, 14 Oct 2011 00:19:26 +0000 (17:19 -0700)
Controllable via 'cache-format', currently it supports only one cache;
'pms', and defaults to it.  If an unsupported cache-format is specified,
the cache is disabled.  If pms is specified and metadata/cache directory
doesn't exist, the cache is disabled.

Finally, this rips out the best module support for locally overriding
the cache format used for pregenerated caches; this functionality made
zero sense (upstream determines the format, we use what is available).

bin/egencache
pym/_emerge/actions.py
pym/portage/dbapi/porttree.py
pym/portage/package/ebuild/config.py
pym/portage/repository/config.py

index 7766e786e02381cfa294b5876a4525bd0db3bd71..26660c1a98587f511aafe5b18d6b0b26cd4c163d 100755 (executable)
@@ -38,6 +38,7 @@ except ImportError:
 from portage import os, _encodings, _unicode_encode, _unicode_decode
 from _emerge.MetadataRegen import MetadataRegen
 from portage.cache.cache_errors import CacheError, StatCollision
+from portage.cache import metadata
 from portage.manifest import guessManifestFileType
 from portage.util import cmp_sort_key, writemsg_level
 from portage import cpv_getkey
@@ -214,8 +215,7 @@ class GenCache(object):
                        consumer=self._metadata_callback,
                        max_jobs=max_jobs, max_load=max_load)
                self.returncode = os.EX_OK
-               metadbmodule = portdb.settings.load_best_module("portdbapi.metadbmodule")
-               self._trg_cache = metadbmodule(portdb.porttrees[0],
+               self._trg_cache = metadata.database(portdb.porttrees[0],
                        "metadata/cache", portage.auxdbkeys[:])
                if rsync:
                        self._trg_cache.raise_stat_collision = True
index 08f70df05757df2cf70b376e7bab44bf50b3b03a..70a92c97256a39f2f16a1123a6c3d18f9b812f5c 100644 (file)
@@ -1660,14 +1660,6 @@ def action_metadata(settings, portdb, myopts, porttrees=None):
        porttrees_data = []
        for path in porttrees:
                src_db = portdb._pregen_auxdb.get(path)
-               if src_db is None and \
-                       os.path.isdir(os.path.join(path, 'metadata', 'cache')):
-                       src_db = portdb.metadbmodule(
-                               path, 'metadata/cache', auxdbkeys, readonly=True)
-                       try:
-                               src_db.ec = portdb._repo_info[path].eclass_db
-                       except AttributeError:
-                               pass
 
                if src_db is not None:
                        porttrees_data.append(TreeData(portdb.auxdb[path],
index ef2e08870669656279dcc1123f22610fc35b79ec..f48741b840e884576ae34305c538681377c3b233 100644 (file)
@@ -120,8 +120,6 @@ class portdbapi(dbapi):
                self._have_root_eclass_dir = os.path.isdir(
                        os.path.join(self.settings.repositories.mainRepoLocation(), "eclass"))
 
-               self.metadbmodule = self.settings.load_best_module("portdbapi.metadbmodule")
-
                #if the portdbapi is "frozen", then we assume that we can cache everything (that no updates to it are happening)
                self.xcache = {}
                self.frozen = 0
@@ -214,10 +212,10 @@ class portdbapi(dbapi):
                        for x in self.porttrees:
                                if x in self._pregen_auxdb:
                                        continue
-                               if os.path.isdir(os.path.join(x, "metadata", "cache")):
-                                       conf = self.repositories.get_repo_for_location(x)
-                                       cache = self._pregen_auxdb[x] = self.metadbmodule(
-                                               x, "metadata/cache", filtered_auxdbkeys, readonly=True)
+                               conf = self.repositories.get_repo_for_location(x)
+                               cache = conf.get_pregenerated_cache(filtered_auxdbkeys, readonly=True)
+                               if cache is not None:
+                                       self._pregen_auxdb[x] = cache
                                        try:
                                                cache.ec = self._repo_info[x].eclass_db
                                        except AttributeError:
index 73af0660e3bc194d0968a64c1924811483f2b773..37dcbb4cf3de3136aea48a7ab474cb05522cb244 100644 (file)
@@ -311,7 +311,6 @@ class config(object):
                        if self.modules["user"] is None:
                                self.modules["user"] = {}
                        self.modules["default"] = {
-                               "portdbapi.metadbmodule": "portage.cache.metadata.database",
                                "portdbapi.auxdbmodule":  "portage.cache.flat_hash.database",
                        }
 
index 2490b65da3a3160feee50c178ccc1a06236da324..9a5473820d76d69926f66246d528e6d72efcf365 100644 (file)
@@ -48,7 +48,7 @@ class RepoConfig(object):
                'eclass_overrides', 'eclass_locations', 'format', 'location',
                'main_repo', 'manifest_hashes', 'masters', 'missing_repo_name',
                'name', 'priority', 'sign_manifest', 'sync', 'thin_manifest',
-               'user_location')
+               'user_location', 'cache_format')
 
        def __init__(self, name, repo_opts):
                """Build a RepoConfig with options in repo_opts
@@ -126,6 +126,16 @@ class RepoConfig(object):
                self.create_manifest = True
                self.disable_manifest = False
                self.manifest_hashes = None
+               self.cache_format = None
+
+       def get_pregenerated_cache(self, auxdbkeys, readonly=True):
+               if self.cache_format is None:
+                       return None
+               elif self.cache_format == 'pms':
+                       from portage.cache.metadata import database
+                       return database(self.location, 'metadata/cache',
+                               auxdbkeys, readonly=readonly)
+               return None
 
        def load_manifest(self, *args, **kwds):
                kwds['thin'] = self.thin_manifest
@@ -377,6 +387,13 @@ class RepoConfigLoader(object):
                        repo.create_manifest = manifest_policy != 'false'
                        repo.disable_manifest = manifest_policy == 'false'
 
+                       # for compatibility w/ PMS, fallback to pms; but also check if the
+                       # cache exists or not.
+                       repo.cache_format = layout_data.get('cache-format', 'pms').lower()
+                       if repo.cache_format == 'pms' and not os.path.isdir(
+                               os.path.join(repo.location, 'metadata', 'cache')):
+                               repo.cache_format = None
+
                        manifest_hashes = layout_data.get('manifest-hashes')
                        if manifest_hashes is not None:
                                manifest_hashes = frozenset(manifest_hashes.upper().split())