Fix linked/unlinked states.

pull/6069/head
Daniel Jaouen 11 years ago
parent 02694b80de
commit 91ac44a5bb

@ -171,6 +171,7 @@ class Homebrew(object):
- upgraded - upgraded
- head - head
- linked - linked
- unlinked
- absent - absent
''' '''
@ -184,6 +185,7 @@ class Homebrew(object):
'upgraded', 'upgraded',
'head', 'head',
'linked', 'linked',
'unlinked',
'absent', 'absent',
) )
) )
@ -406,8 +408,10 @@ class Homebrew(object):
return self._upgrade_packages() return self._upgrade_packages()
elif self.state == 'head': elif self.state == 'head':
return self._install_packages() return self._install_packages()
# elif self.state == 'linked': elif self.state == 'linked':
# return self._linked() return self._link_packages()
elif self.state == 'unlinked':
return self._unlink_packages()
elif self.state == 'absent': elif self.state == 'absent':
return self._uninstall_packages() return self._uninstall_packages()
@ -597,131 +601,79 @@ class Homebrew(object):
return True return True
# /uninstalled ----------------------------- }}} # /uninstalled ----------------------------- }}}
# /commands ---------------------------------------------------- }}}
# linked --------------------------------- {{{
def _link_current_package(self):
if not self.valid_package(self.current_package):
self.failed = True
self.message = 'Invalid package: {0}.'.format(self.current_package)
raise HomebrewException(self.message)
# def link_package(module, brew_path, package): if not self._current_package_is_installed():
# """ Links a single homebrew package. """ self.failed = True
# self.message = 'Package not installed: {0}.'.format(self.current_package)
# failed, changed, msg = False, False, '' raise HomebrewException(self.message)
#
# if not a_valid_package(package): if self.module.check_mode:
# failed = True self.changed = True
# msg = 'invalid package' self.message = 'Package would be linked: {0}'.format(
# self.current_package
# elif not query_package(module, brew_path, package): )
# failed = True raise HomebrewException(self.message)
# msg = 'not installed'
# cmd = [opt
# else: for opt in (self.brew_path, 'link', self.current_package)
# if module.check_mode: if opt]
# module.exit_json(changed=True)
# rc, out, err = self.module.run_command(cmd)
# rc, out, err = module.run_command([ self.changed_count += 1
# brew_path, self.changed = True
# 'link', self.message = 'Package linked: {0}'.format(self.current_package)
# package,
# ]) def _link_packages(self):
# for package in self.packages:
# if rc: self.current_package = package
# failed = True self._link_current_package()
# msg = out.strip()
# else: return True
# if err.strip().lower().find('already linked') != -1: # /linked -------------------------------- }}}
# msg = 'already linked'
# else: # unlinked ------------------------------- {{{
# changed = True def _unlink_current_package(self):
# msg = 'linked' if not self.valid_package(self.current_package):
# self.failed = True
# return (failed, changed, msg) self.message = 'Invalid package: {0}.'.format(self.current_package)
# raise HomebrewException(self.message)
#
# def link_packages(module, brew_path, packages): if not self._current_package_is_installed():
# """ Upgrades one or more packages. """ self.failed = True
# self.message = 'Package not installed: {0}.'.format(self.current_package)
# failed, linked, unchanged, msg = False, 0, 0, '' raise HomebrewException(self.message)
#
# for package in packages: if self.module.check_mode:
# failed, changed, msg = link_package(module, brew_path, package) self.changed = True
# if failed: self.message = 'Package would be unlinked: {0}'.format(
# break self.current_package
# if changed: )
# linked += 1 raise HomebrewException(self.message)
# else:
# unchanged += 1 cmd = [opt
# for opt in (self.brew_path, 'unlink', self.current_package)
# if failed: if opt]
# msg = 'installed: %d, unchanged: %d, error: ' + msg
# msg = msg % (linked, unchanged) rc, out, err = self.module.run_command(cmd)
# elif linked: self.changed_count += 1
# changed = True self.changed = True
# msg = 'linked: %d, unchanged: %d' % (linked, unchanged) self.message = 'Package unlinked: {0}'.format(self.current_package)
# else:
# msg = 'linked: %d, unchanged: %d' % (linked, unchanged) def _unlink_packages(self):
# for package in self.packages:
# return (failed, changed, msg) self.current_package = package
# self._unlink_current_package()
#
# def unlink_package(module, brew_path, package): return True
# """ Unlinks a single homebrew package. """ # /unlinked ------------------------------ }}}
# # /commands ---------------------------------------------------- }}}
# failed, changed, msg = False, False, ''
#
# if not a_valid_package(package):
# failed = True
# msg = 'invalid package'
#
# elif not query_package(module, brew_path, package):
# failed = True
# msg = 'not installed'
#
# else:
# if module.check_mode:
# module.exit_json(changed=True)
#
# rc, out, err = module.run_command([
# brew_path,
# 'unlink',
# package,
# ])
#
# if rc:
# failed = True
# msg = out.strip()
# else:
# if out.find('0 links') != -1:
# msg = 'already unlinked'
# else:
# changed = True
# msg = 'linked'
#
# return (failed, changed, msg)
#
#
# def unlink_packages(module, brew_path, packages):
# """ Unlinks one or more packages. """
#
# failed, unlinked, unchanged, msg = False, 0, 0, ''
#
# for package in packages:
# failed, changed, msg = unlink_package(module, brew_path, package)
# if failed:
# break
# if changed:
# unlinked += 1
# else:
# unchanged += 1
#
# if failed:
# msg = 'installed: %d, unchanged: %d, error: ' + msg
# msg = msg % (unlinked, unchanged)
# elif unlinked:
# changed = True
# msg = 'unlinked: %d, unchanged: %d' % (unlinked, unchanged)
# else:
# msg = 'unlinked: %d, unchanged: %d' % (unlinked, unchanged)
#
# return (failed, changed, msg)
def main(): def main():
@ -764,6 +716,10 @@ def main():
state = 'installed' state = 'installed'
if state in ('latest', 'upgraded'): if state in ('latest', 'upgraded'):
state = 'upgraded' state = 'upgraded'
if state == 'linked':
state = 'linked'
if state == 'unlinked':
state = 'unlinked'
if state in ('absent', 'removed', 'uninstalled'): if state in ('absent', 'removed', 'uninstalled'):
state = 'absent' state = 'absent'

Loading…
Cancel
Save