#NEWLINE# def _uninstall( action = 'remove' , name = None , version = None , pkgs = None , normalize = True , ignore_epoch = False , **kwargs ) : #NEWLINE# #INDENT# '\n    Common function for package removal\n    ' #NEWLINE# if ( action not in ( 'remove' , 'purge' ) ) : #NEWLINE# #INDENT# return { #NEWLINE# #INDENT# 'name' : name , #NEWLINE# 'changes' : { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } , #NEWLINE# 'result' : False , #NEWLINE# 'comment' : "Invalid action '{0}'. This is probably a bug." . format ( action ) , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# pkg_params = __salt__ [ 'pkg_resource.parse_targets' ] ( name , pkgs , normalize = normalize ) [ 0 ] #NEWLINE# #UNINDENT# except MinionError as exc : #NEWLINE# #INDENT# return { #NEWLINE# #INDENT# 'name' : name , #NEWLINE# 'changes' : { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } , #NEWLINE# 'result' : False , #NEWLINE# 'comment' : 'An error was encountered while parsing targets: {0}' . format ( exc ) , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# targets = _find_remove_targets ( name , version , pkgs , normalize , ignore_epoch = ignore_epoch , ** kwargs ) #NEWLINE# if ( isinstance ( targets , dict ) and ( 'result' in targets ) ) : #NEWLINE# #INDENT# return targets #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( not isinstance ( targets , list ) ) : #NEWLINE# #INDENT# return { #NEWLINE# #INDENT# 'name' : name , #NEWLINE# 'changes' : { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } , #NEWLINE# 'result' : False , #NEWLINE# 'comment' : 'An error was encountered while checking targets: {0}' . format ( targets ) , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# #UNINDENT# if ( action == 'purge' ) : #NEWLINE# #INDENT# old_removed = __salt__ [ 'pkg.list_pkgs' ] ( versions_as_list = True , removed = True , ** kwargs ) #NEWLINE# targets . extend ( [ x for x in pkg_params if ( x in old_removed ) ] ) #NEWLINE# #UNINDENT# targets . sort ( ) #NEWLINE# if ( not targets ) : #NEWLINE# #INDENT# return { #NEWLINE# #INDENT# 'name' : name , #NEWLINE# 'changes' : { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } , #NEWLINE# 'result' : True , #NEWLINE# 'comment' : 'None of the targeted packages are installed{0}' . format ( ( ' or partially installed' if ( action == 'purge' ) else '' ) ) , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# if __opts__ [ 'test' ] : #NEWLINE# #INDENT# return { #NEWLINE# #INDENT# 'name' : name , #NEWLINE# 'changes' : { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } , #NEWLINE# 'result' : None , #NEWLINE# 'comment' : 'The following packages will be {0}d: {1}.' . format ( action , ', ' . join ( targets ) ) , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# changes = __salt__ [ 'pkg.{0}' . format ( action ) ] ( name , pkgs = pkgs , version = version , ** kwargs ) #NEWLINE# new = __salt__ [ 'pkg.list_pkgs' ] ( versions_as_list = True , ** kwargs ) #NEWLINE# failed = [ x for x in pkg_params if ( x in new ) ] #NEWLINE# if ( action == 'purge' ) : #NEWLINE# #INDENT# new_removed = __salt__ [ 'pkg.list_pkgs' ] ( versions_as_list = True , removed = True , ** kwargs ) #NEWLINE# failed . extend ( [ x for x in pkg_params if ( x in new_removed ) ] ) #NEWLINE# #UNINDENT# failed . sort ( ) #NEWLINE# if failed : #NEWLINE# #INDENT# return { #NEWLINE# #INDENT# 'name' : name , #NEWLINE# 'changes' : changes , #NEWLINE# 'result' : False , #NEWLINE# 'comment' : 'The following packages failed to {0}: {1}.' . format ( action , ', ' . join ( failed ) ) , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# comments = [ ] #NEWLINE# not_installed = sorted ( [ x for x in pkg_params if ( x not in targets ) ] ) #NEWLINE# if not_installed : #NEWLINE# #INDENT# comments . append ( 'The following packages were not installed: {0}' . format ( ', ' . join ( not_installed ) ) ) #NEWLINE# comments . append ( 'The following packages were {0}d: {1}.' . format ( action , ', ' . join ( targets ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# comments . append ( 'All targeted packages were {0}d.' . format ( action ) ) #NEWLINE# #UNINDENT# return { #NEWLINE# #INDENT# 'name' : name , #NEWLINE# 'changes' : changes , #NEWLINE# 'result' : True , #NEWLINE# 'comment' : ' ' . join ( comments ) , #NEWLINE# #UNINDENT# }