dvc: add get_url()/open() API

As a part of this:
- DataCloud._cloud was refactored into `.get_remote()`
- data stopped using internal _cloud
- added a parametrization for remote tests
This commit is contained in:
Alexander Schepanovski
2019-05-27 17:56:31 +07:00
parent eac6adada6
commit ca93dbcf13
6 changed files with 147 additions and 36 deletions
+15 -26
View File
@@ -48,21 +48,25 @@ class DataCloud(object):
self._config = config
self._core = self._config[Config.SECTION_CORE]
@property
def _cloud(self):
"""Returns a Remote instance using the `core.remote` config"""
remote = self._core.get(Config.SECTION_CORE_REMOTE, "")
def get_remote(self, remote=None, command="<command>"):
if not remote:
remote = self._core.get(Config.SECTION_CORE_REMOTE)
if remote:
return self._init_remote(remote)
if self._core.get(Config.SECTION_CORE_CLOUD, None):
# backward compatibility
# Old config format support for backward compatibility
if Config.SECTION_CORE_CLOUD in self._core:
msg = "using obsoleted config format. Consider updating."
logger.warning(msg)
return self._init_compat()
return None
raise ConfigError(
"No remote repository specified. Setup default repository with\n"
" dvc config core.remote <name>\n"
"or use:\n"
" dvc {} -r <name>\n".format(command)
)
def _init_remote(self, remote):
section = Config.SECTION_REMOTE_FMT.format(remote).lower()
@@ -76,7 +80,6 @@ class DataCloud(object):
def _init_compat(self):
name = self._core.get(Config.SECTION_CORE_CLOUD, "").strip().lower()
if name == "":
self._cloud = None
return None
cloud_type = self.CLOUD_MAP.get(name, None)
@@ -104,20 +107,6 @@ class DataCloud(object):
cloud = cloud_type(self.repo, cloud_config)
return cloud
def _get_cloud(self, remote, cmd):
if remote:
return self._init_remote(remote)
if self._cloud:
return self._cloud
raise ConfigError(
"No remote repository specified. Setup default repository with\n"
" dvc config core.remote <name>\n"
"or use:\n"
" dvc {} -r <name>\n".format(cmd)
)
def push(self, targets, jobs=None, remote=None, show_checksums=False):
"""Push data items in a cloud-agnostic way.
@@ -132,7 +121,7 @@ class DataCloud(object):
return self.repo.cache.local.push(
targets,
jobs=jobs,
remote=self._get_cloud(remote, "push"),
remote=self.get_remote(remote, "push"),
show_checksums=show_checksums,
)
@@ -150,7 +139,7 @@ class DataCloud(object):
return self.repo.cache.local.pull(
targets,
jobs=jobs,
remote=self._get_cloud(remote, "pull"),
remote=self.get_remote(remote, "pull"),
show_checksums=show_checksums,
)
@@ -166,7 +155,7 @@ class DataCloud(object):
show_checksums (bool): show checksums instead of file names in
information messages.
"""
cloud = self._get_cloud(remote, "status")
remote = self.get_remote(remote, "status")
return self.repo.cache.local.status(
targets, jobs=jobs, remote=cloud, show_checksums=show_checksums
targets, jobs=jobs, remote=remote, show_checksums=show_checksums
)