summaryrefslogtreecommitdiff
path: root/src/buildstream/_context.py
diff options
context:
space:
mode:
authorBenjamin Schubert <contact@benschubert.me>2019-07-26 16:10:21 +0100
committerBenjamin Schubert <contact@benschubert.me>2019-07-29 10:42:02 +0100
commit0202301108feeecd52ccd6b23a87f7fb325fa36d (patch)
treeb2d3320435ad0f507035e41814858ec89f37fbe1 /src/buildstream/_context.py
parentb632e471f1ca4764c15534006294f7dc0b842b69 (diff)
downloadbuildstream-0202301108feeecd52ccd6b23a87f7fb325fa36d.tar.gz
context: Move 'CacheBuildTrees' to a FastEnum
This allows removing completely the '_node_get_option_str' on context and ensures every method relying on a few set of keys set their errors consistently
Diffstat (limited to 'src/buildstream/_context.py')
-rw-r--r--src/buildstream/_context.py32
1 files changed, 2 insertions, 30 deletions
diff --git a/src/buildstream/_context.py b/src/buildstream/_context.py
index 4d68ef222..c1a3b0619 100644
--- a/src/buildstream/_context.py
+++ b/src/buildstream/_context.py
@@ -29,7 +29,7 @@ from ._platform import Platform
from ._artifactcache import ArtifactCache
from ._sourcecache import SourceCache
from ._cas import CASCache, CASQuota, CASCacheUsage
-from .types import _SchedulerErrorAction
+from .types import _CacheBuildTrees, _SchedulerErrorAction
from ._workspaces import Workspaces, WorkspaceProjectCache
from .node import Node
from .sandbox import SandboxRemote
@@ -299,8 +299,7 @@ class Context():
self.pull_buildtrees = cache.get_bool('pull-buildtrees')
# Load cache build trees configuration
- self.cache_buildtrees = _node_get_option_str(
- cache, 'cache-buildtrees', ['always', 'auto', 'never'])
+ self.cache_buildtrees = cache.get_enum('cache-buildtrees', _CacheBuildTrees)
# Load logging config
logging = defaults.get_mapping('logging')
@@ -503,30 +502,3 @@ class Context():
if self._casquota is None:
self._casquota = CASQuota(self)
return self._casquota
-
-
-# _node_get_option_str()
-#
-# Like Node.get_scalar().as_str(), but also checks value is one of the allowed option
-# strings. Fetches a value from a dictionary node, and makes sure it's one of
-# the pre-defined options.
-#
-# Args:
-# node (dict): The dictionary node
-# key (str): The key to get a value for in node
-# allowed_options (iterable): Only accept these values
-#
-# Returns:
-# The value, if found in 'node'.
-#
-# Raises:
-# LoadError, when the value is not of the expected type, or is not found.
-#
-def _node_get_option_str(node, key, allowed_options):
- result_node = node.get_scalar(key)
- result = result_node.as_str()
- if result not in allowed_options:
- provenance = result_node.get_provenance()
- raise LoadError("{}: {} should be one of: {}".format(provenance, key, ", ".join(allowed_options)),
- LoadErrorReason.INVALID_DATA)
- return result