diff options
author | Tristan Maat <tm@tlater.net> | 2018-03-22 09:00:08 +0000 |
---|---|---|
committer | Tristan Maat <tm@tlater.net> | 2018-03-22 09:00:08 +0000 |
commit | 3a5a79d7c6aa84c3b60564cb69d30cf35ae2b2aa (patch) | |
tree | 3f059f5f8356251a02b5f3e65726d9a386b3f43b | |
parent | 673a6b1206127a87ebe7c36e1db85b1d04089c65 (diff) | |
download | buildstream-richardmaw-271-workspaces-versioning.tar.gz |
Temporary commitrichardmaw-271-workspaces-versioning
-rwxr-xr-x | buildstream/_project.py | 52 |
1 files changed, 26 insertions, 26 deletions
diff --git a/buildstream/_project.py b/buildstream/_project.py index f4a543b9d..df23feb9d 100755 --- a/buildstream/_project.py +++ b/buildstream/_project.py @@ -212,8 +212,11 @@ class Project(): self.artifact_cache_specs = artifact_cache_specs_from_config_node(config) # Workspace configurations - self._workspaces = self._load_workspace_config() - self._ensure_workspace_config_format() + workspace_config = self._load_workspace_config() + rewrite, self._workspaces = self._ensure_workspace_config_format(workspace_config) + + if rewrite: + self._save_workspace_config() # Assert project version format_version = _yaml.node_get(config, int, 'format-version') @@ -365,8 +368,7 @@ class Project(): # A tuple in the following format: (element, path). def _list_workspaces(self): for element, _ in _yaml.node_items(self._workspaces): - if element != "version": - yield (element, self._workspaces[element]["path"]) + yield (element, self._workspaces[element]["path"]) # _get_workspace() # @@ -381,9 +383,6 @@ class Project(): # otherwise # def _get_workspace(self, element): - if element == "version": - raise LoadError(LoadErrorReason.INVALID_DATA, - "Workspaces for elements named version are not supported.") if element not in self._workspaces: return None return self._workspaces[element]["path"] @@ -398,9 +397,6 @@ class Project(): # path (str) - The path to set the workspace to # def _set_workspace(self, element, path): - if element == "version": - raise LoadError(LoadErrorReason.INVALID_DATA, - "Workspaces for elements named version are not supported.") if element.name not in self._workspaces: self._workspaces[element.name] = {} @@ -417,9 +413,6 @@ class Project(): # element (str) - The element name # def _delete_workspace(self, element): - if element == "version": - raise LoadError(LoadErrorReason.INVALID_DATA, - "Workspaces for elements named version are not supported.") del self._workspaces[element] # _load_workspace_config() @@ -457,15 +450,20 @@ class Project(): # Args: # workspaces (dict): current workspace config, usually output of _load_workspace_config() # + # Returns: + # (bool, dict) Whether the workspace config needs to be + # rewritten and extracted workspaces + # # Raises: LoadError if there was a problem with the workspace config # - def _ensure_workspace_config_format(self): + def _parse_workspace_config(self, workspaces): needs_rewrite = False - version = _yaml.node_get(self._workspaces, int, "version", default_value=0) + version = _yaml.node_get(workspaces, int, "version", default_value=0) + res = {} if version == 0: # Pre-versioning format can be of two forms - for element, config in _yaml.node_items(self._workspaces): + for element, config in _yaml.node_items(workspaces): if isinstance(config, str): pass @@ -479,22 +477,21 @@ class Project(): detail.format(element, os.path.join(self.directory, ".bst", "workspaces.yml"))) - self._workspaces[element] = sources[0][1] + workspaces[element] = sources[0][1] needs_rewrite = True else: raise LoadError(LoadErrorReason.INVALID_DATA, "Workspace config is in unexpected format.") - self._workspaces = { + res = { element: {"path": config} - for element, config in _yaml.node_items(self._workspaces) - if element != "version"} - self._workspaces["version"] = BST_WORKSPACE_FORMAT_VERSION + for element, config in _yaml.node_items(workspaces) + } needs_rewrite = True elif version == BST_WORKSPACE_FORMAT_VERSION: - pass + res = _yaml.node_get(workspaces, dict, "workspaces", default_value={}) else: raise LoadError(LoadErrorReason.INVALID_DATA, @@ -502,8 +499,7 @@ class Project(): "Your version of buildstream may be too old. Max supported version: {}" .format(version, BST_WORKSPACE_FORMAT_VERSION)) - if needs_rewrite: - self._save_workspace_config() + return needs_rewrite, res # _save_workspace_config() # @@ -512,8 +508,12 @@ class Project(): # _set_workspace permanent # def _save_workspace_config(self): - _yaml.dump(_yaml.node_sanitize(self._workspaces), - os.path.join(self.directory, ".bst", "workspaces.yml")) + _yaml.dump( + { + "version": BST_WORKSPACE_FORMAT_VERSION, + "workspaces": _yaml.node_sanitize(self._workspaces) + }, + os.path.join(self.directory, ".bst", "workspaces.yml")) def _extract_plugin_paths(self, node, name): if not node: |