Merge pull request #5038 from basepi/npm4674

Make npm.uninstall and npm.removed more consistent, Fix #4674
This commit is contained in:
David Boucha 2013-05-15 14:53:09 -07:00
commit 7291dae6ee
2 changed files with 25 additions and 13 deletions

View File

@ -10,6 +10,9 @@ import salt.utils
from salt.exceptions import CommandExecutionError
log = logging.getLogger(__name__)
def __virtual__():
'''
Only work when npm is installed.
@ -18,6 +21,7 @@ def __virtual__():
return 'npm'
return False
def _valid_version():
'''
Check the version of npm to ensure this module will work. Currently
@ -86,7 +90,7 @@ def install(pkg=None,
if i.startswith("{"):
break
else:
lines = lines[1:]
lines = lines[1:]
try:
return json.loads(''.join(lines))
@ -94,6 +98,7 @@ def install(pkg=None,
# Still no JSON!! Return the stdout as a string
return result['stdout']
def uninstall(pkg,
dir=None,
runas=None):
@ -118,7 +123,8 @@ def uninstall(pkg,
'''
if not _valid_version():
return '"{0}" is not available.'.format('npm.uninstall')
log.error('"{0}" is not available.'.format('npm.uninstall'))
return False
cmd = 'npm uninstall'
@ -130,7 +136,10 @@ def uninstall(pkg,
result = __salt__['cmd.run_all'](cmd, cwd=dir, runas=runas)
if result['retcode'] != 0:
raise CommandExecutionError(result['stderr'])
log.error(results['stderr'])
return False
return True
def list(pkg=None,
dir=None):

View File

@ -5,6 +5,7 @@ A state module to manage installed NPM packages.
# Import salt libs
from salt.exceptions import CommandExecutionError, CommandNotFoundError
def installed(name,
dir=None,
runas=None,
@ -69,6 +70,7 @@ def installed(name,
return ret
def removed(name,
dir=None,
runas=None,
@ -102,17 +104,19 @@ def removed(name,
ret['comment'] = 'Package {0} is set to be removed'.format(name)
return ret
call = __salt__["npm.uninstall"](
pkg=name,
dir=dir,
runas=runas)
ret["result"] = True
ret["changes"][name] = "Removed"
ret["comment"] = "Package was successfully removed."
if __salt__["npm.uninstall"](pkg=name,
dir=dir,
runas=runas):
ret["result"] = True
ret["changes"][name] = 'Removed'
ret["comment"] = 'Package was successfully removed.'
else:
ret["result"] = False
ret["comment"] = 'Error removing package.'
return ret
def bootstrap(
name,
runas=None):
@ -143,11 +147,10 @@ def bootstrap(
if call:
ret['result'] = True
ret['changes'] = name,'Bootstrapped'
ret['changes'] = name, 'Bootstrapped'
ret['comment'] = 'Directory was successfully bootstrapped'
else:
ret['result'] = False
ret['comment'] = 'Could not bootstrap directory'
return ret