dvc: checkout single file

Fixes #666

Signed-off-by: Ruslan Kuprieiev <[email protected]>
This commit is contained in:
Ruslan Kuprieiev
2018-04-24 13:45:30 +03:00
parent d9d7692e8d
commit 52c08b2926
4 changed files with 27 additions and 8 deletions
+4
View File
@@ -91,6 +91,10 @@ def parse_args(argv=None):
'checkout',
parents=[parent_parser],
help='Checkout data files from cache')
checkout_parser.add_argument(
'targets',
nargs='*',
help='DVC files')
checkout_parser.set_defaults(func=CmdCheckout)
# Run
+5 -5
View File
@@ -1,12 +1,12 @@
import os
import stat
from dvc.system import System
from dvc.command.common.base import CmdBase
from dvc.logger import Logger
class CmdCheckout(CmdBase):
def run(self):
self.project.checkout()
if not self.args.targets:
self.project.checkout()
else:
for target in self.args.targets:
self.project.checkout(target=target)
return 0
+10 -2
View File
@@ -185,9 +185,17 @@ class Project(object):
Logger.info(u'Remove empty directory \'{}\''.format(dir))
os.removedirs(dir)
def checkout(self):
def checkout(self, target=None):
self._remove_untracked_hardlinks()
for stage in self.stages():
if target:
if not Stage.is_stage_file(target):
raise StageNotFoundError(target)
stages = [Stage.load(self, target)]
else:
stages = self.stages()
for stage in stages:
stage.checkout()
def _used_cache(self, target=None):
+8 -1
View File
@@ -16,7 +16,7 @@ class TestCheckout(TestRepro):
def setUp(self):
super(TestCheckout, self).setUp()
self.dvc.add(self.DATA_DIR)
self.data_dir_stage = self.dvc.add(self.DATA_DIR)
self.orig = 'orig'
shutil.copy(self.FOO, self.orig)
@@ -35,6 +35,13 @@ class TestCheckout(TestRepro):
self.assertTrue(filecmp.cmp(self.FOO, self.orig))
class TestCheckoutSingleStage(TestCheckout):
def test(self):
self.dvc.checkout(self.foo_stage.path)
self.dvc.checkout(self.data_dir_stage.path)
self._test_checkout()
class TestCheckoutCorruptedCacheFile(TestRepro):
def test(self):
cache = self.foo_stage.outs[0].cache