From 216897494c5b673036b119793c8567920a0aaea9 Mon Sep 17 00:00:00 2001 From: Ruslan Kuprieiev Date: Wed, 27 Jun 2018 22:25:18 +0300 Subject: [PATCH] config: allow specifying a list of cache types Fixes #709 Signed-off-by: Ruslan Kuprieiev --- dvc/config.py | 11 ++++++++++- dvc/remote/local.py | 15 +++++++++++---- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/dvc/config.py b/dvc/config.py index eb0d5dbeb..148c75e13 100644 --- a/dvc/config.py +++ b/dvc/config.py @@ -19,6 +19,15 @@ def supported_url(url): return supported(url) +def supported_cache_type(types): + if isinstance(types, str): + types = [t.strip() for t in types.split(',')] + for t in types: + if t not in ['reflink', 'hardlink', 'symlink', 'copy']: + return False + return True + + class Config(object): CONFIG = 'config' CONFIG_LOCAL = 'config.local' @@ -31,7 +40,7 @@ class Config(object): SECTION_CACHE = 'cache' SECTION_CACHE_DIR = 'dir' SECTION_CACHE_TYPE = 'type' - SECTION_CACHE_TYPE_SCHEMA = schema.And(schema.Use(str.lower), lambda t: t in ('reflink', 'hardlink', 'symlink', 'copy')) + SECTION_CACHE_TYPE_SCHEMA = supported_cache_type SECTION_CACHE_LOCAL = 'local' SECTION_CACHE_S3 = 's3' SECTION_CACHE_GS = 'gs' diff --git a/dvc/remote/local.py b/dvc/remote/local.py index 0dd8e9ac6..473e6691f 100644 --- a/dvc/remote/local.py +++ b/dvc/remote/local.py @@ -10,6 +10,7 @@ from dvc.state import State from dvc.logger import Logger from dvc.utils import remove, move, copyfile, file_md5 from dvc.config import Config +from dvc.exceptions import DvcException class RemoteLOCAL(RemoteBase): @@ -30,7 +31,14 @@ class RemoteLOCAL(RemoteBase): self.link_state = project.link_state storagepath = config.get(Config.SECTION_AWS_STORAGEPATH, None) self.cache_dir = config.get(Config.SECTION_REMOTE_URL, storagepath) - self.cache_type = config.get(Config.SECTION_CACHE_TYPE, None) + + types = config.get(Config.SECTION_CACHE_TYPE, None) + if types: + if isinstance(types, str): + types = [t.strip() for t in types.split(',')] + self.cache_types = types + else: + self.cache_types = self.CACHE_TYPES if self.cache_dir != None and not os.path.exists(self.cache_dir): os.mkdir(self.cache_dir) @@ -79,8 +87,8 @@ class RemoteLOCAL(RemoteBase): if not os.path.exists(dname): os.makedirs(dname) - if self.cache_type != None: - types = [self.cache_type] + if self.cache_types != None: + types = self.cache_types else: types = self.CACHE_TYPES @@ -95,7 +103,6 @@ class RemoteLOCAL(RemoteBase): msg = 'Cache type \'{}\' is not supported'.format(typ) Logger.debug(msg) if typ == types[-1]: - raise raise DvcException(msg, cause=exc) @staticmethod