Merge pull request #525 from efiop/master

introduce 'dvc fetch' and change 'dvc remove' behavior
This commit is contained in:
Ruslan Kuprieiev
2018-03-08 08:21:18 +02:00
committed by GitHub
4 changed files with 41 additions and 35 deletions
+10 -3
View File
@@ -10,7 +10,7 @@ from dvc.command.init import CmdInit
from dvc.command.remove import CmdRemove
from dvc.command.run import CmdRun
from dvc.command.repro import CmdRepro
from dvc.command.data_sync import CmdDataPush, CmdDataPull, CmdDataStatus
from dvc.command.data_sync import CmdDataPush, CmdDataPull, CmdDataStatus, CmdDataFetch
from dvc.command.gc import CmdGC
from dvc.command.add import CmdAdd
from dvc.command.config import CmdConfig
@@ -161,6 +161,13 @@ def parse_args(argv=None):
help='Push data files to the cloud')
push_parser.set_defaults(func=CmdDataPush)
#Fetch
fetch_parser = cache_subparsers.add_parser(
'fetch',
parents=[parent_cache_parser],
help='Fetch data files from the cloud')
fetch_parser.set_defaults(func=CmdDataFetch)
# Status
status_parser = cache_subparsers.add_parser(
'status',
@@ -194,10 +201,10 @@ def parse_args(argv=None):
remove_parser = subparsers.add_parser(
'remove',
parents=[parent_parser],
help='Remove data file or data directory')
help='Remove outputs of DVC file.')
remove_parser.add_argument('targets',
nargs='+',
help='Target to remove - file or directory.')
help='DVC files.')
remove_parser.set_defaults(func=CmdRemove)
# Garbage collector
+10
View File
@@ -40,6 +40,16 @@ class CmdDataPush(CmdDataBase):
return 0
class CmdDataFetch(CmdDataBase):
def do_run(self, target=None):
try:
self.project.fetch(target=target, jobs=self.args.jobs)
except DvcException as exc:
self.project.logger.error('Failed to fetch data from the cloud', exc)
return 1
return 0
class CmdDataStatus(CmdDataBase):
def _show(self, status):
for s in status:
+11 -14
View File
@@ -91,21 +91,15 @@ class Project(object):
stage.dump()
return stage
def remove(self, fname):
stages = []
output = Output.loads(self, fname)
for out in self.outs():
if out.path == output.path:
stage = out.stage()
stages.append(stage)
def remove(self, target):
if not Stage.is_stage_file(target):
raise StageNotFoundError(target)
if len(stages) == 0:
raise StageNotFoundError(fname)
stage = Stage.load(self, target)
for out in stage.outs:
out.remove()
for stage in stages:
stage.remove()
return stages
return stage
def run(self,
cmd=None,
@@ -207,8 +201,11 @@ class Project(object):
def push(self, target=None, jobs=1):
return self.cloud.push(self._used_cache(target), jobs)
def fetch(self, target=None, jobs=1):
return self.cloud.pull(self._used_cache(target), jobs)
def pull(self, target=None, jobs=1):
ret = self.cloud.pull(self._used_cache(target), jobs)
ret = self.fetch(target, jobs)
self.checkout()
return ret
+10 -18
View File
@@ -12,43 +12,35 @@ from tests.basic_env import TestDvc
class TestRemove(TestDvc):
def test(self):
stage = self.dvc.add(self.FOO)
stages_removed = self.dvc.remove(self.FOO)
stage_removed = self.dvc.remove(stage.path)
self.assertEqual(len(stages_removed), 1)
self.assertIsInstance(stages_removed[0], Stage)
self.assertEqual(stage.path, stages_removed[0].path)
self.assertIsInstance(stage_removed, Stage)
self.assertEqual(stage.path, stage_removed.path)
self.assertFalse(os.path.isfile(self.FOO))
class TestRemoveNonExistentFile(TestDvc):
def test(self):
with self.assertRaises(StageNotFoundError) as cx:
self.dvc.remove('non_existent_file')
class TestRemoveFileOutsideOfRepo(TestDvc):
def test(self):
with self.assertRaises(CmdOutputOutsideOfRepoError) as cx:
self.dvc.remove(os.path.join(os.path.dirname(self.dvc.root_dir), self.FOO))
self.dvc.remove('non_existent_dvc_file')
class TestRemoveDirectory(TestDvc):
def test(self):
stage_add = self.dvc.add(self.DATA_DIR)
stages_removed = self.dvc.remove(self.DATA_DIR)
self.assertEqual(len(stages_removed), 1)
stage_removed = stages_removed[0]
stage_removed = self.dvc.remove(stage_add.path)
self.assertEqual(stage_add.path, stage_removed.path)
self.assertFalse(os.path.exists(self.DATA_DIR))
self.assertFalse(os.path.exists(stage_removed.path))
self.assertTrue(os.path.exists(stage_removed.path))
class TestCmdRemove(TestDvc):
def test(self):
self.dvc.add(self.FOO)
stage = self.dvc.add(self.FOO)
ret = main(['remove',
self.FOO])
stage.path])
self.assertEqual(ret, 0)
ret = main(['remove',
'non-existing-file'])
'non-existing-dvc-file'])
self.assertNotEqual(ret, 0)