<s> import os <EOL> import datetime <EOL> import pickle <EOL> from flask import Flask , request , request_tearing_down , session <EOL> from flask . sessions import SecureCookieSessionInterface <EOL> from sqlalchemy . orm import scoped_session <EOL> from acoustid . script import Script <EOL> from acoustid . web import db <EOL> from acoustid . web . views . general import general_page <EOL> from acoustid . web . views . user import user_page <EOL> from acoustid . web . views . apps import apps_page <EOL> from acoustid . web . views . metadata import metadata_page <EOL> from acoustid . web . views . stats import stats_page <EOL> from acoustid . web . views . admin import admin_page <EOL> config_filename = os . environ [ '<STR_LIT>' ] <EOL> script = Script ( config_filename ) <EOL> script . setup_logging ( ) <EOL> config = script . config <EOL> app = Flask ( '<STR_LIT>' ) <EOL> app . config . update ( <EOL> DEBUG = config . website . debug , <EOL> SECRET_KEY = config . website . secret , <EOL> MB_OAUTH_CLIENT_ID = config . website . mb_oauth_client_id , <EOL> MB_OAUTH_CLIENT_SECRET = config . website . mb_oauth_client_secret , <EOL> GOOGLE_OAUTH_CLIENT_ID = config . website . google_oauth_client_id , <EOL> GOOGLE_OAUTH_CLIENT_SECRET = config . website . google_oauth_client_secret , <EOL> ) <EOL> app . acoustid_config = config <EOL> app . session_interface = SecureCookieSessionInterface ( ) <EOL> app . session_interface . serializer = pickle <EOL> @ app . context_processor <EOL> def inject_common_values ( ) : <EOL> show_donate_banner = False <EOL> if datetime . date . today ( ) . month in ( <NUM_LIT:11> , <NUM_LIT:12> ) : <EOL> show_donate_banner = True <EOL> return dict ( <EOL> account_id = session . get ( '<STR_LIT:id>' ) , <EOL> show_maintenace_banner = config . website . maintenance , <EOL> show_donate_banner = show_donate_banner , <EOL> morris_js_version = '<STR_LIT>' , <EOL> raphael_js_version = '<STR_LIT>' , <EOL> bootstrap_version = '<STR_LIT>' , <EOL> jquery_version = '<STR_LIT>' , <EOL> ) <EOL> def get_flask_request_scope ( ) : <EOL> return id ( request . _get_current_object ( ) ) <EOL> @ request_tearing_down . connect <EOL> def close_db_session ( sender , ** kwargs ) : <EOL> db . session . close ( ) <EOL> db . session_factory . configure ( bind = config . database . create_engine ( ) ) <EOL> db . session = scoped_session ( db . session_factory , scopefunc = get_flask_request_scope ) <EOL> app . register_blueprint ( general_page ) <EOL> app . register_blueprint ( user_page ) <EOL> app . register_blueprint ( apps_page ) <EOL> app . register_blueprint ( metadata_page ) <EOL> app . register_blueprint ( stats_page ) <EOL> app . register_blueprint ( admin_page ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> import argparse <EOL> from werkzeug . serving import run_simple <EOL> from werkzeug . wsgi import DispatcherMiddleware <EOL> from werkzeug . contrib . fixers import ProxyFix <EOL> from acoustid . server import make_application as make_api_application <EOL> parser = argparse . ArgumentParser ( ) <EOL> parser . add_argument ( '<STR_LIT>' , action = '<STR_LIT:store_true>' ) <EOL> parser . add_argument ( '<STR_LIT>' , action = '<STR_LIT:store_true>' ) <EOL> parser . add_argument ( '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , action = '<STR_LIT:store_true>' ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , default = '<STR_LIT:127.0.0.1>' ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , default = <NUM_LIT> , type = int ) <EOL> args = parser . parse_args ( ) <EOL> script . setup_console_logging ( ) <EOL> app . debug = True <EOL> run_args = { <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : [ config_filename ] , <EOL> } <EOL> if args . ssl : <EOL> if args . ssl_crt and args . ssl_key : <EOL> run_args [ '<STR_LIT>' ] = args . ssl_crt , args . ssl_key <EOL> else : <EOL> run_args [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> if args . api : <EOL> app = DispatcherMiddleware ( app , { <EOL> '<STR_LIT>' : make_api_application ( config_filename ) , <EOL> } ) <EOL> if args . proxy : <EOL> app = ProxyFix ( app ) <EOL> run_simple ( args . host , args . port , app , ** run_args ) </s>
