mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-10 15:28:34 +01:00
92 lines
2.6 KiB
Python
92 lines
2.6 KiB
Python
"""Manages cache of a dvc project."""
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
import os
|
|
|
|
from dvc.config import Config
|
|
|
|
|
|
class Cache(object):
|
|
"""Class that manages cache locations of a dvc project.
|
|
|
|
Args:
|
|
project (dvc.project.Project): project instance that this cache
|
|
belongs to.
|
|
"""
|
|
CACHE_DIR = 'cache'
|
|
|
|
def __init__(self, project):
|
|
from dvc.remote import Remote
|
|
|
|
self.project = project
|
|
|
|
config = project.config.config[Config.SECTION_CACHE]
|
|
local = config.get(Config.SECTION_CACHE_LOCAL)
|
|
|
|
if local:
|
|
name = Config.SECTION_REMOTE_FMT.format(local)
|
|
sect = project.config.config[name]
|
|
else:
|
|
default_cache_dir = os.path.join(project.dvc_dir, self.CACHE_DIR)
|
|
cache_dir = config.get(Config.SECTION_CACHE_DIR, default_cache_dir)
|
|
cache_type = config.get(Config.SECTION_CACHE_TYPE)
|
|
protected = config.get(Config.SECTION_CACHE_PROTECTED)
|
|
|
|
sect = {
|
|
Config.PRIVATE_CWD: config.get(Config.PRIVATE_CWD,
|
|
project.dvc_dir),
|
|
Config.SECTION_REMOTE_URL: cache_dir,
|
|
Config.SECTION_CACHE_TYPE: cache_type,
|
|
Config.SECTION_CACHE_PROTECTED: protected
|
|
}
|
|
|
|
self._local = Remote(project, sect)
|
|
|
|
self._s3 = self._get_remote(config, Config.SECTION_CACHE_S3)
|
|
self._gs = self._get_remote(config, Config.SECTION_CACHE_GS)
|
|
self._ssh = self._get_remote(config, Config.SECTION_CACHE_SSH)
|
|
self._hdfs = self._get_remote(config, Config.SECTION_CACHE_HDFS)
|
|
self._azure = self._get_remote(config, Config.SECTION_CACHE_AZURE)
|
|
|
|
@property
|
|
def local(self):
|
|
"""Remote instance for local cache."""
|
|
return self._local
|
|
|
|
@property
|
|
def s3(self):
|
|
"""Remote instance for AWS S3 cache."""
|
|
return self._s3
|
|
|
|
@property
|
|
def gs(self):
|
|
"""Remote instance for Google Cloud Storage cache."""
|
|
return self._gs
|
|
|
|
@property
|
|
def ssh(self):
|
|
"""Remote instance for SSH cache."""
|
|
return self._ssh
|
|
|
|
@property
|
|
def hdfs(self):
|
|
"""Remote instance for HDFS cache."""
|
|
return self._hdfs
|
|
|
|
@property
|
|
def azure(self):
|
|
"""Remote instance for azure cache."""
|
|
return self._azure
|
|
|
|
def _get_remote(self, config, name):
|
|
from dvc.remote import Remote
|
|
|
|
remote = config.get(name, None)
|
|
if not remote:
|
|
return None
|
|
|
|
name = Config.SECTION_REMOTE_FMT.format(remote)
|
|
sect = self.project.config.config[name]
|
|
return Remote(self.project, sect)
|