<s> '''<STR_LIT>''' <EOL> from __future__ import absolute_import <EOL> from salt . exceptions import CommandExecutionError , CommandNotFoundError <EOL> import salt . ext . six as six <EOL> def __virtual__ ( ) : <EOL> '''<STR_LIT>''' <EOL> return '<STR_LIT>' if '<STR_LIT>' in __salt__ else False , '<STR_LIT>' <EOL> def installed ( name , <EOL> pkgs = None , <EOL> dir = None , <EOL> user = None , <EOL> force_reinstall = False , <EOL> registry = None , <EOL> env = None ) : <EOL> '''<STR_LIT>''' <EOL> ret = { '<STR_LIT:name>' : name , '<STR_LIT:result>' : None , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : { } } <EOL> if pkgs is not None : <EOL> pkg_list = pkgs <EOL> else : <EOL> pkg_list = [ name ] <EOL> try : <EOL> installed_pkgs = __salt__ [ '<STR_LIT>' ] ( dir = dir , runas = user , env = env ) <EOL> except ( CommandNotFoundError , CommandExecutionError ) as err : <EOL> ret [ '<STR_LIT:result>' ] = False <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' . format ( name , err ) <EOL> return ret <EOL> else : <EOL> installed_pkgs = dict ( ( p , info ) <EOL> for p , info in six . iteritems ( installed_pkgs ) ) <EOL> pkgs_satisfied = [ ] <EOL> pkgs_to_install = [ ] <EOL> def _pkg_is_installed ( pkg , installed_pkgs ) : <EOL> '''<STR_LIT>''' <EOL> if ( pkg_name in installed_pkgs and <EOL> '<STR_LIT:version>' in installed_pkgs [ pkg_name ] ) : <EOL> return True <EOL> elif '<STR_LIT>' in pkg_name : <EOL> for pkg_details in installed_pkgs . values ( ) : <EOL> try : <EOL> pkg_from = pkg_details . get ( '<STR_LIT>' , '<STR_LIT>' ) . split ( '<STR_LIT>' ) [ <NUM_LIT:1> ] <EOL> if pkg_name . split ( '<STR_LIT>' ) [ <NUM_LIT:1> ] == pkg_from : <EOL> return True <EOL> except IndexError : <EOL> pass <EOL> return False <EOL> for pkg in pkg_list : <EOL> pkg_name , _ , pkg_ver = pkg . partition ( '<STR_LIT:@>' ) <EOL> pkg_name = pkg_name . strip ( ) <EOL> if force_reinstall is True : <EOL> pkgs_to_install . append ( pkg ) <EOL> continue <EOL> if not _pkg_is_installed ( pkg , installed_pkgs ) : <EOL> pkgs_to_install . append ( pkg ) <EOL> continue <EOL> installed_name_ver = '<STR_LIT>' . format ( pkg_name , <EOL> installed_pkgs [ pkg_name ] [ '<STR_LIT:version>' ] ) <EOL> if pkg_ver : <EOL> if installed_pkgs [ pkg_name ] . get ( '<STR_LIT:version>' ) != pkg_ver : <EOL> pkgs_to_install . append ( pkg ) <EOL> else : <EOL> pkgs_satisfied . append ( installed_name_ver ) <EOL> continue <EOL> else : <EOL> pkgs_satisfied . append ( installed_name_ver ) <EOL> continue <EOL> if __opts__ [ '<STR_LIT:test>' ] : <EOL> ret [ '<STR_LIT:result>' ] = None <EOL> comment_msg = [ ] <EOL> if pkgs_to_install : <EOL> comment_msg . append ( '<STR_LIT>' <EOL> . format ( '<STR_LIT:U+002CU+0020>' . join ( pkgs_to_install ) ) ) <EOL> ret [ '<STR_LIT>' ] = { '<STR_LIT>' : [ ] , '<STR_LIT>' : pkgs_to_install } <EOL> if pkgs_satisfied : <EOL> comment_msg . append ( '<STR_LIT>' <EOL> . format ( '<STR_LIT:U+002CU+0020>' . join ( pkg_list ) , '<STR_LIT:U+002CU+0020>' . join ( pkgs_satisfied ) ) ) <EOL> ret [ '<STR_LIT:result>' ] = True <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' . join ( comment_msg ) <EOL> return ret <EOL> if not pkgs_to_install : <EOL> ret [ '<STR_LIT:result>' ] = True <EOL> ret [ '<STR_LIT>' ] = ( '<STR_LIT>' <EOL> . format ( '<STR_LIT:U+002CU+0020>' . join ( pkg_list ) , '<STR_LIT:U+002CU+0020>' . join ( pkgs_satisfied ) ) ) <EOL> return ret <EOL> try : <EOL> cmd_args = { <EOL> '<STR_LIT>' : dir , <EOL> '<STR_LIT>' : user , <EOL> '<STR_LIT>' : registry , <EOL> '<STR_LIT>' : env , <EOL> '<STR_LIT>' : pkg_list , <EOL> } <EOL> call = __salt__ [ '<STR_LIT>' ] ( ** cmd_args ) <EOL> except ( CommandNotFoundError , CommandExecutionError ) as err : <EOL> ret [ '<STR_LIT:result>' ] = False <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' . format ( <EOL> '<STR_LIT:U+002CU+0020>' . join ( pkg_list ) , err ) <EOL> return ret <EOL> if call and ( isinstance ( call , list ) or isinstance ( call , dict ) ) : <EOL> ret [ '<STR_LIT:result>' ] = True <EOL> ret [ '<STR_LIT>' ] = { '<STR_LIT>' : [ ] , '<STR_LIT>' : pkgs_to_install } <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' . format ( <EOL> '<STR_LIT:U+002CU+0020>' . join ( pkgs_to_install ) ) <EOL> else : <EOL> ret [ '<STR_LIT:result>' ] = False <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' . format ( <EOL> '<STR_LIT:U+002CU+0020>' . join ( pkg_list ) ) <EOL> return ret <EOL> def removed ( name , <EOL> dir = None , <EOL> user = None ) : <EOL> '''<STR_LIT>''' <EOL> ret = { '<STR_LIT:name>' : name , '<STR_LIT:result>' : None , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : { } } <EOL> try : <EOL> installed_pkgs = __salt__ [ '<STR_LIT>' ] ( dir = dir ) <EOL> except ( CommandExecutionError , CommandNotFoundError ) as err : <EOL> ret [ '<STR_LIT:result>' ] = False <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' . format ( name , err ) <EOL> return ret <EOL> if name not in installed_pkgs : <EOL> ret [ '<STR_LIT:result>' ] = True <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' . format ( name ) <EOL> return ret <EOL> if __opts__ [ '<STR_LIT:test>' ] : <EOL> ret [ '<STR_LIT:result>' ] = None <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' . format ( name ) <EOL> return ret <EOL> if __salt__ [ '<STR_LIT>' ] ( pkg = name , dir = dir , runas = user ) : <EOL> ret [ '<STR_LIT:result>' ] = True <EOL> ret [ '<STR_LIT>' ] [ name ] = '<STR_LIT>' <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' . format ( name ) <EOL> else : <EOL> ret [ '<STR_LIT:result>' ] = False <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' . format ( name ) <EOL> return ret <EOL> def bootstrap ( name , <EOL> user = None , <EOL> silent = True ) : <EOL> '''<STR_LIT>''' <EOL> ret = { '<STR_LIT:name>' : name , '<STR_LIT:result>' : None , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : { } } <EOL> if __opts__ [ '<STR_LIT:test>' ] : <EOL> try : <EOL> call = __salt__ [ '<STR_LIT>' ] ( dir = name , runas = user , pkg = None , silent = silent , dry_run = True ) <EOL> except ( CommandNotFoundError , CommandExecutionError ) as err : <EOL> ret [ '<STR_LIT:result>' ] = False <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' . format ( name , err ) <EOL> return ret <EOL> ret [ '<STR_LIT:result>' ] = None <EOL> ret [ '<STR_LIT>' ] = { '<STR_LIT>' : [ ] , '<STR_LIT>' : call } <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' . format ( name ) <EOL> return ret <EOL> try : <EOL> call = __salt__ [ '<STR_LIT>' ] ( dir = name , runas = user , pkg = None , silent = silent ) <EOL> except ( CommandNotFoundError , CommandExecutionError ) as err : <EOL> ret [ '<STR_LIT:result>' ] = False <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' . format ( name , err ) <EOL> return ret <EOL> if not call : <EOL> ret [ '<STR_LIT:result>' ] = True <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> return ret <EOL> if isinstance ( call , str ) : <EOL> ret [ '<STR_LIT:result>' ] = False <EOL> ret [ '<STR_LIT>' ] = call <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> else : <EOL> ret [ '<STR_LIT:result>' ] = True <EOL> ret [ '<STR_LIT>' ] = { name : '<STR_LIT>' } <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> return ret <EOL> def cache_cleaned ( name = None , <EOL> user = None ) : <EOL> '''<STR_LIT>''' <EOL> ret = { '<STR_LIT:name>' : name , '<STR_LIT:result>' : None , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : { } } <EOL> specific_pkg = None <EOL> try : <EOL> cached_pkgs = __salt__ [ '<STR_LIT>' ] ( path = name , runas = user ) <EOL> except ( CommandExecutionError , CommandNotFoundError ) as err : <EOL> ret [ '<STR_LIT:result>' ] = False <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' . format ( <EOL> name or '<STR_LIT>' , err ) <EOL> return ret <EOL> if name : <EOL> all_cached_pkgs = __salt__ [ '<STR_LIT>' ] ( path = None , runas = user ) <EOL> cache_root_path = all_cached_pkgs [ <NUM_LIT:0> ] <EOL> specific_pkg = '<STR_LIT>' . format ( cache_root_path , name ) <EOL> if specific_pkg not in cached_pkgs : <EOL> ret [ '<STR_LIT:result>' ] = True <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' . format ( name ) <EOL> return ret <EOL> if __opts__ [ '<STR_LIT:test>' ] : <EOL> ret [ '<STR_LIT:result>' ] = None <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' . format ( name or '<STR_LIT>' ) <EOL> return ret <EOL> if __salt__ [ '<STR_LIT>' ] ( path = name , runas = user ) : <EOL> ret [ '<STR_LIT:result>' ] = True <EOL> ret [ '<STR_LIT>' ] [ name or '<STR_LIT>' ] = '<STR_LIT>' <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' . format ( <EOL> name or '<STR_LIT>' <EOL> ) <EOL> else : <EOL> ret [ '<STR_LIT:result>' ] = False <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' . format ( name or '<STR_LIT>' ) <EOL> return ret </s>
