summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaoul Hidalgo Charman <raoul.hidalgocharman@codethink.co.uk>2019-03-08 17:26:00 +0000
committerbst-marge-bot <marge-bot@buildstream.build>2019-03-25 11:46:44 +0000
commitf5971afc4c5558453103e54f0e3ac4c18e5bafc4 (patch)
treeb50a40af6291d47ee8b17b3ba5332bf2281c6a47
parent1ab80a03e6611cbc0e7480ce442717ca07f1a0ab (diff)
downloadbuildstream-f5971afc4c5558453103e54f0e3ac4c18e5bafc4.tar.gz
_basecache.py: Moves has remote methods
Move both `has_push_remotes` and `has_fetch_remotes` from `ArtifactCache`. Part of #440
-rw-r--r--buildstream/_artifactcache.py42
-rw-r--r--buildstream/_basecache.py42
-rw-r--r--buildstream/element.py4
-rw-r--r--tests/artifactcache/pull.py2
-rw-r--r--tests/artifactcache/push.py4
5 files changed, 47 insertions, 47 deletions
diff --git a/buildstream/_artifactcache.py b/buildstream/_artifactcache.py
index f97da4661..4af6f132c 100644
--- a/buildstream/_artifactcache.py
+++ b/buildstream/_artifactcache.py
@@ -263,48 +263,6 @@ class ArtifactCache(BaseCache):
return self.cas.diff(ref_a, ref_b, subdir=subdir)
- # has_fetch_remotes():
- #
- # Check whether any remote repositories are available for fetching.
- #
- # Args:
- # element (Element): The Element to check
- #
- # Returns: True if any remote repositories are configured, False otherwise
- #
- def has_fetch_remotes(self, *, element=None):
- if not self._has_fetch_remotes:
- # No project has fetch remotes
- return False
- elif element is None:
- # At least one (sub)project has fetch remotes
- return True
- else:
- # Check whether the specified element's project has fetch remotes
- remotes_for_project = self._remotes[element._get_project()]
- return bool(remotes_for_project)
-
- # has_push_remotes():
- #
- # Check whether any remote repositories are available for pushing.
- #
- # Args:
- # element (Element): The Element to check
- #
- # Returns: True if any remote repository is configured, False otherwise
- #
- def has_push_remotes(self, *, element=None):
- if not self._has_push_remotes:
- # No project has push remotes
- return False
- elif element is None:
- # At least one (sub)project has push remotes
- return True
- else:
- # Check whether the specified element's project has push remotes
- remotes_for_project = self._remotes[element._get_project()]
- return any(remote.spec.push for remote in remotes_for_project)
-
# push():
#
# Push committed artifact to remote repository.
diff --git a/buildstream/_basecache.py b/buildstream/_basecache.py
index a8c58e48f..696cbf9c1 100644
--- a/buildstream/_basecache.py
+++ b/buildstream/_basecache.py
@@ -190,6 +190,48 @@ class BaseCache():
self._remotes[project] = project_remotes
+ # has_fetch_remotes():
+ #
+ # Check whether any remote repositories are available for fetching.
+ #
+ # Args:
+ # plugin (Plugin): The Plugin to check
+ #
+ # Returns: True if any remote repositories are configured, False otherwise
+ #
+ def has_fetch_remotes(self, *, plugin=None):
+ if not self._has_fetch_remotes:
+ # No project has fetch remotes
+ return False
+ elif plugin is None:
+ # At least one (sub)project has fetch remotes
+ return True
+ else:
+ # Check whether the specified element's project has fetch remotes
+ remotes_for_project = self._remotes[plugin._get_project()]
+ return bool(remotes_for_project)
+
+ # has_push_remotes():
+ #
+ # Check whether any remote repositories are available for pushing.
+ #
+ # Args:
+ # element (Element): The Element to check
+ #
+ # Returns: True if any remote repository is configured, False otherwise
+ #
+ def has_push_remotes(self, *, plugin=None):
+ if not self._has_push_remotes:
+ # No project has push remotes
+ return False
+ elif plugin is None:
+ # At least one (sub)project has push remotes
+ return True
+ else:
+ # Check whether the specified element's project has push remotes
+ remotes_for_project = self._remotes[plugin._get_project()]
+ return any(remote.spec.push for remote in remotes_for_project)
+
################################################
# Local Private Methods #
################################################
diff --git a/buildstream/element.py b/buildstream/element.py
index cb04a9c15..08cdac724 100644
--- a/buildstream/element.py
+++ b/buildstream/element.py
@@ -1810,7 +1810,7 @@ class Element(Plugin):
# Pull is pending if artifact remote server available
# and pull has not been attempted yet
- return self.__artifacts.has_fetch_remotes(element=self) and not self.__pull_done
+ return self.__artifacts.has_fetch_remotes(plugin=self) and not self.__pull_done
# _pull_done()
#
@@ -1863,7 +1863,7 @@ class Element(Plugin):
# (bool): True if this element does not need a push job to be created
#
def _skip_push(self):
- if not self.__artifacts.has_push_remotes(element=self):
+ if not self.__artifacts.has_push_remotes(plugin=self):
# No push remotes for this element's project
return True
diff --git a/tests/artifactcache/pull.py b/tests/artifactcache/pull.py
index 3e05bcecf..3c10c256c 100644
--- a/tests/artifactcache/pull.py
+++ b/tests/artifactcache/pull.py
@@ -150,7 +150,7 @@ def _test_pull(user_config_file, project_dir, cache_dir,
# Manually setup the CAS remote
cas.setup_remotes(use_config=True)
- if cas.has_push_remotes(element=element):
+ if cas.has_push_remotes(plugin=element):
# Push the element's artifact
if not cas.pull(element, element_key):
queue.put("Pull operation failed")
diff --git a/tests/artifactcache/push.py b/tests/artifactcache/push.py
index 18d6d80bc..69f3fbfbb 100644
--- a/tests/artifactcache/push.py
+++ b/tests/artifactcache/push.py
@@ -125,7 +125,7 @@ def _test_push(user_config_file, project_dir, element_name, element_key, queue):
cas.setup_remotes(use_config=True)
cas.initialize_remotes()
- if cas.has_push_remotes(element=element):
+ if cas.has_push_remotes(plugin=element):
# Push the element's artifact
if not cas.push(element, [element_key]):
queue.put("Push operation failed")
@@ -184,7 +184,7 @@ def test_push_directory(cli, tmpdir, datafiles):
# Manually setup the CAS remote
artifactcache.setup_remotes(use_config=True)
artifactcache.initialize_remotes()
- assert artifactcache.has_push_remotes(element=element)
+ assert artifactcache.has_push_remotes(plugin=element)
# Recreate the CasBasedDirectory object from the cached artifact
artifact_ref = element.get_artifact_name(element_key)