Example #1
0
def test_init_app_converts_truthy_to_bool(notify_api, os_environ, notify_config):
    notify_api.config['MY_SETTING'] = True
    os_environ.update({'MY_SETTING': 'false'})

    init_app(notify_api)

    assert notify_api.config['MY_SETTING'] is False
Example #2
0
def test_init_app_updates_known_config_options(notify_api, os_environ, notify_config):
    notify_api.config['MY_SETTING'] = 'foo'
    os_environ.update({'MY_SETTING': 'bar'})

    init_app(notify_api)

    assert notify_api.config['MY_SETTING'] == 'bar'
Example #3
0
 def setUp(self):
     """Before each test, set up a blank database"""
     self.project = create_app()
     init_app(self.project, 'test')
     self.app = self.project.test_client()
     with self.project.test_request_context():
         create_db(self.project)
         clear_db(self.project)
Example #4
0
def shell(config):
    """
    run flask shell
    """
    init_app(config)
    from app import config, db
    from app.models import User
    shell = Shell(make_context=lambda: dict(app=app, config=config, db=db, User=User))
    shell.run(True, False)
Example #5
0
File: run.py Project: MoXoCo/one
def init_db():
    # 必须初始化 app 才能操作数据库
    app = init_app()
    db = models.db
    db.drop_all()
    db.create_all()
    log('db has already init')
 def test_app_initialization(self):
     '''
     Test whether the init_app method returns
     an instance of class Amity
     '''
     result = app.init_app()
     self.assertIsInstance(result, Amity)
Example #7
0
def rebuild_db():
    # 必须初始化 app 才能操作数据库
    application = init_app()
    db = models.db
    db.drop_all()
    db.create_all()
    print('auth rebuild database')
Example #8
0
    def create_app(self):
        (app, _, _) = init_app()

        for attr in dir(self):
            if not attr.isupper() or attr.startswith('_'):
                continue
            setattr(self, 'original_{0}'.format(attr), app.config.get(attr))
            app.config[attr] = getattr(self, attr)

        return app
Example #9
0
File: run.py Project: MoXoCo/one
def update():
    app = init_app()
    one_index = One_Index_Spider()
    # one的格式是 { url_num: [title, content, img]}
    one = one_index.run
    for key, value in one.items():
        if not models.Post.query.filter_by(url_num=int(key)).first():
            post = models.Post()
            post.url_num = key
            post.title, post.content, post.img = value
            post.save()
        else:
            log('{} 已在数据库中'.format(key))
Example #10
0
def main(argv=None):

    if not argv:
        argv = sys.argv[1:]

    options = parse_args(argv)

    app = init_app(options.config)

    if options.shell:
        script.make_shell(make_shell, use_ipython=True)
    else:
        app.run(host=options.host, port=int(options.port))

    return 0
from app import init_app, redirect
from dotenv import load_dotenv
load_dotenv()
import os
import requests
import urllib.parse as urlparse
from flask import (Flask, render_template, request, redirect, session, url_for,
                   make_response, jsonify)

# jos ei halua käyttää oraclea lokaalisti, voi säätää app=init_app("sqlite")

app = init_app("oracle")
#app = init_app("sqlite")

port = int(os.environ.get("PORT", 3000))

app.secret_key = 'supersecret'


@app.route('/')
def index():
    return app.send_static_file('index.html')


if __name__ == '__main__':
    app.run(debug=True, host='127.0.0.1', port=port)
Example #12
0
def run():
    config = dict(
        # host = '0.0.0.0',
        # port = 3000,
        debug=True, )
    init_app().run(**config)
Example #13
0
from aiohttp import web
import app
import config

app = app.init_app(argv=None)
web.run_app(app, port=config.PORT)

if __name__ == '__main__':
    web.run_app(app, port=config.PORT)
Example #14
0
def run():
    flask_app.app_context().push()
    init_app()
    flask_app.run(debug=True, host='0.0.0.0')
Example #15
0
def create_app():
    from app import init_app

    return init_app(debug=True)
Example #16
0
def runserver(host, port, config):
    """
    run server
    """
    init_app(config)
    app.run(host, port)
Example #17
0
#!/usr/bin/env python

import os
import random
import readline
from pprint import pprint
from mpd import MPDClient

client = MPDClient()
client.connect("localhost", 6600)
from flask import *

print("Flask imported")
from app import init_app
import helpers

print("Helpers imported")
import extensions as ext

print("Extensions imported")

app = init_app("settings_dev.py")
print("app initialized")
os.environ["PYTHONINSPECT"] = "True"


