def setup(): # type: () -> None global script config_path = os.path.dirname( os.path.abspath(__file__)) + '/../acoustid-test.conf' script = Script(config_path, tests=True) if not os.environ.get('SKIP_DB_SETUP'): with script.context() as ctx: create_tables(ctx.db) prepare_databases(ctx.db) ctx.db.session.commit()
def shell_cmd(config): # type: (str) -> None """Run shell.""" import IPython script = Script(config) script.setup_console_logging() script.setup_sentry() with script.context() as ctx: _ = ctx IPython.embed()
def run_import_cmd(config): # type: (str) -> None """Run import.""" script = Script(config) script.setup_console_logging() script.setup_sentry() run_import(script)
def run_cron_cmd(config): # type: (str) -> None """Run cron.""" script = Script(config) script.setup_console_logging() script.setup_sentry() run_cron(script)
def run_api_cmd(config, workers=None, threads=None): # type: (str, Optional[int], Optional[int]) -> None """Run production uWSGI with the API.""" os.environ['ACOUSTID_CONFIG'] = config script = Script(config) script.setup_console_logging() script.setup_sentry() run_api_app(script.config, workers=workers, threads=threads)
def run_script_cmd(name, config): # type: (str, str) -> None """Run a built-in script.""" script = Script(config) script.setup_console_logging() script.setup_sentry() mod = importlib.import_module('acoustid.scripts.{}'.format(name)) func_name = 'run_{}'.format(name) func = getattr(mod, func_name) func(script, None, None)
def setup(): global script config_path = os.path.dirname( os.path.abspath(__file__)) + '/../acoustid-test.conf' script = Script(config_path, tests=True) if not os.environ.get('SKIP_DB_SETUP'): with closing(script.engine.connect()) as conn: with conn.begin(): if os.environ.get('ACOUSTID_TEST_FULL_DB_SETUP'): conn.execute('CREATE EXTENSION intarray') conn.execute('CREATE EXTENSION pgcrypto') conn.execute('CREATE EXTENSION cube') conn.execute('CREATE EXTENSION acoustid') metadata.create_all(conn) for table in reversed(metadata.sorted_tables): conn.execute(table.delete()) prepare_database(conn, BASE_SQL)
import pickle from flask import Flask, request, request_tearing_down, session from flask.sessions import SecureCookieSessionInterface from sqlalchemy.orm import scoped_session from acoustid.script import Script from acoustid.web import db from acoustid.web.views.general import general_page from acoustid.web.views.user import user_page from acoustid.web.views.apps import apps_page from acoustid.web.views.metadata import metadata_page from acoustid.web.views.stats import stats_page from acoustid.web.views.admin import admin_page config_filename = os.environ['ACOUSTID_CONFIG'] script = Script(config_filename) script.setup_logging() config = script.config app = Flask('acoustid.web') app.config.update( DEBUG=config.website.debug, SECRET_KEY=config.website.secret, MB_OAUTH_CLIENT_ID=config.website.mb_oauth_client_id, MB_OAUTH_CLIENT_SECRET=config.website.mb_oauth_client_secret, GOOGLE_OAUTH_CLIENT_ID=config.website.google_oauth_client_id, GOOGLE_OAUTH_CLIENT_SECRET=config.website.google_oauth_client_secret, ) app.acoustid_config = config
def make_application(config_filename=None, tests=False): if config_filename is None: config_filename = os.environ.get('ACOUSTID_CONFIG') script = Script(config_filename, tests=tests) script.setup_logging() config = script.config app = Flask('acoustid.web') app.config.update( DEBUG=config.website.debug, SECRET_KEY=config.website.secret, MB_OAUTH_CLIENT_ID=config.website.mb_oauth_client_id, MB_OAUTH_CLIENT_SECRET=config.website.mb_oauth_client_secret, GOOGLE_OAUTH_CLIENT_ID=config.website.google_oauth_client_id, GOOGLE_OAUTH_CLIENT_SECRET=config.website.google_oauth_client_secret, ) app.acoustid_script = script app.acoustid_config = config app.acoustid_config_filename = config_filename app.wsgi_app = ProxyFix(app.wsgi_app) sentry_sdk.init(config.sentry.web_dsn, release=GIT_RELEASE, integrations=[FlaskIntegration()]) # can't use json because of python-openid app.session_interface = SecureCookieSessionInterface() app.session_interface.serializer = pickle @app.context_processor def inject_common_values(): show_donate_banner = False if datetime.date.today().month in (11, 12): show_donate_banner = True return dict( account_id=session.get('id'), show_maintenace_banner=config.website.maintenance, show_donate_banner=show_donate_banner, morris_js_version='0.5.1', raphael_js_version='2.1.4', bootstrap_version='3.3.6', jquery_version='1.12.0', ) def get_flask_request_scope(): try: return id(request._get_current_object()) except RuntimeError: return 0 @app.teardown_request def close_db_session(*args, **kwargs): db.session.remove() @app.route('/_health') def health(): from acoustid.api import get_health_response return get_health_response(script, request, require_master=True) @app.route('/_health_docker') def health_docker(): from acoustid.api import get_health_response return get_health_response(script, request) db.configure(script, get_flask_request_scope) app.register_blueprint(general_page) app.register_blueprint(user_page) app.register_blueprint(apps_page) app.register_blueprint(metadata_page) app.register_blueprint(stats_page) app.register_blueprint(admin_page) return app
import os import pickle from flask import Flask, request, request_tearing_down, session from flask.sessions import SecureCookieSessionInterface from sqlalchemy.orm import scoped_session from acoustid.script import Script from acoustid.web import db from acoustid.web.views.general import general_page from acoustid.web.views.user import user_page from acoustid.web.views.apps import apps_page from acoustid.web.views.metadata import metadata_page from acoustid.web.views.stats import stats_page config_filename = os.environ['ACOUSTID_CONFIG'] script = Script(config_filename) script.setup_logging() config = script.config app = Flask('acoustid.web') app.config.update( DEBUG=config.website.debug, SECRET_KEY=config.website.secret, MB_OAUTH_CLIENT_ID=config.website.mb_oauth_client_id, MB_OAUTH_CLIENT_SECRET=config.website.mb_oauth_client_secret, GOOGLE_OAUTH_CLIENT_ID=config.website.google_oauth_client_id, GOOGLE_OAUTH_CLIENT_SECRET=config.website.google_oauth_client_secret, ) app.acoustid_config = config
def run_cron_cmd(config): """Run cron.""" script = Script(config) script.setup_console_logging() script.setup_sentry() run_cron(script)
def run_api_cmd(config, workers): """Run production uWSGI with the API.""" script = Script(config) script.setup_console_logging() script.setup_sentry() run_api_app(script.config, workers=workers)