<s> import os <EOL> import sys <EOL> import webbrowser <EOL> import semantic_version <EOL> import argparse <EOL> from web_ui import app , db <EOL> from gevent import Greenlet , monkey <EOL> from gevent . wsgi import WSGIServer <EOL> from gevent . event import Event <EOL> from sqlalchemy . exc import OperationalError <EOL> from uuid import uuid4 <EOL> from nucleus . models import Souma , Starmap <EOL> from nucleus . update import timed_update_check <EOL> from nucleus . helpers import configure_app <EOL> from synapse import Synapse <EOL> from web_ui . helpers import host_kind , compile_less <EOL> monkey . patch_all ( ) <EOL> """<STR_LIT>""" <EOL> parser = argparse . ArgumentParser ( description = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , <EOL> default = False , <EOL> action = "<STR_LIT:store_true>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_argument ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> default = False , <EOL> action = "<STR_LIT:store_true>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_argument ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> default = False , <EOL> action = "<STR_LIT:store_true>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_argument ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> type = int , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> default = app . config [ '<STR_LIT>' ] , <EOL> help = "<STR_LIT>" ) <EOL> args = parser . parse_args ( ) <EOL> configure_app ( app , args ) <EOL> """<STR_LIT>""" <EOL> if getattr ( sys , '<STR_LIT>' , None ) == '<STR_LIT>' : <EOL> import imp <EOL> import httplib <EOL> original_load_module = imp . load_module <EOL> original_find_module = imp . find_module <EOL> def custom_load_module ( name , file , pathname , description ) : <EOL> if name == '<STR_LIT>' : <EOL> return httplib <EOL> return original_load_module ( name , file , pathname , description ) <EOL> def custom_find_module ( name , path = None ) : <EOL> if name == '<STR_LIT>' : <EOL> return ( None , None , None ) <EOL> return original_find_module ( name , path ) <EOL> imp . load_module = custom_load_module <EOL> imp . find_module = custom_find_module <EOL> __httplib__ = imp . load_module ( '<STR_LIT>' , * imp . find_module ( '<STR_LIT>' ) ) <EOL> assert __httplib__ is httplib <EOL> """<STR_LIT>""" <EOL> start = True <EOL> local_souma = None <EOL> from nucleus . database import initialize_database <EOL> try : <EOL> initialize_database ( app , db ) <EOL> except OperationalError , e : <EOL> app . logger . error ( "<STR_LIT>" + <EOL> "<STR_LIT>" + <EOL> "<STR_LIT>" . format ( <EOL> app . config [ "<STR_LIT>" ] , e ) ) <EOL> start = False <EOL> local_souma = Souma . query . get ( app . config [ "<STR_LIT>" ] ) <EOL> if local_souma is None : <EOL> app . logger . info ( "<STR_LIT>" . format ( app . config [ '<STR_LIT>' ] [ : <NUM_LIT:6> ] ) ) <EOL> local_souma = Souma ( id = app . config [ '<STR_LIT>' ] , version = app . config [ "<STR_LIT>" ] ) <EOL> local_souma . generate_keys ( ) <EOL> local_souma . starmap = Starmap ( id = uuid4 ( ) . hex , kind = "<STR_LIT:index>" ) <EOL> db . session . add ( local_souma ) <EOL> db . session . commit ( ) <EOL> start = True <EOL> elif local_souma . version < semantic_version . Version ( app . config [ "<STR_LIT>" ] ) : <EOL> app . logger . error ( """<STR_LIT>""" . format ( <EOL> local_souma . version , app . config [ "<STR_LIT>" ] , app . config [ "<STR_LIT>" ] ) ) <EOL> app . config [ "<STR_LIT>" ] = os . path . abspath ( '<STR_LIT:.>' ) <EOL> """<STR_LIT>""" <EOL> if start : <EOL> if app . config [ '<STR_LIT>' ] : <EOL> app . run ( app . config [ '<STR_LIT>' ] , app . config [ '<STR_LIT>' ] ) <EOL> else : <EOL> shutdown = Event ( ) <EOL> if not app . config [ '<STR_LIT>' ] : <EOL> if host_kind ( ) == "<STR_LIT>" : <EOL> compile_less ( ) <EOL> app . logger . info ( "<STR_LIT>" ) <EOL> local_server = WSGIServer ( ( '<STR_LIT>' , app . config [ '<STR_LIT>' ] ) , app ) <EOL> local_server . start ( ) <EOL> webbrowser . open ( "<STR_LIT>" . format ( app . config [ "<STR_LIT>" ] ) ) <EOL> app . logger . info ( "<STR_LIT>" ) <EOL> if app . config [ "<STR_LIT>" ] : <EOL> synapse = Synapse ( ) <EOL> synapse . electrical . login_all ( ) <EOL> else : <EOL> try : <EOL> synapse = Synapse ( ) <EOL> synapse . electrical . login_all ( ) <EOL> except Exception , e : <EOL> app . logger . error ( e ) <EOL> if host_kind ( ) in [ "<STR_LIT>" , "<STR_LIT>" ] : <EOL> app . logger . info ( "<STR_LIT>" ) <EOL> timed_update_check ( ) <EOL> shutdown . wait ( ) <EOL> sys . exit ( ) </s>
