Esempio n. 1
0
def app_valid(config_valid, db_session):
    LOGGER = logging.getLogger('lorem-ipsum')
    LOGGER.setLevel(logging.DEBUG)
    import app
    flask_app = Flask('lorem-ipsum')
    app.create_flask_app(flask_app)
    with app.app.test_request_context():
        yield flask_app
Esempio n. 2
0
def app(database: str):
    test_app = create_flask_app({
        "BCRYPT_LOG_ROUNDS":
        10,
        "SECRET_KEY":
        environ["FLASK_SECRET_KEY"],
        "SQLALCHEMY_TRACK_MODIFICATIONS":
        False,
        "SQLALCHEMY_DATABASE_URI":
        f"sqlite:///{database}",
    })
    return test_app
Esempio n. 3
0
def app(request):
    """Creates test app"""
    app = create_flask_app(__name__, 'test_config.Config')

    # Establish an application context before running the tests.
    ctx = app.app_context()
    ctx.push()

    def teardown():
        ctx.pop()

    request.addfinalizer(teardown)
    return app
Esempio n. 4
0
from app import create_flask_app
from common_constants.constants import FLASK_CONFIG_MODULE
from database import session
from restful_apis import create_restful_api
from utils import config_logger
from flask_jwt_extended import JWTManager

app = create_flask_app('Flask Jwt')
app.config.from_object(FLASK_CONFIG_MODULE)
app.config['JWT_SECRET_KEY'] = 'demo_app'
jwt = JWTManager(app)
app.config['JWT_HEADER_TYPE'] = 'JWT'

config_logger(app)
create_restful_api(app)


def close_session(resp):
    session.close()  # used to remove actual session
    # session.remove() https://groups.google.com/forum/#!msg/sqlalchemy/twoHzgXcR60/nZqMKkCz9UwJ
    return resp

app.teardown_request(close_session)
app.teardown_appcontext(close_session)


if __name__ == '__main__':
    app.run()
Esempio n. 5
0
from time import time
from datetime import datetime

from apscheduler.schedulers.background import BackgroundScheduler

from app import create_flask_app
from Database.redis import check_actual_users_redis

scheduler = BackgroundScheduler()

scheduler.add_job(func=check_actual_users_redis, trigger="interval", minutes=60)

scheduler.start()

if __name__ == "__main__":
    create_flask_app().run(host='0.0.0.0')
Esempio n. 6
0
def main():
    args = docopt(__doc__, version='zenfeed ' + VERSION)

    log_arg, log_level = args['--log'].rsplit(':', 1)
    if log_arg not in ('stderr', 'syslog'):
        setup_logger(type='file',
                     filename=path(log_arg).abspath(),
                     level=log_level)
    else:
        setup_logger(type=log_arg, level=log_level)

    logger.info('Zenfeed %s booting...', VERSION)

    if args['genstatic']:
        return genstatic(args['PATH'])

    port = int(args['--port'])

    cache_disabled = args['--no-cache']

    path_prefix = args['--prefix']
    if path_prefix.endswith('/'):
        path_prefix = path_prefix[:-1]
    if path_prefix and not path_prefix.startswith('/'):
        path_prefix = '/' + path_prefix

    fixed_language = args['--lang']
    if fixed_language == 'browser':
        fixed_language = None
    else:
        logger.info('Language fixed to "%s"', fixed_language)
        if (fixed_language not in LANGUAGES
                and fixed_language.split('_', 1)[0] not in LANGUAGES):
            return logger.critical('Fixed language not supported !')

    fixed_timezone = args['--tz']
    logger.info('Timezone fixed to "%s"', fixed_timezone)
    if fixed_timezone not in all_timezones:
        return logger.critical('Fixed timezone not supported !')

    db_uri = args['--database']
    if db_uri == ':memory:':
        db_uri = 'sqlite://'
    elif not "://" in db_uri:
        db_uri = 'sqlite:///%s' % path(db_uri).abspath()

    import app as app_module
    app = app_module.create_flask_app(prefix=path_prefix)
    app.config.update(
        DEBUG=args['--debug'],
        SQL_DEBUG=False,
        SECRET_KEY=urandom(32),
        SQLALCHEMY_DATABASE_URI=db_uri,
        FAVICON_DIR=path(args['--favicons']).abspath(),
        FIXED_LANGUAGE=fixed_language,
        FIXED_TIMEZONE=fixed_timezone,
        CACHE_ENABLED=not cache_disabled,
        PATH_PREFIX=path_prefix,
    )
    Cache(app)

    from models import setup_tables, Feed
    patch_socket()
    patch_ssl()
    setup_tables()

    from deadline_manager import deadlineManager
    import views
    from werkzeug.contrib.fixers import ProxyFix
    app.wsgi_app = ProxyFix(app.wsgi_app)

    feeds = Feed.query.all()
    deadlineManager.favicon_dir = path(args['--favicons']).abspath()
    deadlineManager.launch_deadline_workers(feeds)
    deadlineManager.start()

    logger.info("Server started at port %d (prefix: %s/)", port, path_prefix)
    if args['--debug']:
        logger.warning("DEBUG mode activated")
        app.run(host='0.0.0.0', port=port, debug=True)
    else:
        from gevent.wsgi import WSGIServer
        http_server = WSGIServer(('0.0.0.0', port), app)
        try:
            http_server.serve_forever()
        except KeyboardInterrupt:
            pass
Esempio n. 7
0
import logging
import os

