1from __future__ import unicode_literals 2 3import dvc.logger as logger 4from dvc.exceptions import DvcException 5 6 7def _cleanup_unused_links(self, all_stages): 8 used = [] 9 for stage in all_stages: 10 for out in stage.outs: 11 used.append(out.path) 12 self.state.remove_unused_links(used) 13 14 15def checkout(self, target=None, with_deps=False, force=False, recursive=False): 16 from dvc.stage import StageFileDoesNotExistError, StageFileBadNameError 17 18 if target and not recursive: 19 all_stages = self.active_stages() 20 try: 21 stages = self.collect(target, with_deps=with_deps) 22 except (StageFileDoesNotExistError, StageFileBadNameError) as exc: 23 raise DvcException( 24 str(exc) + " Did you mean 'git checkout {}'?".format(target) 25 ) 26 else: 27 all_stages = self.active_stages(target) 28 stages = all_stages 29 30 with self.state: 31 _cleanup_unused_links(self, all_stages) 32 33 for stage in stages: 34 if stage.locked: 35 logger.warning( 36 "DVC file '{path}' is locked. Its dependencies are" 37 " not going to be checked out.".format(path=stage.relpath) 38 ) 39 40 stage.checkout(force=force) 41