rename/refactor to avoid shadowing version() functions

This commit is contained in:
Chris Rebert 2013-05-16 18:36:16 -07:00
parent 6122b8a2b5
commit 4dafa17dde
11 changed files with 79 additions and 80 deletions

View File

@ -319,11 +319,11 @@ def install(name=None,
# comma-separated list
pkg_params = {name: kwargs.get('version')}
targets = []
for param, version in pkg_params.iteritems():
if version is None:
for param, version_num in pkg_params.iteritems():
if version_num is None:
targets.append(param)
else:
targets.append('"{0}={1}"'.format(param, version))
targets.append('"{0}={1}"'.format(param, version_num))
if fromrepo:
log.info('Targeting repo "{0}"'.format(fromrepo))
cmd = 'apt-get -q -y {confold} {confdef} {verify} {target} install ' \
@ -478,13 +478,13 @@ def list_pkgs(versions_as_list=False):
for line in out.splitlines():
cols = line.split()
try:
linetype, status, name, version = [cols[x] for x in (0, 2, 3, 4)]
linetype, status, name, version_num = [cols[x] for x in (0, 2, 3, 4)]
except ValueError:
continue
name = _pkgname_without_arch(name)
if len(cols) and ('install' in linetype or 'hold' in linetype) and \
'installed' in status:
__salt__['pkg_resource.add_pkg'](ret, name, version)
__salt__['pkg_resource.add_pkg'](ret, name, version_num)
# Check for virtual packages. We need dctrl-tools for this.
if __salt__['cmd.has_exec']('grep-available'):
@ -533,8 +533,8 @@ def _get_upgradable():
ret = {}
for line in upgrades:
name = _get(line, 'name')
version = _get(line, 'version')
ret[name] = version
version_num = _get(line, 'version')
ret[name] = version_num
return ret

View File

@ -71,10 +71,10 @@ def list_pkgs(versions_as_list=False):
cmd = 'brew list --versions'
for line in __salt__['cmd.run'](cmd).splitlines():
try:
name, version = line.split(' ')[0:2]
name, version_num = line.split(' ')[0:2]
except ValueError:
continue
__salt__['pkg_resource.add_pkg'](ret, name, version)
__salt__['pkg_resource.add_pkg'](ret, name, version_num)
__salt__['pkg_resource.sort_pkglist'](ret)
__context__['pkg.list_pkgs'] = ret

View File

@ -46,9 +46,9 @@ def fullversion():
cmd = 'dnsmasq -v'
out = __salt__['cmd.run'](cmd).splitlines()
comps = out[0].split()
version = comps[2]
version_num = comps[2]
comps = out[1].split()
return {'version': version,
return {'version': version_num,
'compile options': comps[3:]}

View File

@ -122,8 +122,8 @@ def _get_upgradable():
ret = {}
for line in upgrades:
name = _get(line, 'name')
version = _get(line, 'version')
ret[name] = version
version_num = _get(line, 'version')
ret[name] = version_num
return ret
@ -304,9 +304,9 @@ def install(name=None,
# Handle version kwarg for a single package target
if pkgs is None and sources is None:
version = kwargs.get('version')
if version:
pkg_params = {name: version}
version_num = kwargs.get('version')
if version_num:
pkg_params = {name: version_num}
elif slot is not None:
pkg_params = {name: ':{0}'.format(slot)}
@ -319,14 +319,14 @@ def install(name=None,
if pkg_type == 'repository':
targets = list()
for param, version in pkg_params.iteritems():
if version is None:
for param, version_num in pkg_params.iteritems():
if version_num is None:
targets.append(param)
elif version.startswith(':'):
elif version_num.startswith(':'):
# Really this 'version' is a slot
targets.append('{0}{1}'.format(param, version))
targets.append('{0}{1}'.format(param, version_num))
else:
match = re.match('^([<>])?(=)?([^<>=]+)$', version)
match = re.match('^([<>])?(=)?([^<>=]+)$', version_num)
if match:
gt_lt, eq, verstr = match.groups()
prefix = gt_lt or ''

View File

@ -53,12 +53,12 @@ def latest_version(*names, **kwargs):
'{0}'.format(' '.join(names))
for line in __salt__['cmd.run_stdout'](cmd).splitlines():
try:
name, version = line.split()
name, version_num = line.split()
# Only add to return dict if package is in the list of packages
# passed, otherwise dependencies will make their way into the
# return data.
if name in names:
ret[name] = version
ret[name] = version_num
except (ValueError, IndexError):
pass
@ -143,12 +143,12 @@ def list_pkgs(versions_as_list=False):
if not line:
continue
try:
name, version = line.split()[0:2]
name, version_num = line.split()[0:2]
except ValueError:
log.error('Problem parsing pacman -Q: Unexpected formatting in '
'line: "{0}"'.format(line))
else:
__salt__['pkg_resource.add_pkg'](ret, name, version)
__salt__['pkg_resource.add_pkg'](ret, name, version_num)
__salt__['pkg_resource.sort_pkglist'](ret)
__context__['pkg.list_pkgs'] = ret
@ -240,11 +240,11 @@ def install(name=None,
if pkg_params is None or len(pkg_params) == 0:
return {}
version = kwargs.get('version')
if version:
version_num = kwargs.get('version')
if version_num:
if pkgs is None and sources is None:
# Allow "version" to work for single package target
pkg_params = {name: version}
pkg_params = {name: version_num}
else:
log.warning('"version" parameter will be ignored for multiple '
'package targets')
@ -256,11 +256,11 @@ def install(name=None,
elif pkg_type == 'repository':
targets = []
problems = []
for param, version in pkg_params.iteritems():
if version is None:
for param, version_num in pkg_params.iteritems():
if version_num is None:
targets.append(param)
else:
match = re.match('^([<>])?(=)?([^<>=]+)$', version)
match = re.match('^([<>])?(=)?([^<>=]+)$', version_num)
if match:
gt_lt, eq, verstr = match.groups()
prefix = gt_lt or ''
@ -270,7 +270,7 @@ def install(name=None,
targets.append('{0}{1}{2}'.format(param, prefix, verstr))
else:
msg = 'Invalid version string "{0}" for package ' \
'"{1}"'.format(version, name)
'"{1}"'.format(version_num, name)
problems.append(msg)
if problems:
for problem in problems:

View File

@ -37,17 +37,17 @@ def upgrade_available(name):
salt '*' pkgutil.upgrade_available CSWpython
'''
version = None
version_num = None
cmd = '/opt/csw/bin/pkgutil -c --parse --single {0} 2>/dev/null'.format(
name)
out = __salt__['cmd.run_stdout'](cmd)
if out:
version = out.split()[2].strip()
if version:
if version == "SAME":
version_num = out.split()[2].strip()
if version_num:
if version_num == "SAME":
return ''
else:
return version
return version_num
return ''
@ -133,8 +133,8 @@ def list_pkgs(versions_as_list=False):
if index % 2 == 0:
name = lines[index].split()[0].strip()
if index % 2 == 1:
version = lines[index].split()[1].strip()
__salt__['pkg_resource.add_pkg'](ret, name, version)
version_num = lines[index].split()[1].strip()
__salt__['pkg_resource.add_pkg'](ret, name, version_num)
__salt__['pkg_resource.sort_pkglist'](ret)
__context__['pkg.list_pkgs'] = ret

View File

@ -92,8 +92,8 @@ def list_pkgs(versions_as_list=False):
if index % 2 == 0:
name = lines[index].split()[0].strip()
if index % 2 == 1:
version = lines[index].split()[1].strip()
__salt__['pkg_resource.add_pkg'](ret, name, version)
version_num = lines[index].split()[1].strip()
__salt__['pkg_resource.add_pkg'](ret, name, version_num)
__salt__['pkg_resource.sort_pkglist'](ret)
__context__['pkg.list_pkgs'] = ret

View File

@ -450,8 +450,8 @@ def lucene_version(core_name=None):
for name in __salt__['config.option']('solr.cores'):
resp = _get_admin_info('system', core_name=name)
if resp['success']:
version = resp['data']['lucene']['lucene-spec-version']
data = {name: {'lucene_version': version}}
version_num = resp['data']['lucene']['lucene-spec-version']
data = {name: {'lucene_version': version_num}}
else: # generally this means that an exception happened.
data = {name: {'lucene_version': None}}
success = False
@ -460,8 +460,8 @@ def lucene_version(core_name=None):
else:
resp = _get_admin_info('system', core_name=core_name)
if resp['success']:
version = resp['data']['lucene']['lucene-spec-version']
return _get_return_dict(True, {'version': version}, resp['errors'])
version_num = resp['data']['lucene']['lucene-spec-version']
return _get_return_dict(True, {'version': version_num}, resp['errors'])
else:
return resp
@ -502,8 +502,8 @@ def version(core_name=None):
else:
resp = _get_admin_info('system', core_name=core_name)
if resp['success']:
version = resp['data']['lucene']['solr-spec-version']
return _get_return_dict(True, {'version': version},
version_num = resp['data']['lucene']['solr-spec-version']
return _get_return_dict(True, {'version': version_num},
resp['errors'], resp['warnings'])
else:
return resp

View File

@ -60,7 +60,7 @@ def latest_version(*names, **kwargs):
pkgs = list_pkgs()
for name in names:
candidate = '0'
version = '0'
version_num = '0'
pkginfo = _get_package_info(name)
if not pkginfo:
# pkg not available in repo, skip
@ -70,9 +70,9 @@ def latest_version(*names, **kwargs):
name = pkginfo[candidate]['full_name']
ret[name] = ''
if name in pkgs:
version = pkgs[name]
version_num = pkgs[name]
if __salt__['pkg_resource.perform_cmp'](str(candidate),
str(version)) > 0:
str(version_num)) > 0:
ret[name] = candidate
continue
for ver in pkginfo.keys():
@ -81,9 +81,9 @@ def latest_version(*names, **kwargs):
name = pkginfo[candidate]['full_name']
ret[name] = ''
if name in pkgs:
version = pkgs[name]
version_num = pkgs[name]
if __salt__['pkg_resource.perform_cmp'](str(candidate),
str(version)) > 0:
str(version_num)) > 0:
ret[name] = candidate
return ret
@ -157,7 +157,7 @@ def version(*names, **kwargs):
if len(names) == 1:
versions = _get_package_info(names[0])
if versions:
for version, val in versions.iteritems():
for val in versions.itervalues():
if 'full_name' in val and len(val.get('full_name', '')) > 0:
win_names.append(val.get('full_name', ''))
nums = __salt__['pkg_resource.version'](*win_names, **kwargs)
@ -172,7 +172,7 @@ def version(*names, **kwargs):
ret[name] = ''
versions = _get_package_info(name)
if versions:
for version, val in versions.iteritems():
for val in versions.itervalues():
if 'full_name' in val and len(val.get('full_name', '')) > 0:
reverse_dict[val.get('full_name', '')] = name
win_names.append(val.get('full_name', ''))
@ -424,20 +424,21 @@ def install(name=None, refresh=False, **kwargs):
if pkginfo[pkg]['full_name'] in old:
return '{0} already installed'.format(pkginfo[pkg]['full_name'])
if kwargs.get('version') is not None:
version = kwargs['version']
version_num = kwargs['version']
else:
version = _get_latest_pkg_version(pkginfo)
if pkginfo[version]['installer'].startswith('salt:') or pkginfo[version]['installer'].startswith('http:') or pkginfo[version]['installer'].startswith('https:') or pkginfo[version]['installer'].startswith('ftp:'):
cached_pkg = __salt__['cp.is_cached'](pkginfo[version]['installer'])
version_num = _get_latest_pkg_version(pkginfo)
installer = pkginfo[version_num]['installer']
if installer.startswith('salt:') or installer.startswith('http:') or installer.startswith('https:') or installer.startswith('ftp:'):
cached_pkg = __salt__['cp.is_cached'](installer)
if not cached_pkg:
# It's not cached. Cache it, mate.
cached_pkg = \
__salt__['cp.cache_file'](pkginfo[version]['installer'])
__salt__['cp.cache_file'](installer)
else:
cached_pkg = pkginfo[version]['installer']
cached_pkg = installer
cached_pkg = cached_pkg.replace('/', '\\')
cmd = '"' + str(cached_pkg) + '"' + str(pkginfo[version]['install_flags'])
if pkginfo[version].get('msiexec'):
cmd = '"' + str(cached_pkg) + '"' + str(pkginfo[version_num]['install_flags'])
if pkginfo[version_num].get('msiexec'):
cmd = 'msiexec /i ' + cmd
__salt__['cmd.run_all'](cmd)
__context__.pop('pkg.list_pkgs', None)

View File

@ -182,7 +182,7 @@ def list_pkgs(versions_as_list=False):
'%{ARCH}\n"'
for line in __salt__['cmd.run'](cmd).splitlines():
try:
name, version, rel, arch = line.split('_|-')
name, pkgver, rel, arch = line.split('_|-')
# Handle unpack errors (should never happen with the queryformat we are
# using, but can't hurt to be careful).
except ValueError:
@ -190,7 +190,6 @@ def list_pkgs(versions_as_list=False):
# Support 32-bit packages on x86_64 systems
if __grains__.get('cpuarch', '') == 'x86_64' and arch == 'i686':
name += '.i686'
pkgver = version
if rel:
pkgver += '-{0}'.format(rel)
__salt__['pkg_resource.add_pkg'](ret, name, pkgver)
@ -315,11 +314,11 @@ def install(name=None,
if pkg_params is None or len(pkg_params) == 0:
return {}
version = kwargs.get('version')
if version:
version_num = kwargs.get('version')
if version_num:
if pkgs is None and sources is None:
# Allow "version" to work for single package target
pkg_params = {name: version}
pkg_params = {name: version_num}
else:
log.warning('"version" parameter will be ignored for multiple '
'package targets')
@ -330,8 +329,8 @@ def install(name=None,
downgrade = []
if pkg_type == 'repository':
targets = []
for pkgname, version in pkg_params.iteritems():
if version is None:
for pkgname, version_num in pkg_params.iteritems():
if version_num is None:
targets.append(pkgname)
else:
cver = old.get(pkgname, '')
@ -342,8 +341,8 @@ def install(name=None,
arch = '.i686'
else:
arch = ''
pkgstr = '"{0}-{1}{2}"'.format(pkgname, version, arch)
if not cver or __salt__['pkg.compare'](pkg1=version,
pkgstr = '"{0}-{1}{2}"'.format(pkgname, version_num, arch)
if not cver or __salt__['pkg.compare'](pkg1=version_num,
oper='>=',
pkg2=cver):
targets.append(pkgstr)

View File

@ -133,8 +133,7 @@ def list_pkgs(versions_as_list=False):
cmd = 'rpm -qa --queryformat "%{NAME}_|-%{VERSION}_|-%{RELEASE}\n"'
ret = {}
for line in __salt__['cmd.run'](cmd).splitlines():
name, version, rel = line.split('_|-')
pkgver = version
name, pkgver, rel = line.split('_|-')
if rel:
pkgver += '-{0}'.format(rel)
__salt__['pkg_resource.add_pkg'](ret, name, pkgver)
@ -238,11 +237,11 @@ def install(name=None,
if pkg_params is None or len(pkg_params) == 0:
return {}
version = kwargs.get('version')
if version:
version_num = kwargs.get('version')
if version_num:
if pkgs is None and sources is None:
# Allow "version" to work for single package target
pkg_params = {name: version}
pkg_params = {name: version_num}
else:
log.warning('"version" parameter will be ignored for multiple '
'package targets')
@ -250,11 +249,11 @@ def install(name=None,
if pkg_type == 'repository':
targets = []
problems = []
for param, version in pkg_params.iteritems():
if version is None:
for param, version_num in pkg_params.iteritems():
if version_num is None:
targets.append(param)
else:
match = re.match('^([<>])?(=)?([^<>=]+)$', version)
match = re.match('^([<>])?(=)?([^<>=]+)$', version_num)
if match:
gt_lt, eq, verstr = match.groups()
prefix = gt_lt or ''
@ -265,7 +264,7 @@ def install(name=None,
log.debug(targets)
else:
msg = 'Invalid version string "{0}" for package ' \
'"{1}"'.format(version, name)
'"{1}"'.format(version_num, name)
problems.append(msg)
if problems:
for problem in problems: