Fixed up the use of mirrors with cygwin

- Simplified the use of cygcheck to look for packages that are already installed
- Added documentation for adding mirrors to a cygwin state/module
This commit is contained in:
Daniel Hobley 2015-02-17 16:30:32 +01:00
parent fcb7395dc4
commit bdafb0b4e0
2 changed files with 49 additions and 17 deletions

View File

@ -96,12 +96,14 @@ def check_valid_package(package,
mirrors=None):
"""Check if the package is valid on the given mirrors."""
if mirrors is None:
mirrors = {DEFAULT_MIRROR: DEFAULT_MIRROR_KEY}
mirrors = [{DEFAULT_MIRROR: DEFAULT_MIRROR_KEY}]
LOG.debug('Checking Valid Mirrors: {0}'.format(mirrors))
for mirror in mirrors:
if package in _get_all_packages(mirror, cyg_arch):
for mirror_url, key in mirror.items():
if package in _get_all_packages(mirror_url, cyg_arch):
return True
return False
@ -137,9 +139,10 @@ def _run_silent_cygwin(cyg_arch='x86_64',
options.append('--local-package-dir {0}'.format(cyg_cache_dir))
if mirrors is None:
mirrors = {DEFAULT_MIRROR: DEFAULT_MIRROR_KEY}
for mirror, key in mirrors.items():
options.append('--site {0}'.format(mirror))
mirrors = [{DEFAULT_MIRROR: DEFAULT_MIRROR_KEY}]
for mirror in mirrors:
for mirror_url, key in mirror.items():
options.append('--site {0}'.format(mirror_url))
if key:
options.append('--pubkey {0}'.format(key))
options.append('--no-desktop')
@ -164,15 +167,11 @@ def _run_silent_cygwin(cyg_arch='x86_64',
def _cygcheck(args, cyg_arch='x86_64'):
"""Run the cygcheck executable."""
bashcmd = ' '.join([
os.sep.join(['c:', _get_cyg_dir(cyg_arch), 'bin', 'bash']),
'--login', '-c'])
cygcheck = '\'cygcheck {0}\''.format(args)
cmdline = ' '.join([bashcmd, cygcheck])
cmd = ' '.join([
os.sep.join(['c:', _get_cyg_dir(cyg_arch), 'bin', 'cygcheck']),
'-c', args])
ret = __salt__['cmd.run_all'](
cmdline
)
ret = __salt__['cmd.run_all'](cmd)
if ret['retcode'] == 0:
return ret['stdout']
@ -198,6 +197,7 @@ def install(packages=None,
.. code-block:: bash
salt '*' cyg.install dos2unix
salt '*' cyg.install dos2unix mirrors=[{'http://mirror': 'http://url/to/public/key}]
"""
args = []
# If we want to install packages
@ -229,6 +229,7 @@ def uninstall(packages,
.. code-block:: bash
salt '*' cyg.uninstall dos2unix
salt '*' cyg.uninstall dos2unix mirrors=[{'http://mirror': 'http://url/to/public/key}]
"""
args = []
if packages is not None:
@ -254,6 +255,7 @@ def update(cyg_arch='x86_64', mirrors=None):
.. code-block:: bash
salt '*' cyg.update
salt '*' cyg.update dos2unix mirrors=[{'http://mirror': 'http://url/to/public/key}]
"""
args = []
args.append('--upgrade-also')

View File

@ -39,6 +39,16 @@ def installed(name,
mirrors : None
List of mirrors to check.
None will use a default mirror (kernel.org)
CLI Example:
.. code-block:: yaml
rsync:
cyg.installed:
- mirrors:
- http://mirror/without/public/key: ""
- http://mirror/with/public/key: http://url/of/public/key
'''
ret = {'name': name, 'result': None, 'comment': '', 'changes': {}}
@ -95,6 +105,16 @@ def removed(name, cyg_arch='x86_64', mirrors=None):
mirrors : None
List of mirrors to check.
None will use a default mirror (kernel.org)
CLI Example:
.. code-block:: yaml
rsync:
cyg.removed:
- mirrors:
- http://mirror/without/public/key: ""
- http://mirror/with/public/key: http://url/of/public/key
'''
ret = {'name': name, 'result': None, 'comment': '', 'changes': {}}
@ -111,7 +131,7 @@ def removed(name, cyg_arch='x86_64', mirrors=None):
ret['comment'] = 'Invalid package name.'
return ret
if name not in __salt__['cyg.list'](name, cyg_arch, mirrors):
if name not in __salt__['cyg.list'](name, cyg_arch):
ret['result'] = True
ret['comment'] = 'Package is not installed.'
return ret
@ -143,6 +163,16 @@ def updated(name=None, cyg_arch='x86_64', mirrors=None):
mirrors : None
List of mirrors to check.
None will use a default mirror (kernel.org)
CLI Example:
.. code-block:: yaml
rsync:
cyg.updated:
- mirrors:
- http://mirror/without/public/key: ""
- http://mirror/with/public/key: http://url/of/public/key
'''
ret = {'name': 'cyg.updated', 'result': None, 'comment': '', 'changes': {}}