def show(obj):
    """Show the dump of the properties of the object."""
    pprint(vars(obj))
Example #18
0
import sys
import logging
from config import DevConfig, TestConfig, ProdConfig
from app import init_app
from app.error_handling import AppFailureException
from app.constants import APP_FAILURE

if __name__ == '__main__':
    app = None
    if len(sys.argv) == 2:
        environment = sys.argv[1]
        if environment == 'prod':
            app = init_app(ProdConfig)
        elif environment == 'test':
            app = init_app(TestConfig)
        elif environment == 'dev':
            app = init_app(DevConfig)
    else:
        app = init_app(DevConfig)

    try:
        app.run(host='0.0.0.0')
    except AppFailureException:
        logging.error(APP_FAILURE)
Example #19
0
async def client(test_client):
    """Создаем фикстуру клиента."""
    app = init_app()
    return await test_client(app)
Example #20
0
#!/usr/bin/env python3

# @FileName : wsgi.py
# @作者 : Liu
# @日期 : 2019年05月30日
# @时间 : 11时08分

from app import init_app

application = init_app('default')

if __name__ == '__main__':
    application.run()
Example #21
0
#!/usr/bin/env python

import app
# from config import production_config as config
from config import developer_config as config
from flask_sslify import SSLify

app = app.init_app(config)
sslify = SSLify(app)

if __name__ == '__main__':
    app.run(host='0.0.0.0', debug=True)
Example #22
0
import sys

from app import app, init_app
from embed import embed_for_training
from train import train

TRAIN_DATA_PATH = "data/BiLSTM_train_data.csv"
VALIDATION_DATA_PATH = "data/BiLSTM_validation_data.csv"
EMBEDDING_PATH = "embeding/GoogleNews-vectors-negative300"
MODEL_PATH = "model"
RESPONSE_DATA_PATH = "data/response_data.csv"

PORT = 22370

if __name__ == "__main__":
    if len(sys.argv) < 2 or sys.argv[1] not in ["train", "serve"]:
        sys.exit("Expect argument [train|serve]")

    if sys.argv[1].lower() == "train":
        x_train, y_train, x_validation, y_validation, embeddings = embed_for_training(
            TRAIN_DATA_PATH, VALIDATION_DATA_PATH, EMBEDDING_PATH)
        model = train(x_train, y_train, x_validation, y_validation, embeddings)
        model.save(MODEL_PATH)
    if sys.argv[1].lower() == "serve":
        init_app(MODEL_PATH, RESPONSE_DATA_PATH)
        app.run(host="0.0.0.0", port=PORT)
Example #23
0
#!/bin/env python
from app import init_app, socketio

app = init_app(debug=True)

if __name__ == '__main__':
    socketio.run(app, host='0.0.0.0')
Example #24
0
 def create_app(self):
     init_app()
     return app
Example #25
0
from app import init_app
from app import socketio
from app.config import config

app = init_app(config['dev'])
print(app.config)

if __name__ == '__main__':
    if app.debug:
        socketio.run(app, port=7659, host='0.0.0.0')
    else:
        # gevent is supported in a number of different configurations.
        # The long-polling transport is fully supported with the gevent package,
        # but unlike eventlet, gevent does not have native WebSocket support.
        # To add support for WebSocket there are currently two options.
        # Installing the gevent-websocket package adds WebSocket support to gevent or one can use the uWSGI web server,
        # which comes with WebSocket functionality. The use of gevent is also a performant option,
        #  but slightly lower than eventlet.

        socketio.run(app, port=7659, host='0.0.0.0')
Example #26
0
from app import init_app  # noqa
app = init_app()  # noqa
Example #27
0
def run():
    config = dict(debug=True, )
    init_app().run(**config)
Example #28
0
def run():
    config = dict(
        debug=True,
        host='0.0.0.0'
    )
    init_app().run(**config)
Example #29
0
#coding=utf-8
from app import DebugConfig, init_app, gevent_run
import os

basedir = os.path.dirname(os.path.abspath(__file__)) or "."


class MyConfig(DebugConfig):
    # override default Configs
    SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(basedir, 'app.db')
    LOGGING_FILE = os.path.join(basedir, "logs", "app.log")
    UPLOAD_DIR = os.path.join(basedir, "uploads")


app = init_app(MyConfig)

if __name__ == "__main__":
    # for debug only
    gevent_run(app, "0.0.0.0", 5000)
Example #30
0
 def setUp(self):
     init_app(app)
     self.app = app.test_client()
Example #31
0
#!/usr/bin/env python3

