Ejemplo n.º 1
0
def create_app(test_config=None):
    print("Starting app...")

    app = Flask(__name__, instance_relative_config=True)
    CORS(app)
    CORS(controller.bp)

    if test_config:
        app.config.from_object(test_config)
    else:
        app.config.from_object('config')
        app.config.from_pyfile('config.py', silent=True)

    # ensure the instance folder exists
    try:
        os.makedirs(app.instance_path)
    except OSError:
        pass

    init_db(app)
    init_socket_server(app)
    init_admin(app)

    app.cli.add_command(info)

    # register blueprints
    app.register_blueprint(controller.bp)

    return app
Ejemplo n.º 2
0
def create_app(test_config=None):
    app = Flask(__name__, instance_relative_config=True)

    ca_pub_key, _ = PGPKey.from_file(
        os.path.join(app.root_path, '..', 'key', 'pub.asc'))
    ca_sec_key, _ = PGPKey.from_file(
        os.path.join(app.root_path, '..', 'key', 'sec.asc'))

    assert ca_sec_key.is_protected
    assert ca_sec_key.is_unlocked is False

    app.config.from_mapping(
        SECRET_KEY='sooO0O0Oo0O0oo0OoOOo-s3cur3',
        CA_PUB_KEY=ca_pub_key,
        CA_SEC_KEY=ca_sec_key,
        CA_PASSPHRASE='is521xyz!',
        DB=os.path.join(app.instance_path, 'ca.db'),
    )

    try:
        os.makedirs(app.instance_path)
    except OSError:
        pass

    app.register_blueprint(user.bp)
    app.register_blueprint(cert.bp)

    app.teardown_appcontext(db.close_db)

    if not os.path.isfile(app.config['DB']):
        with app.app_context():
            db.init_db()

    return app
Ejemplo n.º 3
0
def create_server() -> Flask:
    """Create and return the flask server"""
    server = Flask(__name__, static_folder=os.path.join(".", "assets"))

    init_db(server)
    create_endpoints(server)
    create_app(server)

    return server
Ejemplo n.º 4
0
def seed():
    init_db()
    place_count = Place.query.filter().count()
    if place_count == 0:
        db_session.add(
            Place(id="1111",
                  name="木木卡的黑店",
                  longitude="25.066765",
                  latitude="121.526336"))
        db_session.commit()
Ejemplo n.º 5
0
def app():

    app = create_app({
        "TESTING":
        True,
        "DATABASE":
        "postgresql://*****:*****@postgresql_test:5433/prophy_test"
    })

    with app.app_context():
        init_db()

    yield app
Ejemplo n.º 6
0
def app():

    db_fd, db_path = tempfile.mkstemp()

    app = create_app(test_config={
        'SQLALCHEMY_DATABASE_URI': 'sqlite:///{}'.format(db_path)
    })
    with app.app_context():
        db = get_db()
        init_db()

    yield app

    os.close(db_fd)
    os.unlink(db_path)
Ejemplo n.º 7
0
def app():
    db_fd, db_path = tempfile.mkstemp()

    app = create_app({
        'TESTING': True,
        'DATABASE': db_path,
    })

    with app.app_context():
        init_db()
        get_db().executescript(_data_sql)

    yield app

    os.close(db_fd)
    os.unlink(db_path)
Ejemplo n.º 8
0
def main():
    # Conversation Handlers
    updater.dispatcher.add_handler(conversation_handler)

    # Command Handlers
    updater.dispatcher.add_handler(CommandHandler('stop', stop))

    # Message Handlers
    # ...

    init_db(True)
    print({**get_data()})

    if not get_active_queue():
        print(create_queue(is_active=True))

    updater.start_polling()
Ejemplo n.º 9
0
def app():
    """Create and configure a new app instance for each test"""

    # create temporary file to isolate database for each test.
    db_fd, db_path = tempfile.mkstemp()

    # create app with common test config
    app = create_app({'TESTING': True, 'DATABASE': db_path})

    with app.app_context():
        init_db()
        get_db()

    yield app

    # close and remove temporary database
    os.close(db_fd)
    os.unlink(db_path)
Ejemplo n.º 10
0
def create_app(test_config=None):
    app = Flask(__name__, instance_relative_config=True)
    try:
        os.makedirs(app.instance_path)
    except OSError:
        pass
    init_db(app.instance_path)

    @app.route('/hello')
    def hello():
        return 'Welcome to memchess!'

    @app.route('/chess', methods=['POST'])
    def calc():
        content = request.get_json()
        n = content['n']
        piece = content['chessPiece']
        id = piece + '_' + str(n)
        result = get_result(app.instance_path, id)
        if result is not None:
            return f'Result for {id} is {result}'
        print(f"***Job started with id = {id} @{datetime.datetime.now()}")
        insert_into_db(app.instance_path, str(id), 'RUNNING...')
        _task = Process(target=run_task,
                        args=(n, n, piece, str(id), app.instance_path),
                        kwargs={"main_task": True})
        _task.start()
        return f'Use this id to retrieve the result: {id}'

    @app.route('/result', methods=['GET'])
    def result():
        id = request.args.get('id')
        result = get_result(app.instance_path, id)
        return f'Result for {id} is {result}'

    return app
Ejemplo n.º 11
0
#!/usr/bin/python3
"""Project runner."""

import logging

from aiohttp import web

from src.db import init_db
from src.server import APP
from src.settings import BFF_SERVER_HOST, BFF_SERVER_PORT, DEBUG

if __name__ == '__main__':
    init_db()

    log_level = logging.DEBUG if DEBUG else logging.INFO
    logging.basicConfig(level=log_level)

    web.run_app(
        APP,
        port=BFF_SERVER_PORT,
        host=BFF_SERVER_HOST,
        access_log_format='%t %a "%r" %s',
    )
Ejemplo n.º 12
0
def create_db():
    """Test database create."""
    _execute_query('CREATE DATABASE "{0}"'.format(TEST_DB_NAME))
    init_db(TEST_DB_NAME)
    _apply_migrations()
    return DATABASE