Merge pull request #818 from efiop/master

config: allow specifying a list of cache types
This commit is contained in:
Ruslan Kuprieiev
2018-06-27 22:34:29 +03:00
committed by GitHub
2 changed files with 21 additions and 5 deletions
+10 -1
View File
@@ -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'
+11 -4
View File
@@ -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