help="Reload the server if any file changes") def server(reload=False): "Run the server" if reload: reload_module.reload_me("server") else: waitress.serve(app, host=app.config["HOST"], port=app.config["PORT"], threads=app.config["THREADS"]) def make_shell_context(): return dict(app=app, db=db.db, queue=queue, mail=mail, security=security, docker=docker, applications=applications, machine=machine, compose=compose, network=network) manager.add_command("shell", flask_script.Shell(make_context=make_shell_context)) @flask_migrate.MigrateCommand.command def create(): "Create the database" db_create() def db_create(): name = app.config["DB_NAME"] create_database(name) create_database(name + "_test") def create_database(name): if db.create(name): print("Created {} database".format(name))
def make_shell_context(): return dict(app=app, db=db.db, queue=queue, mail=mail, security=security, docker=docker, applications=applications, machine=machine, compose=compose, network=network) manager.add_command("shell", flask_script.Shell(make_context=make_shell_context)) @flask_migrate.MigrateCommand.command def create(): "Create the database" db_create() def db_create(): name = app.config["DB_NAME"] create_database(name) create_database(name + "_test") def create_database(name):
import tripadvisor import flask_script as script from flask_migrate import Migrate, MigrateCommand from prometheus_flask_exporter.multiprocess import UWsgiPrometheusMetrics from tripadvisor.models import User, Follow, TripAdvisor, Comment,\ Love, Child_cmt, Click, Comment_like app = tripadvisor.create_application() migrate = Migrate(app, tripadvisor.db) manager = script.Manager(app) manager.add_command('runserver', script.Server(host='0.0.0.0', port=8000)) manager.add_command('shell', script.Shell(make_context=lambda: {'current_app': app})) try: metrics = UWsgiPrometheusMetrics(app=app, default_labels={'project': 'hotel'}) metrics.start_http_server(9200) except ModuleNotFoundError: pass def make_shell_context(): return dict(app=app, db=tripadvisor.db, User=User, Follow=Follow, Food=Food, Survey=Survey, TripAdvisor=TripAdvisor)
import flask_script from wg_forge_backend_test import create_application from wg_forge_backend_test.extensions import database from wg_forge_backend_test.cats import models from wg_forge_backend_test.commands import DatabaseFiller from wg_forge_backend_test.conf import Config manager = flask_script.Manager(create_application) manager.add_command("runserver", flask_script.Server()) manager.add_command("shell", flask_script.Shell()) manager.add_command("fill_database", DatabaseFiller()) @manager.shell def make_shell_context(): return dict(app=create_application(), config=Config, db=database, models=models) def main(): manager.run() if __name__ == '__main__': main()