def is_cached(self, path, saltenv='base', cachedir=None): ''' Returns the full path to a file if it is cached locally on the minion otherwise returns a blank string ''' if path.startswith('salt://'): path, senv = hubblestack.utils.url.parse(path) if senv: saltenv = senv escaped = True if hubblestack.utils.url.is_escaped(path) else False # also strip escape character '|' localsfilesdest = os.path.join(self.opts['cachedir'], 'localfiles', path.lstrip('|/')) filesdest = os.path.join(self.opts['cachedir'], 'files', saltenv, path.lstrip('|/')) extrndest = self._extrn_path(path, saltenv, cachedir=cachedir) if os.path.exists(filesdest): return hubblestack.utils.url.escape( filesdest) if escaped else filesdest elif os.path.exists(localsfilesdest): return hubblestack.utils.url.escape(localsfilesdest) \ if escaped \ else localsfilesdest elif os.path.exists(extrndest): return extrndest return ''
def unescape(url): ''' remove escape character `|` from `url` ''' scheme = urlparse(url).scheme if not scheme: return url.lstrip('|') elif scheme == 'salt': path, saltenv = parse(url) if hubblestack.utils.platform.is_windows() and '|' in url: return create(path.lstrip('_'), saltenv) else: return create(path.lstrip('|'), saltenv) else: return url
def cache_local_file(self, path, **kwargs): ''' Cache a local file on the minion in the localfiles cache ''' dest = os.path.join(self.opts['cachedir'], 'localfiles', path.lstrip('/')) destdir = os.path.dirname(dest) if not os.path.isdir(destdir): os.makedirs(destdir) shutil.copyfile(path, dest) return dest