replace env_splitter construct with urllib utils

This commit is contained in:
Justin Findlay 2015-05-02 04:00:17 -06:00
parent cc8ecee621
commit 1b786d0692
3 changed files with 27 additions and 62 deletions

View file

@ -13,6 +13,7 @@ import fnmatch
import salt.minion
import salt.fileclient
import salt.utils
import salt.utils.url
import salt.crypt
import salt.transport
from salt.exceptions import CommandExecutionError
@ -329,21 +330,11 @@ def cache_file(path, saltenv='base', env=None):
saltenv = env
_mk_client()
if path.startswith('salt://|'):
# Strip pipe. Windows doesn't allow pipes in filenames
path = u'salt://{0}'.format(path[8:])
env_splitter = '?saltenv='
if '?env=' in path:
salt.utils.warn_until(
'Boron',
'Passing a salt environment should be done using \'saltenv\' '
'not \'env\'. This functionality will be removed in Salt Boron.'
)
env_splitter = '?env='
try:
path, saltenv = path.split(env_splitter)
except ValueError:
pass
path, senv = salt.utils.url.split_env(path)
if senv:
saltenv = senv
result = __context__['cp.fileclient'].cache_file(path, saltenv)
if not result:
log.error(

View file

@ -49,6 +49,7 @@ import salt.utils.find
import salt.utils.filebuffer
import salt.utils.files
import salt.utils.atomicfile
import salt.utils.url
from salt.exceptions import CommandExecutionError, SaltInvocationError
log = logging.getLogger(__name__)
@ -3009,30 +3010,16 @@ def source_list(source, source_hash, saltenv):
'''
# get the master file list
if isinstance(source, list):
mfiles = __salt__['cp.list_master'](saltenv)
mdirs = __salt__['cp.list_master_dirs'](saltenv)
mfiles = [(f, saltenv) for f in __salt__['cp.list_master'](saltenv)]
mdirs = [(d, saltenv) for d in __salt__['cp.list_master_dirs'](saltenv)]
for single in source:
if isinstance(single, dict):
single = next(iter(single))
env_splitter = '?saltenv='
if '?env=' in single:
salt.utils.warn_until(
'Boron',
'Passing a salt environment should be done using '
'\'saltenv\' not \'env\'. This functionality will be '
'removed in Salt Boron.'
)
env_splitter = '?env='
try:
_, senv = single.split(env_splitter)
except ValueError:
continue
else:
mfiles += ['{0}?saltenv={1}'.format(f, senv)
for f in __salt__['cp.list_master'](senv)]
mdirs += ['{0}?saltenv={1}'.format(d, senv)
for d in __salt__['cp.list_master_dirs'](senv)]
path, senv = salt.utils.url.parse(single)
if senv:
mfiles += [(f, senv) for f in __salt__['cp.list_master'](senv)]
mdirs += [(d, senv) for d in __salt__['cp.list_master_dirs'](senv)]
ret = None
for single in source:
@ -3045,7 +3032,10 @@ def source_list(source, source_hash, saltenv):
single_hash = single[single_src] if single[single_src] else source_hash
proto = _urlparse(single_src).scheme
if proto == 'salt':
if single_src[7:] in mfiles or single_src[7:] in mdirs:
path, senv = salt.utils.url.parse(single_src)
if not senv:
senv = saltenv
if (path, saltenv) in mfiles or (path, saltenv) in mdirs:
ret = (single_src, single_hash)
break
elif proto.startswith('http') or proto == 'ftp':
@ -3056,7 +3046,10 @@ def source_list(source, source_hash, saltenv):
ret = (single_src, single_hash)
break
elif isinstance(single, six.string_types):
if single[7:] in mfiles or single[7:] in mdirs:
path, senv = salt.utils.url.parse(single)
if not senv:
senv = saltenv
if (path, senv) in mfiles or (path, senv) in mdirs:
ret = (single, source_hash)
break
if ret is None:

View file

@ -83,6 +83,7 @@ import shutil
# Import salt libs
import salt.utils
import salt.utils.url
from salt.ext.six import string_types
from salt.exceptions import CommandExecutionError, CommandNotFoundError
@ -126,36 +127,16 @@ def _get_pip_bin(bin_env):
return bin_env
def _process_salt_url(path, saltenv):
'''
Process 'salt://' and '?saltenv=' out of `path` and return the stripped
path and the saltenv.
'''
path = path.split('salt://', 1)[-1]
env_splitter = '?saltenv='
if '?env=' in path:
salt.utils.warn_until(
'Boron',
'Passing a salt environment should be done using \'saltenv\' '
'not \'env\'. This functionality will be removed in Salt Boron.'
)
env_splitter = '?env='
try:
path, saltenv = path.split(env_splitter)
except ValueError:
pass
return path, saltenv
def _get_cached_requirements(requirements, saltenv):
'''
Get the location of a cached requirements file; caching if necessary.
'''
requirements_file, saltenv = _process_salt_url(requirements, saltenv)
if requirements_file not in __salt__['cp.list_master'](saltenv):
req_file, senv = salt.utils.url.parse(requirements)
if senv:
saltenv = senv
if req_file not in __salt__['cp.list_master'](saltenv):
# Requirements file does not exist in the given saltenv.
return False