if __name__ == "__main__" or __name__ == 'app' and os.getenv('env') != 'test':
    import json

    print('Running local app...')
    with open(f"{os.path.expanduser('~')}/.cloud-projects/lorem-ipsum-local-integration.json", "r") as _file:
        json = dict(json.load(_file))
        print(json)
        for k, v in json.items():
            os.environ[k] = str(v)
    os.environ['env'] = 'test'
    import app

    flask_app = app.create_flask_app()
    LOGGER = logging.getLogger('lorem-ipsum')
    LOGGER.setLevel(logging.DEBUG)
    from lorem_ipsum.search_engine import SearchEngine
    SearchEngine.start_search_engine()
    flask_app.run(port=5000, debug=False)

Esempio n. 8
0
def main():
    args = docopt(__doc__, version='zenfeed ' + VERSION)

    log_arg, log_level = args['--log'].rsplit(':', 1)
    if log_arg not in ('stderr', 'syslog'):
        setup_logger(type='file', filename=path(log_arg).abspath(),
                     level=log_level)
    else:
        setup_logger(type=log_arg, level=log_level)

    logger.info('Zenfeed %s booting...', VERSION)

    if args['genstatic']:
        return genstatic(args['PATH'])

    port = int(args['--port'])

    cache_disabled = args['--no-cache']

    path_prefix = args['--prefix']
    if path_prefix.endswith('/'):
        path_prefix = path_prefix[:-1]
    if path_prefix and not path_prefix.startswith('/'):
        path_prefix = '/' + path_prefix

    fixed_language = args['--lang']
    if fixed_language == 'browser':
        fixed_language = None
    else:
        logger.info('Language fixed to "%s"', fixed_language)
        if (fixed_language not in LANGUAGES
            and fixed_language.split('_', 1)[0] not in LANGUAGES):
            return logger.critical('Fixed language not supported !')

    fixed_timezone = args['--tz']
    logger.info('Timezone fixed to "%s"', fixed_timezone)
    if fixed_timezone not in all_timezones:
        return logger.critical('Fixed timezone not supported !')

    db_uri = args['--database']
    if db_uri == ':memory:':
        db_uri = 'sqlite://'
    elif not "://" in db_uri:
        db_uri = 'sqlite:///%s' % path(db_uri).abspath()

    import app as app_module
    app = app_module.create_flask_app(prefix=path_prefix)
    app.config.update(
        DEBUG = args['--debug'],
        SQL_DEBUG = False,
        SECRET_KEY = urandom(32),
        SQLALCHEMY_DATABASE_URI = db_uri,
        FAVICON_DIR = path(args['--favicons']).abspath(),
        FIXED_LANGUAGE = fixed_language,
        FIXED_TIMEZONE = fixed_timezone,
        CACHE_ENABLED = not cache_disabled,
        PATH_PREFIX = path_prefix,
    )
    Cache(app)

    from models import setup_tables, Feed
    patch_socket()
    patch_ssl()
    setup_tables()

    from deadline_manager import deadlineManager
    import views
    from werkzeug.contrib.fixers import ProxyFix
    app.wsgi_app = ProxyFix(app.wsgi_app)

    feeds = Feed.query.all()
    deadlineManager.favicon_dir = path(args['--favicons']).abspath()
    deadlineManager.launch_deadline_workers(feeds)
    deadlineManager.start()

    logger.info("Server started at port %d (prefix: %s/)", port, path_prefix)
    if args['--debug']:
        logger.warning("DEBUG mode activated")
        app.run(host='0.0.0.0', port=port, debug=True)
    else:
        from gevent.wsgi import WSGIServer
        http_server = WSGIServer(('0.0.0.0', port), app)
        try:
            http_server.serve_forever()
        except KeyboardInterrupt:
            pass
Esempio n. 9
0
 def create_app(self):
     return create_flask_app('testing')
Esempio n. 10
0
import os

if __name__ == "__main__" or __name__ == 'app' and os.getenv('env') != 'test':
    import json

    print('Running local app...')
    with open(f"{os.path.expanduser('~')}/.cloud-projects/lorem-ipsum-local.json", "r") as _file:
        json = dict(json.load(_file))
        print(json)
        for k, v in json.items():
            os.environ[k] = str(v)
    import app

    app.create_flask_app().run(port=5000, debug=True)
Esempio n. 11
0
"""
Application Main Manage Module

flask 웹 어플리케이션을 실행시키기 위한 메인 코드입니다. 
flask application 객체를 생성하고, 각종 shell context 설정 및 cli command 설정을 담당합니다.
"""

from config import config
from app import create_flask_app

application = create_flask_app(config)
Esempio n. 12
0
from app import create_flask_app
from script import init_scripts
from worker import init_workers
import config
import worker
import task
import threading
import time


if __name__ == '__main__':
    config.load_config()
    flask_app = create_flask_app()
    flask_app.config['SECRET_KEY'] = '66666666666'
    init_scripts()
    init_workers()
    flask_app.run(port=2333, debug=True)
    task.stop_all()
    worker.shutdown()

Esempio n. 13
0
                                      fallback=8000)
    max_workers = config_ini.getint('General', 'max_workers', fallback=0)
    timeout = config_ini.getint('General', 'timeout', fallback=120)

else:
    sys.exit(1)

from app import db
from app import logger
from app import create_flask_app
from app import babel

C = Context("Collector Web Server", config_file, logger)
C.Set()

app = create_flask_app('Collector', config_file)
# GV GV Defines templates globals !!!!
app.add_template_global(name='current_app', f=current_app)
# GV CONFIGURATION PATCH !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

logger.name = "Collector Web Server"
# GV Setup logger handlers
# GV Actual File system all logger -------------------------------------
file_handler = add_Logging_Handler(logger=logger,
                                   level=C.log_level,
                                   folder=C.log_folder,
                                   nameFormat="%s.log" %
                                   logger.name.replace(' ', '_'),
                                   handlerType='TIME_ROTATING')
# GV Default File logger filters (omits) AUDIT records, then an audit
# GV logger needs to be defined