diff options
author | Jürg Billeter <j@bitron.ch> | 2017-07-19 15:32:48 +0200 |
---|---|---|
committer | Jürg Billeter <j@bitron.ch> | 2017-07-20 07:24:56 +0200 |
commit | 2c04a7746229c89fd0589cae89c83104f43f4702 (patch) | |
tree | d7f02a229f6c3897be849141749c3f82c48e3b54 | |
parent | 513ee660cc3412f4bc127e0e66c7ed36db660d40 (diff) | |
download | buildstream-2c04a7746229c89fd0589cae89c83104f43f4702.tar.gz |
_artifactcache: Add set_offline()
-rw-r--r-- | buildstream/_artifactcache/artifactcache.py | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/buildstream/_artifactcache/artifactcache.py b/buildstream/_artifactcache/artifactcache.py index e8ec28abc..2508e0b88 100644 --- a/buildstream/_artifactcache/artifactcache.py +++ b/buildstream/_artifactcache/artifactcache.py @@ -65,6 +65,8 @@ class ArtifactCache(): self.__remote_refs = None + self.__offline = False + # contains(): # # Check whether the artifact for the specified Element is already available @@ -224,7 +226,7 @@ class ArtifactCache(): # Returns: True if remote repository is available, False otherwise # def can_fetch(self): - return self.remote is not None + return not self.__offline and self.remote is not None # pull(): # @@ -236,6 +238,9 @@ class ArtifactCache(): # def pull(self, element, progress=None): + if self.__offline: + raise _ArtifactError("Attempt to pull artifact while offline") + if self.context.artifact_pull.startswith("/"): remote = "file://" + self.context.artifact_pull elif self.remote is not None: @@ -314,7 +319,7 @@ class ArtifactCache(): # Returns: True if remote repository is available, False otherwise # def can_push(self): - return self.context.artifact_push is not None + return not self.__offline and self.context.artifact_push is not None # push(): # @@ -331,6 +336,9 @@ class ArtifactCache(): # _ArtifactError if there was an error def push(self, element): + if self.__offline: + raise _ArtifactError("Attempt to push artifact while offline") + if self.context.artifact_push is None: raise _ArtifactError("Attempt to push artifact without any push URL") @@ -369,3 +377,10 @@ class ArtifactCache(): raise _ArtifactError("Failed to push artifact {}: {}".format(ref, e)) from e return pushed + + # set_offline(): + # + # Do not attempt to pull or push artifacts. + # + def set_offline(self): + self.__offline = True |