# @FileName : manager.py
# @作者 : Liu
# @日期 : 2019年05月10日
# @时间 : 11时29分
from flask_script import Manager
from flask_migrate import Migrate, MigrateCommand, upgrade, migrate
from app import init_app, db

app = init_app('production')
manger = Manager(app)
migrates = Migrate(app, db=db)
manger.add_command('db', MigrateCommand)


@manger.command
def dev():
    from livereload import Server
    liver_server = Server(app.wsgi_app)
    liver_server.watch('**/*.*')
    liver_server.serve(open_url_delay=True)


@manger.command
def test():
    pass


@manger.command
def update_db():
Example #32
0
def test_init_app_ignores_unknown_options(notify_api, os_environ,
                                          notify_config):
    os_environ.update({'MY_OTHER_SETTING': 'bar'})

    init_app(notify_api)
    assert 'MY_OTHER_SETTING' not in notify_api.config
Example #33
0
    ap.add_argument('-p', '--port', default=5000)
    ap.add_argument('-c', '--config', default="settings_prod.py")
    ap.add_argument('-s', '--shell',  action='store_true', default=False)

    args = ap.parse_args(args_list)
    return args


def main(argv=None):

    if not argv:
        argv = sys.argv[1:]

    options = parse_args(argv)

    app = init_app(options.config)

    if options.shell:
        script.make_shell(make_shell, use_ipython=True)
    else:
        app.run(host=options.host, port=int(options.port))

    return 0


if __name__ == '__main__':
    status = main()
    sys.exit(status)
else:
    app = init_app('settings_prod.py')
Example #34
0
#import sys
#import os

#with open('/data/UCF/demo/logs/sysinfo.txt', 'w') as f:
    #f.write(str(sys.version_info[0]) + '\n')
    #f.write(str(sys.path))

from app import init_app 
import os

init_app('config.BasicConfig')

from app import app

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=8007)
Example #35
0
def test_init_app_ignores_unknown_options(notify_api, os_environ, notify_config):
    os_environ.update({'MY_OTHER_SETTING': 'bar'})

    init_app(notify_api)
    assert 'MY_OTHER_SETTING' not in notify_api.config
Example #36
0
                        dest='host',
                        type=str,
                        default='0.0.0.0',
                        help='Host you want to use for deployment')
    parser.add_argument('-c',
                        '--config',
                        dest='config_path',
                        type=str,
                        default=None,
                        help='Custom config you want to load')

    return parser.parse_args()


if __name__ == '__main__':

    args = get_arguments()

    custom_config = None
    # Loads custom config based on file path of the config.json file
    if args.config_path:
        custom_config = load_custom_config(args.config_path)

    app = init_app(custom_config)

    app.run(host=args.host,
            port=args.port,
            use_reloader=bool(args.reloader),
            threaded=True,
            debug=bool(args.debugger))
Example #37
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2017/2/16 上午10:36
# @Author  : Rain
# @Desc    : 程序启动类:python manager runserver
# @File    : manager.py

import os
from flask_script import Manager, Server
from app import init_app
from sqlalchemy import create_engine
from sqlalchemy_utils import database_exists, create_database
from flask_migrate import MigrateCommand
from app.utils.utils import generate_password

instance = init_app(os.getenv('config', 'development'))
manager = Manager(instance)
manager.add_command("runserver", Server(host="0.0.0.0"))
manager.add_command('db', MigrateCommand)


@manager.command
def create_db():
    engine = create_engine(instance.config['SQLALCHEMY_DATABASE_URI'],
                           convert_unicode=True)
    if not database_exists(engine.url):
        create_database(engine.url)


@manager.command
def gen_secret():
Example #38
0
from flask import render_template

from app import init_app
from flask import request

from app.views.actor import get_frequent_cooperation_by_id

app = init_app()  # 创建app


@app.route('/', methods=['GET', 'POST'])
def login():
    return render_template("login.html", errors="")


if __name__ == '__main__':
    app.run()
Example #39
0
from app import app, init_app

app.config.from_object("config.Config")
init_app()
if __name__ == "__main__":
    app.run(host=app.config["HOST"])
Example #40
0
def rebuild_db():
    app = init_app()
    db = models.db
    db.drop_all()
    db.create_all()
    print('auth rebuild database')
Example #41
0
 def create_app(self):
     init_app()
     return app
Example #42
0
import logging

logging.basicConfig(level=logging.DEBUG)
from app import init_app

app = init_app()
from app import init_app, redirect
from dotenv import load_dotenv
load_dotenv()
import os
import requests
import urllib.parse as urlparse
from flask import (Flask, render_template, request, redirect, session, url_for,
                   make_response, jsonify)

