mirror of
https://github.com/valitydev/salt-common.git
synced 2024-11-07 02:45:21 +00:00
215 lines
8.5 KiB
Diff
215 lines
8.5 KiB
Diff
--- /usr/lib/python2.7/site-packages/salt/modules/ebuild.py 2016-07-25 23:06:40.000000000 +0300
|
|
+++ ebuild.py 2016-08-18 21:31:22.009611949 +0300
|
|
@@ -347,7 +347,21 @@
|
|
salt '*' pkg.version <package name>
|
|
salt '*' pkg.version <package1> <package2> <package3> ...
|
|
'''
|
|
- return __salt__['pkg_resource.version'](*names, **kwargs)
|
|
+ if len(names) == 0:
|
|
+ return ''
|
|
+
|
|
+ ret = {}
|
|
+ # Initialize the dict with empty strings
|
|
+ for name in names:
|
|
+ ret[name] = ''
|
|
+ installed = _cpv_to_version(_vartree().dep_bestmatch(name))
|
|
+ if installed:
|
|
+ ret[name] = installed
|
|
+
|
|
+ # Return a string if only one package name passed
|
|
+ if len(names) == 1:
|
|
+ return ret[names[0]]
|
|
+ return ret
|
|
|
|
|
|
def porttree_matches(name):
|
|
@@ -454,6 +468,61 @@
|
|
return True if conf_flags else False
|
|
|
|
|
|
+def process_target(param, version_num):
|
|
+ match = re.match('^(~|-|\*)?([<>])?(=)?([^<>=]*)$', version_num)
|
|
+ if match:
|
|
+ keyword, gt_lt, eq, verstr = match.groups()
|
|
+ prefix = gt_lt or ''
|
|
+ prefix += eq or ''
|
|
+ # We need to delete quotes around use flag list elements
|
|
+ verstr = verstr.replace("'", "")
|
|
+ # If no prefix characters were supplied and verstr contains a version, use '='
|
|
+ if len(verstr) > 0 and verstr[0] != ':' and verstr[0] != '[':
|
|
+ prefix = prefix or '='
|
|
+ target = '"{0}{1}-{2}"'.format(prefix, param, verstr)
|
|
+ else:
|
|
+ target = '"{0}{1}"'.format(param, verstr)
|
|
+ else:
|
|
+ target = '"{0}"'.format(param)
|
|
+
|
|
+ changes = {}
|
|
+
|
|
+ if '[' in target:
|
|
+ old = __salt__['portage_config.get_flags_from_package_conf']('use', target[1:-1])
|
|
+ __salt__['portage_config.append_use_flags'](target[1:-1])
|
|
+ new = __salt__['portage_config.get_flags_from_package_conf']('use', target[1:-1])
|
|
+ if old != new:
|
|
+ changes[param + '-USE'] = {'old': old, 'new': new}
|
|
+ target = target[:target.rfind('[')] + '"'
|
|
+
|
|
+ if keyword is not None:
|
|
+ if keyword == '~':
|
|
+ v = ['~*']
|
|
+ elif keyword == '*':
|
|
+ v = ['**']
|
|
+ elif keyword == '-':
|
|
+ v = ['~ARCH']
|
|
+ else:
|
|
+ v = [keyword]
|
|
+ old = __salt__['portage_config.get_flags_from_package_conf']('accept_keywords', target[1:-1])
|
|
+ __salt__['portage_config.append_to_package_conf']('accept_keywords', target[1:-1], v)
|
|
+ new = __salt__['portage_config.get_flags_from_package_conf']('accept_keywords', target[1:-1])
|
|
+ if old != new:
|
|
+ changes[param + '-ACCEPT_KEYWORD'] = {'old': old, 'new': new}
|
|
+
|
|
+ if not changes:
|
|
+ inst_v = version(param)
|
|
+
|
|
+ # Prevent latest_version from calling refresh_db. Either we
|
|
+ # just called it or we were asked not to.
|
|
+ if latest_version(param, refresh=False) == inst_v:
|
|
+ all_uses = __salt__['portage_config.get_cleared_flags'](param)
|
|
+ if _flags_changed(*all_uses):
|
|
+ changes[param] = {'version': inst_v,
|
|
+ 'old': {'use': all_uses[0]},
|
|
+ 'new': {'use': all_uses[1]}}
|
|
+ return target, changes
|
|
+
|
|
def install(name=None,
|
|
refresh=False,
|
|
pkgs=None,
|
|
@@ -604,7 +673,9 @@
|
|
|
|
changes = {}
|
|
|
|
- if pkg_type == 'repository':
|
|
+ if not pkg_type == 'repository':
|
|
+ targets = pkg_params
|
|
+ else:
|
|
targets = list()
|
|
for param, version_num in six.iteritems(pkg_params):
|
|
original_param = param
|
|
@@ -617,56 +688,13 @@
|
|
else:
|
|
keyword = None
|
|
|
|
- match = re.match('^(~)?([<>])?(=)?([^<>=]*)$', version_num)
|
|
- if match:
|
|
- keyword, gt_lt, eq, verstr = match.groups()
|
|
- prefix = gt_lt or ''
|
|
- prefix += eq or ''
|
|
- # We need to delete quotes around use flag list elements
|
|
- verstr = verstr.replace("'", "")
|
|
- # If no prefix characters were supplied and verstr contains a version, use '='
|
|
- if len(verstr) > 0 and verstr[0] != ':' and verstr[0] != '[':
|
|
- prefix = prefix or '='
|
|
- target = '"{0}{1}-{2}"'.format(prefix, param, verstr)
|
|
- else:
|
|
- target = '"{0}{1}"'.format(param, verstr)
|
|
- else:
|
|
- target = '"{0}"'.format(param)
|
|
-
|
|
- if '[' in target:
|
|
- old = __salt__['portage_config.get_flags_from_package_conf']('use', target[1:-1])
|
|
- __salt__['portage_config.append_use_flags'](target[1:-1])
|
|
- new = __salt__['portage_config.get_flags_from_package_conf']('use', target[1:-1])
|
|
- if old != new:
|
|
- changes[param + '-USE'] = {'old': old, 'new': new}
|
|
- target = target[:target.rfind('[')] + '"'
|
|
-
|
|
- if keyword is not None:
|
|
- __salt__['portage_config.append_to_package_conf']('accept_keywords',
|
|
- target[1:-1],
|
|
- ['~ARCH'])
|
|
- changes[param + '-ACCEPT_KEYWORD'] = {'old': '', 'new': '~ARCH'}
|
|
-
|
|
- if not changes:
|
|
- inst_v = version(param)
|
|
-
|
|
- # Prevent latest_version from calling refresh_db. Either we
|
|
- # just called it or we were asked not to.
|
|
- if latest_version(param, refresh=False) == inst_v:
|
|
- all_uses = __salt__['portage_config.get_cleared_flags'](param)
|
|
- if _flags_changed(*all_uses):
|
|
- changes[param] = {'version': inst_v,
|
|
- 'old': {'use': all_uses[0]},
|
|
- 'new': {'use': all_uses[1]}}
|
|
+ target, flag_changes = process_target(param, version_num)
|
|
+ changes.update(flag_changes)
|
|
targets.append(target)
|
|
- else:
|
|
- targets = pkg_params
|
|
- cmd = 'emerge --ask n --quiet {0} {1} {2}'.format(bin_opts, emerge_opts, ' '.join(targets))
|
|
|
|
+ cmd = 'emerge --ask n --quiet {0} {1} {2}'.format(bin_opts, emerge_opts, ' '.join(targets))
|
|
old = list_pkgs()
|
|
- call = __salt__['cmd.run_all'](cmd,
|
|
- output_loglevel='trace',
|
|
- python_shell=False)
|
|
+ call = __salt__['cmd.run_all'](cmd, output_loglevel='trace', python_shell=False)
|
|
__context__.pop('pkg.list_pkgs', None)
|
|
if call['retcode'] != 0:
|
|
return _process_emerge_err(call['stdout'], call['stderr'])
|
|
@@ -994,7 +1022,7 @@
|
|
|
|
salt '*' pkg.version_clean <version_string>
|
|
'''
|
|
- return re.match(r'^~?[<>]?=?([^<>=:\[]+).*$', version)
|
|
+ return re.match(r'^(?:~|-|\*)?[<>]?=?([^<>=:\[\~\-\*]+).*$', version)
|
|
|
|
|
|
def check_extra_requirements(pkgname, pkgver):
|
|
@@ -1009,7 +1037,7 @@
|
|
'''
|
|
keyword = None
|
|
|
|
- match = re.match('^(~)?([<>])?(=)?([^<>=]*)$', pkgver)
|
|
+ match = re.match('^(~|-|\*)?([<>])?(=)?([^<>=]*)$', pkgver)
|
|
if match:
|
|
keyword, gt_lt, eq, verstr = match.groups()
|
|
prefix = gt_lt or ''
|
|
@@ -1017,7 +1045,7 @@
|
|
# We need to delete quotes around use flag list elements
|
|
verstr = verstr.replace("'", "")
|
|
# If no prefix characters were supplied and verstr contains a version, use '='
|
|
- if verstr[0] != ':' and verstr[0] != '[':
|
|
+ if len(verstr) > 0 and verstr[0] != ':' and verstr[0] != '[':
|
|
prefix = prefix or '='
|
|
atom = '{0}{1}-{2}'.format(prefix, pkgname, verstr)
|
|
else:
|
|
@@ -1035,7 +1063,7 @@
|
|
except KeyError:
|
|
return False
|
|
|
|
- des_repo = re.match(r'^.+::([^\[]+).*$', atom)
|
|
+ des_repo = re.match(r'^.+::([^\[\~\-\*]+).*$', atom)
|
|
if des_repo and des_repo.group(1) != cur_repo:
|
|
return False
|
|
|
|
@@ -1045,8 +1073,16 @@
|
|
if x[0] != '-' or x[1:] in cur_use]) > 0:
|
|
return False
|
|
|
|
- if keyword:
|
|
- if not __salt__['portage_config.has_flag']('accept_keywords', atom, '~ARCH'):
|
|
+ if keyword is not None:
|
|
+ if keyword == '~':
|
|
+ v = '~*'
|
|
+ elif keyword == '*':
|
|
+ v = '**'
|
|
+ elif keyword == '-':
|
|
+ v = '~ARCH'
|
|
+ else:
|
|
+ v = keyword
|
|
+ if not __salt__['portage_config.has_flag']('accept_keywords', atom, v):
|
|
return False
|
|
|
|
return True
|