def _make_remote_property(name): """ The config file is stored in a way that allows you to have a cache for each remote. This is needed when specifying external outputs (as they require you to have an external cache location). Imagine a config file like the following: ['remote "dvc-storage"'] url = ssh://localhost/tmp ask_password = true [cache] ssh = dvc-storage This method creates a cached property, containing cache named `name`: self.config == {'ssh': 'dvc-storage'} self.ssh # a RemoteSSH instance """ def getter(self): from dvc.remote import Remote remote = self.config.get(name) if not remote: return None return Remote(self.repo, name=remote) getter.__name__ = builtin_str(name) return cached_property(getter)
class Resource(dict): """A resource value""" def __init__(self, data): dict.__init__(self, data) assert {'bucket', 'key', 'name', 'size'} <= set(self) @property def url(self): return "http://{bucket}.s3.amazonaws.com/{key}".format(**self) @property def human_size(self): if self['size'] == 0: return '0b' i = int(math.log(self['size'], 1024)) return '%d%s' % (math.ceil( self['size'] / 1024**i), ['b', 'kb', 'mb', 'gb', 'tb'][i]) @cached_property def frame(self): return ops.frame_loads(self._raw()) def _raw(self): blob = ops.download_as_string(self['bucket'], self['key']) if self.get('compressed') in {True, 'zlib'}: blob = zlib.decompress(blob) elif self.get('compressed') == 'gzip': blob = gzip_decompress(blob) return blob raw = cached_property(_raw) def open(self): return BytesIO(self.raw)