def installed(name, dir, pkgs=None, user=None, env=None):
 ret = {'name': name, 'result': None, 'comment': '', 'changes': {}}
 if (pkgs is not None):
  pkg_list = pkgs
 else:
  pkg_list = [name]
 try:
  installed_pkgs = __salt__['bower.list'](dir=dir, runas=user, env=env)
 except (CommandNotFoundError, CommandExecutionError) as err:
  ret['result'] = False
  ret['comment'] = "Error looking up '{0}': {1}".format(name, err)
  return ret
 else:
  installed_pkgs = dict(((p, info) for (p, info) in six.iteritems(installed_pkgs)))
 pkgs_satisfied = []
 pkgs_to_install = []
 for pkg in pkg_list:
  (pkg_name, _, pkg_ver) = pkg.partition('#')
  pkg_name = pkg_name.strip()
  if (pkg_name not in installed_pkgs):
   pkgs_to_install.append(pkg)
   continue
  if (pkg_name in installed_pkgs):
   installed_pkg = installed_pkgs[pkg_name]
   installed_pkg_ver = installed_pkg.get('pkgMeta').get('version')
   installed_name_ver = '{0}#{1}'.format(pkg_name, installed_pkg_ver)
   if pkg_ver:
    if (installed_pkg_ver != pkg_ver):
     pkgs_to_install.append(pkg)
    else:
     pkgs_satisfied.append(installed_name_ver)
    continue
   else:
    pkgs_satisfied.append(installed_name_ver)
    continue
 if __opts__['test']:
  ret['result'] = None
  comment_msg = []
  if pkgs_to_install:
   comment_msg.append("Bower package(s) '{0}' are set to be installed".format(', '.join(pkgs_to_install)))
   ret['changes'] = {'old': [], 'new': pkgs_to_install}
  if pkgs_satisfied:
   comment_msg.append("Package(s) '{0}' satisfied by {1}".format(', '.join(pkg_list), ', '.join(pkgs_satisfied)))
  ret['comment'] = '. '.join(comment_msg)
  return ret
 if (not pkgs_to_install):
  ret['result'] = True
  ret['comment'] = "Package(s) '{0}' satisfied by {1}".format(', '.join(pkg_list), ', '.join(pkgs_satisfied))
  return ret
 try:
  cmd_args = {'pkg': None, 'dir': dir, 'pkgs': None, 'runas': user, 'env': env}
  if (pkgs is not None):
   cmd_args['pkgs'] = pkgs
  else:
   cmd_args['pkg'] = pkg_name
  call = __salt__['bower.install'](**cmd_args)
 except (CommandNotFoundError, CommandExecutionError) as err:
  ret['result'] = False
  ret['comment'] = "Error installing '{0}': {1}".format(', '.join(pkg_list), err)
  return ret
 if call:
  ret['result'] = True
  ret['changes'] = {'old': [], 'new': pkgs_to_install}
  ret['comment'] = "Package(s) '{0}' successfully installed".format(', '.join(pkgs_to_install))
 else:
  ret['result'] = False
  ret['comment'] = "Could not install package(s) '{0}'".format(', '.join(pkg_list))
 return ret

def installed ( name , dir , pkgs = None , user = None , env = None ) : ret = { 'name' : name , 'result' : None , 'comment' : '' , 'changes' : { } } if ( pkgs is not None ) : pkg_list = pkgs else : pkg_list = [ name ] try : installed_pkgs = __salt__ [ 'bower.list' ] ( dir = dir , runas = user , env = env ) except ( CommandNotFoundError , CommandExecutionError ) as err : ret [ 'result' ] = False ret [ 'comment' ] = "Error looking up '{0}': {1}" . format ( name , err ) return ret else : installed_pkgs = dict ( ( ( p , info ) for ( p , info ) in six . iteritems ( installed_pkgs ) ) ) pkgs_satisfied = [ ] pkgs_to_install = [ ] for pkg in pkg_list : ( pkg_name , _ , pkg_ver ) = pkg . partition ( '#' ) pkg_name = pkg_name . strip ( ) if ( pkg_name not in installed_pkgs ) : pkgs_to_install . append ( pkg ) continue if ( pkg_name in installed_pkgs ) : installed_pkg = installed_pkgs [ pkg_name ] installed_pkg_ver = installed_pkg . get ( 'pkgMeta' ) . get ( 'version' ) installed_name_ver = '{0}#{1}' . format ( pkg_name , installed_pkg_ver ) if pkg_ver : if ( installed_pkg_ver != pkg_ver ) : pkgs_to_install . append ( pkg ) else : pkgs_satisfied . append ( installed_name_ver ) continue else : pkgs_satisfied . append ( installed_name_ver ) continue if __opts__ [ 'test' ] : ret [ 'result' ] = None comment_msg = [ ] if pkgs_to_install : comment_msg . append ( "Bower package(s) '{0}' are set to be installed" . format ( ', ' . join ( pkgs_to_install ) ) ) ret [ 'changes' ] = { 'old' : [ ] , 'new' : pkgs_to_install } if pkgs_satisfied : comment_msg . append ( "Package(s) '{0}' satisfied by {1}" . format ( ', ' . join ( pkg_list ) , ', ' . join ( pkgs_satisfied ) ) ) ret [ 'comment' ] = '. ' . join ( comment_msg ) return ret if ( not pkgs_to_install ) : ret [ 'result' ] = True ret [ 'comment' ] = "Package(s) '{0}' satisfied by {1}" . format ( ', ' . join ( pkg_list ) , ', ' . join ( pkgs_satisfied ) ) return ret try : cmd_args = { 'pkg' : None , 'dir' : dir , 'pkgs' : None , 'runas' : user , 'env' : env } if ( pkgs is not None ) : cmd_args [ 'pkgs' ] = pkgs else : cmd_args [ 'pkg' ] = pkg_name call = __salt__ [ 'bower.install' ] ( ** cmd_args ) except ( CommandNotFoundError , CommandExecutionError ) as err : ret [ 'result' ] = False ret [ 'comment' ] = "Error installing '{0}': {1}" . format ( ', ' . join ( pkg_list ) , err ) return ret if call : ret [ 'result' ] = True ret [ 'changes' ] = { 'old' : [ ] , 'new' : pkgs_to_install } ret [ 'comment' ] = "Package(s) '{0}' successfully installed" . format ( ', ' . join ( pkgs_to_install ) ) else : ret [ 'result' ] = False ret [ 'comment' ] = "Could not install package(s) '{0}'" . format ( ', ' . join ( pkg_list ) ) return ret
verify that the specified python is installed with pyenv .