app = init_app("sqlite")

port = int(os.environ.get("PORT", 3000))

app.secret_key = 'supersecret'


@app.route('/')
def index():
    return app.send_static_file('index.html')


if __name__ == '__main__':
    app.run(debug=True, host='127.0.0.1', port=port)
Example #44
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import pytest
import json
from app import init_app
from globals import config
from db import redis_client
from sqlalchemy_utils import database_exists, drop_database

runner = init_app().test_cli_runner()
admin_token = runner.invoke(args=['generate_admin_jwt', 'josh']).output


# scope: Run once per test function. The setup portion is run before each test using the fixture.
# autouse: Invoke fixture automatically without declaring a function argument explicitly.
@pytest.fixture(scope='function', autouse=True)
def setup_api(request):
	# Init HTTP web server
	app = init_app()
	# Create and delete database
	if not database_exists(config.DATABASE_URL):
		runner.invoke(args=['create_tables'])

	def tear_down():
		drop_database(config.DATABASE_URL)

	request.addfinalizer(tear_down)
	testing_client = app.test_client()
	return testing_client

Example #45
0
from app import app, init_app

init_app()

if __name__ == '__main__':
    app.run()
Example #46
0
def cleardb(config=None):
    init_app(flask_app, config)
    clear_db(flask_app)
Example #47
0
def main():
    app = init_app()
    web.run_app(app)
Example #48
0
from app import init_app
from cache import cache

mono_app = init_app('config.py')
Example #49
0
def run(config=None):
    """Run local server."""
    init_app(flask_app, config)
    flask_app.run()
Example #50
0
def run():
    config = dict(
        debug=True,
    )
    init_app().run(**config)
Example #51
0
import logging

from app import init_app, create_root
from tools.config_properties import init_config, get_config
from tools.logger_tag import LoggerTag


def create_logger():
    logger = logging.getLogger('tag')
    logger.level = logging.DEBUG
    handler = logging.StreamHandler()
    handler.setLevel(logger.level)
    handler.setFormatter(
        logging.Formatter(
            '%(asctime)s - %(tag)s - %(levelname)s - %(message)s'))
    logger.addHandler(handler)


if __name__ == '__main__':

    create_logger()
    LoggerTag('app').info('Run application')

    init_config()
    application = init_app()
    config = get_config()
    create_root(config.get_root_email(), config.get_root_password())
    application.run(host='0.0.0.0', port=8000)
Example #52
0
from flask_script import Manager, Server, prompt, prompt_pass
from fuzzywuzzy import fuzz
from unidecode import unidecode
from watchdog.events import FileSystemEventHandler
from watchdog.observers import Observer

from app import app, init_app, version, Roles
from app.extensions import db, jsglue
from app.models.education import Education
from app.models.group import Group
from app.models.navigation import NavigationEntry
from app.models.role_model import GroupRole
from app.models.setting_model import Setting
from app.models.user import User

init_app(query_settings=False)

migrate = Migrate(app, db)
versionbump = Manager(
    help="Apply a version bump",
    description=("Apply a version bump. "
                 "Versioning works using the following format: "
                 "SYSTEM.FEATURE.IMPROVEMENT.BUG-/HOTFIX"))
administrators = Manager(
    help="Add or remove users from the administrators group",
    description="Add or remove users from the administrators group")

manager = Manager(app, description="Manager console for viaduct")
manager.add_command("runserver", Server())
manager.add_command('db', MigrateCommand)
manager.add_command('versionbump', versionbump)
Example #53
0
import asyncio
from aiohttp import web
from app import init_app

if __name__ == '__main__':
    try:
        loop = asyncio.get_event_loop()
        app = loop.run_until_complete(init_app())
        print('Server started')
        web.run_app(app)
        print('Server was stopped')
    except Exception as e:
        print(e)
Example #54
0
def initdb(config=None):
    """Create DB from scratch"""
    init_app(flask_app, config)
    create_db(flask_app)
 def setUp(self):
     self.app = app.init_app()
     self.app.config['TESTING'] = True
     self.app.config['LOGIN_RATE_LIMIT'] = '1/minute'
Example #56
0
#!/usr/bin/env python

from app import create_app, init_app
from flask.ext.script import Manager, Shell

app = init_app()
manager = Manager(app)


@manager.command
def create():
	app = create_app()

@manager.command
def runserver():
	app.run(host='0.0.0.0', port=83, debug=True)

if __name__ == "__main__":
	manager.run()
Example #57
0
from app import init_app

application = init_app()

if __name__ == '__main__':
    application.run()