dvc: refactor

Add a new return value for pull, push, and fetch.
It represents the number of files processed.

Fixes #1619
This commit is contained in:
Shao-Chun Ma
2019-02-16 15:25:05 +01:00
parent 33cdc50c88
commit 73b2a3362c
5 changed files with 24 additions and 10 deletions
+15 -3
View File
@@ -22,9 +22,11 @@ class CmdDataBase(CmdBase):
class CmdDataPull(CmdDataBase):
UP_TO_DATE_MSG = "Everything is up-to-date."
def do_run(self, target=None):
try:
self.repo.pull(
processed_files_count = self.repo.pull(
target=target,
jobs=self.args.jobs,
remote=self.args.remote,
@@ -38,13 +40,17 @@ class CmdDataPull(CmdDataBase):
except Exception:
logger.error("failed to pull data from the cloud")
return 1
if processed_files_count == 0:
logger.info(self.UP_TO_DATE_MSG)
return 0
class CmdDataPush(CmdDataBase):
UP_TO_DATE_MSG = "Everything is up-to-date."
def do_run(self, target=None):
try:
self.repo.push(
processed_files_count = self.repo.push(
target=target,
jobs=self.args.jobs,
remote=self.args.remote,
@@ -57,13 +63,17 @@ class CmdDataPush(CmdDataBase):
except Exception:
logger.error("failed to push data to the cloud")
return 1
if processed_files_count == 0:
logger.info(self.UP_TO_DATE_MSG)
return 0
class CmdDataFetch(CmdDataBase):
UP_TO_DATE_MSG = "Everything is up-to-date."
def do_run(self, target=None):
try:
self.repo.fetch(
processed_files_count = self.repo.fetch(
target=target,
jobs=self.args.jobs,
remote=self.args.remote,
@@ -76,6 +86,8 @@ class CmdDataFetch(CmdDataBase):
except Exception:
logger.error("failed to fetch data from the cloud")
return 1
if processed_files_count == 0:
logger.info(self.UP_TO_DATE_MSG)
return 0
+5 -4
View File
@@ -657,8 +657,7 @@ class RemoteLOCAL(RemoteBase):
chunks = self._get_chunks(download, remote, status_info, status, jobs)
if len(chunks) == 0:
print("Everything up-to-date")
return
return 0
futures = []
with ThreadPoolExecutor(max_workers=jobs) as executor:
@@ -669,8 +668,10 @@ class RemoteLOCAL(RemoteBase):
for f in futures:
f.result()
return len(chunks)
def push(self, checksum_infos, remote, jobs=None, show_checksums=False):
self._process(
return self._process(
checksum_infos,
remote,
jobs=jobs,
@@ -679,7 +680,7 @@ class RemoteLOCAL(RemoteBase):
)
def pull(self, checksum_infos, remote, jobs=None, show_checksums=False):
self._process(
return self._process(
checksum_infos,
remote,
jobs=jobs,
+1 -1
View File
@@ -23,6 +23,6 @@ def fetch(
jobs=jobs,
recursive=recursive,
)["local"]
self.cloud.pull(
return self.cloud.pull(
used, jobs, remote=remote, show_checksums=show_checksums
)
+2 -1
View File
@@ -13,7 +13,7 @@ def pull(
force=False,
recursive=False,
):
self.fetch(
processed_files_count = self.fetch(
target,
jobs,
remote=remote,
@@ -26,3 +26,4 @@ def pull(
self.checkout(
target=target, with_deps=with_deps, force=force, recursive=recursive
)
return processed_files_count
+1 -1
View File
@@ -23,6 +23,6 @@ def push(
jobs=jobs,
recursive=recursive,
)["local"]
self.cloud.push(
return self.cloud.push(
used, jobs, remote=remote, show_checksums=show_checksums
)