mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-04 07:18:27 +01:00
dvc: checkout single file
Fixes #666 Signed-off-by: Ruslan Kuprieiev <[email protected]>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
@@ -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):
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user