forked from iterative/dvc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request iterative#356 from efiop/master
Internal and external design changes
- Loading branch information
Showing
45 changed files
with
992 additions
and
1,606 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import os | ||
|
||
|
||
class Cache(object): | ||
CACHE_DIR = 'cache' | ||
|
||
def __init__(self, dvc_dir): | ||
self.cache_dir = os.path.join(dvc_dir, self.CACHE_DIR) | ||
|
||
@staticmethod | ||
def init(dvc_dir): | ||
cache_dir = os.path.join(dvc_dir, Cache.CACHE_DIR) | ||
os.mkdir(cache_dir) | ||
return Cache(dvc_dir) | ||
|
||
def all(self): | ||
clist = [] | ||
for cache in os.listdir(self.cache_dir): | ||
path = os.path.join(self.cache_dir, cache) | ||
if os.path.isfile(path): | ||
clist.append(path) | ||
return clist | ||
|
||
def get(self, md5): | ||
return os.path.join(self.cache_dir, md5) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,8 @@ | ||
import os | ||
|
||
from dvc.command.common.base import CmdBase | ||
from dvc.logger import Logger | ||
from dvc.state_file import StateFile | ||
from dvc.path.data_item import DataItem | ||
|
||
|
||
class CmdAdd(CmdBase): | ||
def __init__(self, settings): | ||
super(CmdAdd, self).__init__(settings) | ||
|
||
def collect_file(self, fname): | ||
return [self.settings.path_factory.data_item(fname)] | ||
|
||
def collect_dir(self, dname): | ||
targets = [] | ||
for root, dirs, files in os.walk(dname): | ||
for fname in files: | ||
targets += self.collect_file(os.path.join(root, fname)) | ||
return targets | ||
|
||
def collect_targets(self, inputs): | ||
targets = [] | ||
for i in inputs: | ||
if not os.path.isdir(i): | ||
targets += self.collect_file(i) | ||
else: | ||
targets += self.collect_dir(i) | ||
return targets | ||
|
||
def add_files(self, targets): | ||
for data_item in targets: | ||
data_item.move_data_to_cache() | ||
|
||
def create_state_files(self, targets): | ||
""" | ||
Create state files for all targets. | ||
""" | ||
for data_item in targets: | ||
Logger.debug('Creating state file for {}'.format(data_item.data.relative)) | ||
|
||
fname = os.path.basename(data_item.data.relative + StateFile.STATE_FILE_SUFFIX) | ||
out = StateFile.parse_deps_state(self.settings, [data_item.data.relative], | ||
currdir=os.path.curdir) | ||
state_file = StateFile(fname=fname, | ||
cmd=None, | ||
out=out, | ||
out_git=[], | ||
deps=[], | ||
locked=True) | ||
state_file.save() | ||
Logger.debug('State file "{}" was created'.format(data_item.state.relative)) | ||
|
||
def run(self): | ||
targets = self.collect_targets(self.parsed_args.input) | ||
self.add_files(targets) | ||
self.create_state_files(targets) | ||
msg = 'DVC add: {}'.format(str(self.parsed_args.input)) | ||
self.commit_if_needed(msg) | ||
for target in self.args.targets: | ||
self.project.add(target) | ||
return 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,7 @@ | ||
import os | ||
|
||
from dvc.command.common.base import CmdBase | ||
from dvc.command.common.cache_dir import CacheDir | ||
from dvc.config import ConfigI | ||
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 | ||
|
||
if not System.samefile(data, cache): | ||
return False | ||
|
||
return True | ||
|
||
@staticmethod | ||
def checkout(items): | ||
for item in items: | ||
if CmdCheckout.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): | ||
self.remove_not_tracked_hardlinks() | ||
items = self.settings.path_factory.all_existing_data_items() | ||
self.checkout(items) | ||
self.project.checkout() | ||
return 0 | ||
|
||
def remove_not_tracked_hardlinks(self): | ||
untracked_files = self.git.all_untracked_files() | ||
|
||
cache_dir = os.path.join(self.git.git_dir_abs, ConfigI.CACHE_DIR) | ||
cached_files = CacheDir(cache_dir).find_caches(untracked_files) | ||
|
||
for file in cached_files: | ||
Logger.info(u'Remove \'{}\''.format(file)) | ||
os.remove(file) | ||
|
||
dir = os.path.dirname(file) | ||
if not os.listdir(dir): | ||
Logger.info(u'Remove empty directory \'{}\''.format(dir)) | ||
os.removedirs(dir) | ||
pass |
Oops, something went wrong.