diff options
author | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2018-04-02 19:55:24 +0900 |
---|---|---|
committer | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2018-04-02 19:55:57 +0900 |
commit | 19e31adb00f19f0789a3c4622150ca8f6e9c8901 (patch) | |
tree | ee84cbb595ecdf274801a1864b484bf0d0dc1657 /buildstream/_pipeline.py | |
parent | 8b5742dd8b3d6e437703ca02553804ce7cc9d53d (diff) | |
download | buildstream-19e31adb00f19f0789a3c4622150ca8f6e9c8901.tar.gz |
Refactoring of highlevel workspace code
Move all workspace related code out of Pipeline() and into the
frontend App() object.
Some changes in transition here include:
o Workspaces() object methods for looking up and deleting workspaces
now take an element name instead of an element.
o Share code for partial App() initialization between the
`workspace close` and `workspace list` commands
o No longer require that an element exist in the project
in order to close a workspace
This fixes issue #249
Diffstat (limited to 'buildstream/_pipeline.py')
-rw-r--r-- | buildstream/_pipeline.py | 136 |
1 files changed, 0 insertions, 136 deletions
diff --git a/buildstream/_pipeline.py b/buildstream/_pipeline.py index 59219ab11..676b068a7 100644 --- a/buildstream/_pipeline.py +++ b/buildstream/_pipeline.py @@ -22,7 +22,6 @@ import os import stat import shlex -import shutil import tarfile import itertools from contextlib import contextmanager @@ -574,141 +573,6 @@ class Pipeline(): else: utils.link_files(sandbox_root, directory) - # open_workspace - # - # Open a project workspace. - # - # Args: - # directory (str): The directory to stage the source in - # no_checkout (bool): Whether to skip checking out the source - # track_first (bool): Whether to track and fetch first - # force (bool): Whether to ignore contents in an existing directory - # - def open_workspace(self, scheduler, directory, no_checkout, track_first, force): - # When working on workspaces we only have one target - target = self.targets[0] - workdir = os.path.abspath(directory) - - if not list(target.sources()): - build_depends = [x.name for x in target.dependencies(Scope.BUILD, recurse=False)] - if not build_depends: - raise PipelineError("The given element has no sources or build-dependencies") - detail = "Try opening a workspace on one of its dependencies instead:\n" - detail += " \n".join(build_depends) - raise PipelineError("The given element has no sources", detail=detail) - - # Check for workspace config - if self.project._workspaces.get_workspace(target): - raise PipelineError("Workspace '{}' is already defined." - .format(target.name)) - - plan = [target] - - # Track/fetch if required - queues = [] - track = None - - if track_first: - track = TrackQueue() - queues.append(track) - if not no_checkout or track_first: - fetch = FetchQueue(skip_cached=True) - queues.append(fetch) - - if queues: - queues[0].enqueue(plan) - - _, status = scheduler.run(queues) - if status == SchedStatus.ERROR: - raise PipelineError() - elif status == SchedStatus.TERMINATED: - raise PipelineError(terminated=True) - - if not no_checkout and target._consistency() != Consistency.CACHED: - raise PipelineError("Could not stage uncached source. " + - "Use `--track` to track and " + - "fetch the latest version of the " + - "source.") - - # Check directory - try: - os.makedirs(directory, exist_ok=True) - except OSError as e: - raise PipelineError("Failed to create workspace directory: {}".format(e)) from e - - workspace = self.project._workspaces.create_workspace(target, workdir) - - if not no_checkout: - if not force and os.listdir(directory): - raise PipelineError("Checkout directory is not empty: {}".format(directory)) - - with target.timed_activity("Staging sources to {}".format(directory)): - workspace.open() - - with target.timed_activity("Saving workspace configuration"): - self.project._workspaces.save_config() - - # close_workspace - # - # Close a project workspace - # - # Args: - # remove_dir (bool) - Whether to remove the associated directory - # - def close_workspace(self, remove_dir): - # When working on workspaces we only have one target - target = self.targets[0] - - # Remove workspace directory if prompted - if remove_dir: - workspace = self.project._workspaces.get_workspace(target) - if workspace is not None: - with target.timed_activity("Removing workspace directory {}" - .format(workspace.path)): - try: - shutil.rmtree(workspace.path) - except OSError as e: - raise PipelineError("Could not remove '{}': {}" - .format(workspace.path, e)) from e - - # Delete the workspace config entry - with target.timed_activity("Removing workspace"): - try: - self.project._workspaces.delete_workspace(target) - except KeyError: - raise PipelineError("Workspace '{}' is currently not defined" - .format(target.name)) - - # Update workspace config - self.project._workspaces.save_config() - - # Reset source to avoid checking out the (now empty) workspace - for source in target.sources(): - source._del_workspace() - - # reset_workspace - # - # Reset a workspace to its original state, discarding any user - # changes. - # - # Args: - # scheduler: The app scheduler - # track (bool): Whether to also track the source - # no_checkout (bool): Whether to check out the source (at all) - # - def reset_workspace(self, scheduler, track, no_checkout): - # When working on workspaces we only have one target - target = self.targets[0] - workspace = self.project._workspaces.get_workspace(target) - - if workspace is None: - raise PipelineError("Workspace '{}' is currently not defined" - .format(target.name)) - - self.close_workspace(True) - - self.open_workspace(scheduler, workspace.path, no_checkout, track, False) - # pull() # # Pulls elements from the pipeline |