<s> from wsgid . core . command import ICommand <EOL> from wsgid . core import Plugin <EOL> from wsgid . core import WsgidApp <EOL> import sys <EOL> import os <EOL> class CommandStatus ( Plugin ) : <EOL> implements = [ ICommand ] <EOL> def command_name ( self ) : <EOL> return '<STR_LIT:status>' <EOL> def name_matches ( self , name ) : <EOL> return name == '<STR_LIT:status>' <EOL> def run ( self , options , ** kwargs ) : <EOL> app = WsgidApp ( options . app_path ) <EOL> status = { True : '<STR_LIT>' , False : '<STR_LIT>' } <EOL> sys . stdout . write ( "<STR_LIT>" . format ( status = status [ self . _any_running ( app . worker_pids ( ) ) ] ) ) <EOL> sys . stdout . write ( "<STR_LIT>" . format ( pids = "<STR_LIT:U+002CU+0020>" . join ( [ str ( p ) for p in app . master_pids ( ) ] ) ) ) <EOL> sys . stdout . write ( "<STR_LIT>" . format ( pids = "<STR_LIT:U+002CU+0020>" . join ( [ self . _prepare_pid ( p ) for p in app . worker_pids ( ) ] ) ) ) <EOL> def _any_running ( self , pids ) : <EOL> '''<STR_LIT>''' <EOL> return len ( filter ( self . _pid_exists , pids ) ) > <NUM_LIT:0> <EOL> def _pid_exists ( self , pid ) : <EOL> '''<STR_LIT>''' <EOL> try : <EOL> os . kill ( pid , <NUM_LIT:0> ) <EOL> return True <EOL> except : <EOL> return False <EOL> def _prepare_pid ( self , pid ) : <EOL> '''<STR_LIT>''' <EOL> if self . _pid_exists ( pid ) : <EOL> return str ( pid ) <EOL> else : <EOL> return "<STR_LIT>" . format ( pid ) <EOL> def extra_options ( self ) : <EOL> return [ ] </s>
