示例#1
0
文件: url.py 项目: umutbb/hubble
def is_escaped(url):
    '''
    test whether `url` is escaped with `|`
    '''
    scheme = urlparse(url).scheme
    if not scheme:
        return url.startswith('|')
    elif scheme == 'salt':
        path, saltenv = parse(url)
        if hubblestack.utils.platform.is_windows() and '|' in url:
            return path.startswith('_')
        else:
            return path.startswith('|')
    else:
        return False
示例#2
0
    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 ''
示例#3
0
 def _check_proto(self, path):
     '''
     Make sure that this path is intended for the salt master and trim it
     '''
     if not path.startswith('salt://'):
         raise MinionError('Unsupported path: {0}'.format(path))
     file_path, saltenv = hubblestack.utils.url.parse(path)
     return file_path
示例#4
0
文件: url.py 项目: umutbb/hubble
def escape(url):
    '''
    add escape character `|` to `url`
    '''
    if hubblestack.utils.platform.is_windows():
        return url

    scheme = urlparse(url).scheme
    if not scheme:
        if url.startswith('|'):
            return url
        else:
            return '|{0}'.format(url)
    elif scheme == 'salt':
        path, saltenv = parse(url)
        if path.startswith('|'):
            return create(path, saltenv)
        else:
            return create('|{0}'.format(path), saltenv)
    else:
        return url