<s> '''<STR_LIT>''' <EOL> import subprocess , json , sys <EOL> from gtwisted . core import reactor <EOL> from gfirefly . utils import services <EOL> from gfirefly . distributed . root import PBRoot , BilateralFactory <EOL> from gfirefly . server . globalobject import GlobalObject <EOL> from gtwisted . utils import log <EOL> from gfirefly . server . logobj import loogoo <EOL> from flask import Flask <EOL> reactor = reactor <EOL> MULTI_SERVER_MODE = <NUM_LIT:1> <EOL> SINGLE_SERVER_MODE = <NUM_LIT:2> <EOL> MASTER_SERVER_MODE = <NUM_LIT:3> <EOL> class Master : <EOL> """<STR_LIT:U+0020>""" <EOL> def __init__ ( self ) : <EOL> """<STR_LIT:U+0020>""" <EOL> self . configpath = None <EOL> self . mainpath = None <EOL> self . root = None <EOL> self . webroot = None <EOL> def config ( self , configpath , mainpath ) : <EOL> """<STR_LIT:U+0020>""" <EOL> self . configpath = configpath <EOL> self . mainpath = mainpath <EOL> def masterapp ( self ) : <EOL> """<STR_LIT:U+0020>""" <EOL> config = json . load ( open ( self . configpath , '<STR_LIT:r>' ) ) <EOL> GlobalObject ( ) . json_config = config <EOL> mastercnf = config . get ( '<STR_LIT>' ) <EOL> rootport = mastercnf . get ( '<STR_LIT>' ) <EOL> webport = mastercnf . get ( '<STR_LIT>' ) <EOL> masterlog = mastercnf . get ( '<STR_LIT>' ) <EOL> self . root = PBRoot ( ) <EOL> rootservice = services . Service ( "<STR_LIT>" ) <EOL> self . root . addServiceChannel ( rootservice ) <EOL> self . webroot = Flask ( "<STR_LIT>" ) <EOL> GlobalObject ( ) . root = self . root <EOL> GlobalObject ( ) . webroot = self . webroot <EOL> if masterlog : <EOL> log . addObserver ( loogoo ( masterlog ) ) <EOL> log . startLogging ( sys . stdout ) <EOL> import webapp <EOL> import rootapp <EOL> reactor . listenWSGI ( webport , self . webroot ) <EOL> reactor . listenTCP ( rootport , BilateralFactory ( self . root ) ) <EOL> def start ( self ) : <EOL> '''<STR_LIT:U+0020>''' <EOL> sys_args = sys . argv <EOL> if len ( sys_args ) > <NUM_LIT:2> and sys_args [ <NUM_LIT:1> ] == "<STR_LIT>" : <EOL> server_name = sys_args [ <NUM_LIT:2> ] <EOL> if server_name == "<STR_LIT>" : <EOL> mode = MASTER_SERVER_MODE <EOL> else : <EOL> mode = SINGLE_SERVER_MODE <EOL> else : <EOL> mode = MULTI_SERVER_MODE <EOL> server_name = "<STR_LIT>" <EOL> if mode == MULTI_SERVER_MODE : <EOL> self . masterapp ( ) <EOL> config = json . load ( open ( self . configpath , '<STR_LIT:r>' ) ) <EOL> sersconf = config . get ( '<STR_LIT>' ) <EOL> for sername in sersconf . keys ( ) : <EOL> cmds = '<STR_LIT>' % ( self . mainpath , sername , self . configpath ) <EOL> subprocess . Popen ( cmds , shell = True ) <EOL> reactor . run ( ) <EOL> elif mode == SINGLE_SERVER_MODE : <EOL> config = json . load ( open ( self . configpath , '<STR_LIT:r>' ) ) <EOL> sername = server_name <EOL> cmds = '<STR_LIT>' % ( self . mainpath , sername , self . configpath ) <EOL> subprocess . Popen ( cmds , shell = True ) <EOL> else : <EOL> self . masterapp ( ) <EOL> reactor . run ( ) </s>
