<s> import abc <EOL> from distutils . spawn import find_executable <EOL> import six <EOL> from st2actions . runners import ActionRunner <EOL> __all__ = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ] <EOL> WINEXE_EXISTS = find_executable ( '<STR_LIT>' ) is not None <EOL> SMBCLIENT_EXISTS = find_executable ( '<STR_LIT>' ) is not None <EOL> ERROR_CODE_TO_MESSAGE_MAP = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> @ six . add_metaclass ( abc . ABCMeta ) <EOL> class BaseWindowsRunner ( ActionRunner ) : <EOL> def _verify_winexe_exists ( self ) : <EOL> if not WINEXE_EXISTS : <EOL> msg = ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> raise Exception ( msg ) <EOL> def _verify_smbclient_exists ( self ) : <EOL> if not SMBCLIENT_EXISTS : <EOL> msg = ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> raise Exception ( msg ) <EOL> def _get_winexe_command_args ( self , host , username , password , command , domain = None ) : <EOL> args = [ '<STR_LIT>' ] <EOL> args += [ '<STR_LIT>' , '<STR_LIT:0>' ] <EOL> if domain : <EOL> args += [ '<STR_LIT>' , '<STR_LIT>' % ( domain , username , password ) ] <EOL> else : <EOL> args += [ '<STR_LIT>' , '<STR_LIT>' % ( username , password ) ] <EOL> args += [ '<STR_LIT>' % ( host ) ] <EOL> args += [ command ] <EOL> return args <EOL> def _get_smbclient_command_args ( self , host , username , password , command , share = '<STR_LIT>' , <EOL> domain = None ) : <EOL> """<STR_LIT>""" <EOL> args = [ '<STR_LIT>' ] <EOL> values = { '<STR_LIT>' : domain , '<STR_LIT:username>' : username , '<STR_LIT:password>' : password } <EOL> if domain : <EOL> auth_string = '<STR_LIT>' % values <EOL> else : <EOL> auth_string = '<STR_LIT>' % values <EOL> args += [ '<STR_LIT>' , auth_string ] <EOL> args += [ '<STR_LIT>' % { '<STR_LIT:host>' : host , '<STR_LIT>' : share } ] <EOL> args += [ '<STR_LIT:-c>' , command ] <EOL> return args <EOL> def _parse_winexe_error ( self , stdout , stderr ) : <EOL> for code , message in ERROR_CODE_TO_MESSAGE_MAP . items ( ) : <EOL> if code in stdout : <EOL> return message <EOL> return None </s>
