Skip to content

Instantly share code, notes, and snippets.

@shcheklein
Last active May 9, 2019 22:43
Show Gist options
  • Save shcheklein/d37325461be9509fb46f5600997502a9 to your computer and use it in GitHub Desktop.
Save shcheklein/d37325461be9509fb46f5600997502a9 to your computer and use it in GitHub Desktop.
DVC Main by Ruslan
"DVC CORE CONTRIBUTOR"
import os
from stat import ST_INO, ST_DEV
from dvc.command.base import CmdBase, DvcLock
from dvc.logger import Logger
from dvc.system import System
class CmdCheckout(CmdBase):
def __init__(self, settings):
super(CmdCheckout, self).__init__(settings)
@staticmethod
def cache_ok(item):
data = item.data.relative
cache = item.cache.relative
if not os.path.isfile(data) or not os.path.isfile(cache):
return False
data_st = os.stat(data)
cache_st = os.stat(cache)
if (data_st[ST_INO], data_st[ST_DEV]) != (cache_st[ST_INO], cache_st[ST_DEV]):
return False
return True
def checkout(self, items):
for item in items:
if self.cache_ok(item):
continue
if os.path.isfile(item.data.relative):
os.remove(item.data.relative)
System.hardlink(item.cache.relative, item.data.relative)
Logger.info('Checkout \'{}\''.format(item.data.relative))
def run(self):
with DvcLock(self.is_locker, self.git):
items = self.settings.path_factory.all_existing_data_items()
self.checkout(items)
return 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment