<s> """<STR_LIT>""" <EOL> import eventlet <EOL> import os <EOL> import os . path <EOL> import sys <EOL> from daemon . daemon import DaemonContext <EOL> from daemon . runner import DaemonRunner , make_pidlockfile <EOL> from eventlet import wsgi <EOL> from optparse import OptionParser <EOL> from playa import VERSION , app <EOL> class PlayaServer ( DaemonRunner ) : <EOL> pidfile_timeout = <NUM_LIT:10> <EOL> start_message = u"<STR_LIT>" <EOL> def __init__ ( self , host = None , port = None , pidfile = None , <EOL> logfile = None , daemonize = False , debug = False ) : <EOL> if not logfile : <EOL> logfile = app . config [ '<STR_LIT>' ] <EOL> logfile = os . path . realpath ( logfile ) <EOL> pidfile = os . path . realpath ( pidfile or app . config [ '<STR_LIT>' ] ) <EOL> if daemonize : <EOL> detach_process = True <EOL> else : <EOL> detach_process = False <EOL> self . daemon_context = DaemonContext ( detach_process = detach_process ) <EOL> self . daemon_context . stdout = open ( logfile , '<STR_LIT>' ) <EOL> self . daemon_context . stderr = open ( logfile , '<STR_LIT>' , buffering = <NUM_LIT:0> ) <EOL> self . pidfile = make_pidlockfile ( pidfile , self . pidfile_timeout ) <EOL> self . daemon_context . pidfile = self . pidfile <EOL> self . host = host or app . config [ '<STR_LIT>' ] <EOL> self . port = port or app . config [ '<STR_LIT>' ] <EOL> self . debug = debug <EOL> self . app = self <EOL> def execute ( self , action ) : <EOL> self . action = action <EOL> if self . daemon_context . detach_process is False and self . action == '<STR_LIT:start>' : <EOL> self . run ( ) <EOL> else : <EOL> self . do_action ( ) <EOL> def run ( self ) : <EOL> upgrade ( ) <EOL> if self . debug : <EOL> app . run ( host = self . host , port = self . port , debug = self . debug ) <EOL> else : <EOL> wsgi . server ( eventlet . listen ( ( self . host , self . port ) ) , app ) <EOL> def upgrade ( ) : <EOL> if not os . path . exists ( app . config [ '<STR_LIT>' ] ) : <EOL> os . makedirs ( app . config [ '<STR_LIT>' ] ) <EOL> def main ( ) : <EOL> command_list = ( '<STR_LIT:start>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> args = sys . argv <EOL> if len ( args ) < <NUM_LIT:2> or args [ <NUM_LIT:1> ] not in command_list : <EOL> print "<STR_LIT>" <EOL> print <EOL> print "<STR_LIT>" <EOL> for cmd in command_list : <EOL> print "<STR_LIT:U+0020>" , cmd <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> parser = OptionParser ( version = "<STR_LIT>" % VERSION ) <EOL> parser . add_option ( '<STR_LIT>' , metavar = '<STR_LIT>' ) <EOL> if args [ <NUM_LIT:1> ] == '<STR_LIT:start>' : <EOL> parser . add_option ( '<STR_LIT>' , action = '<STR_LIT:store_true>' , default = False , dest = '<STR_LIT>' ) <EOL> parser . add_option ( '<STR_LIT>' , metavar = '<STR_LIT>' ) <EOL> parser . add_option ( '<STR_LIT>' , type = int , metavar = '<STR_LIT>' ) <EOL> parser . add_option ( '<STR_LIT>' , action = '<STR_LIT:store_true>' , default = False , dest = '<STR_LIT>' ) <EOL> parser . add_option ( '<STR_LIT>' , action = '<STR_LIT>' , default = False , dest = '<STR_LIT>' ) <EOL> parser . add_option ( '<STR_LIT>' , dest = '<STR_LIT>' ) <EOL> parser . add_option ( '<STR_LIT>' , dest = '<STR_LIT>' ) <EOL> elif args [ <NUM_LIT:1> ] == '<STR_LIT>' : <EOL> parser . add_option ( '<STR_LIT>' , dest = '<STR_LIT>' ) <EOL> parser . add_option ( '<STR_LIT>' , dest = '<STR_LIT>' ) <EOL> ( options , args ) = parser . parse_args ( ) <EOL> if options . config : <EOL> app . config . from_pyfile ( options . config ) <EOL> else : <EOL> config_path = os . path . expanduser ( os . path . join ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> if os . path . exists ( config_path ) : <EOL> app . config . from_pyfile ( config_path ) <EOL> if args [ <NUM_LIT:0> ] == '<STR_LIT>' : <EOL> upgrade ( ) <EOL> elif args [ <NUM_LIT:0> ] == '<STR_LIT:start>' : <EOL> web = PlayaServer ( host = options . host , port = options . port , <EOL> pidfile = options . pidfile , logfile = options . logfile , <EOL> daemonize = options . daemonize , debug = options . debug ) <EOL> web . execute ( args [ <NUM_LIT:0> ] ) <EOL> elif args [ <NUM_LIT:0> ] == '<STR_LIT>' : <EOL> web = PlayaServer ( ) <EOL> web . execute ( args [ <NUM_LIT:0> ] ) <EOL> elif args [ <NUM_LIT:0> ] == '<STR_LIT>' : <EOL> web = PlayaServer ( pidfile = options . pidfile , logfile = options . logfile ) <EOL> web . execute ( args [ <NUM_LIT:0> ] ) <EOL> sys . exit ( <NUM_LIT:0> ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( ) </s>
