#NEWLINE# @ deferredAsThread #NEWLINE# def findProcesses( self ) : #NEWLINE# #INDENT# "Attempt to find a process by an ASSIMILATION pattern.\n           This is a relatively naive attempt to find an application\n           that works in most cases. \n\n           NOTE:\n             If your ASSIMILATION pattern includes group matches the \n             dictionary will be updated with the output of\n             ``groupdict() from re.search``.  If droned is able to\n             read the environment settings from the application that\n             will be inlcuded in the result dictionary as well. \n\n\n           @callback (list) -  sorted([(int('PID'), dict), ...])\n           @errback (twisted.python.failure.Failure())\n           @return defer.Deferred()\n        " #NEWLINE# candidates = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# def safe_process( pid ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# return AppProcess ( Server ( config . HOSTNAME ) , pid ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# err ( 'problem' ) #NEWLINE# return None #NEWLINE# #UNINDENT# #UNINDENT# if self . PROCESS_REGEX : #NEWLINE# #INDENT# for process in ( safe_process ( pid ) for pid in listProcesses ( ) ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# if ( not process ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# if ( not process . __class__ . isValid ( process ) ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# if ( process . pid in candidates ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# if ( process . ppid != 1 ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# if ( not process . running ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# if ( not process . localInstall ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# if process . managed : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# cmd = ' ' . join ( process . cmdline ) #NEWLINE# if ( not cmd ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# match = self . PROCESS_REGEX . search ( d ) #NEWLINE# if ( not match ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# _result = dict ( ** process . environ ) #NEWLINE# _result . update ( match . groupdict ( ) ) #NEWLINE# _result . update ( { #NEWLINE# #INDENT# 'pid' : process . pid , #NEWLINE# #UNINDENT# } ) #NEWLINE# candidates [ _result [ 'pid' ] ] = _result #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# self . log ( 'error searching for process check console log' ) #NEWLINE# err ( 'error searching for process' ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return sorted ( [ ( pid , d ) for ( pid , d ) in candidates . items ( ) if ( pid > 1 ) ] )