Exemple #1
0
                         help="a .conf file (required)")
    return parser


if __name__ == '__main__':
    build_parser ().parse_args (namespace = args)
    config = config_from_pyfile (args.profile)

    init_logging (
        args,
        logging.StreamHandler (), # stderr
        logging.FileHandler ('load_edits.log')
    )

    parameters = dict ()
    db = db_tools.PostgreSQLEngine (**config)

    tree = lxml.etree.parse (args.input if args.input != '-' else sys.stdin)

    with db.engine.begin () as conn:
        db_tools.truncate_editor_tables (conn)

    log (logging.INFO, "Loading cliques ...")

    with db.engine.begin () as conn:
        values = []
        for row in tree.xpath ('/sql/export_cliques/row'):
            values.append ({ e.tag : e.text for e in row })

        execute (conn, """
        TRUNCATE import_cliques;
Exemple #2
0
def create_app(Config):
    """ App creation function """

    instance_path = os.path.abspath('instance')

    app = flask.Flask(__name__)

    global_config = os.path.join(instance_path, Config.CONFIG_FILE)
    app.config.from_object(Config)
    app.config.from_pyfile(global_config)

    # pylint: disable=no-member
    app.logger.setLevel(Config.LOG_LEVEL)
    app.logger.info("Instance path: {ip}".format(ip=instance_path))

    app.register_blueprint(static.bp)
    app.register_blueprint(login.bp)

    app.config.dba = db_tools.PostgreSQLEngine(**app.config)
    user_db_url = app.config.dba.url
    # tell flask_sqlalchemy where the user authentication database is
    app.config['SQLALCHEMY_DATABASE_URI'] = user_db_url

    static.init_app(app)
    do_init_app(app)

    instances = collections.OrderedDict()
    extra_files = [instance_path + '/' + Config.CONFIG_FILE]

    for fn in glob.glob(instance_path + '/*.conf'):
        extra_files.append(fn)
        fn = os.path.basename(fn)
        if fn == Config.CONFIG_FILE:
            continue

        sub_app = flask.Flask(__name__)
        sub_app.config.from_object(Config)
        sub_app.config.from_pyfile(global_config)
        sub_app.config.from_pyfile(os.path.join(instance_path, fn))
        sub_app.config['CONFIG_FILE'] = fn
        sub_app.config['APPLICATION_DIR'] = sub_app.config['APPLICATION_ROOT']
        sub_app.config['APPLICATION_ROOT'] = os.path.join(
            app.config['APPLICATION_ROOT'], sub_app.config['APPLICATION_ROOT'])
        sub_app.register_blueprint(main.bp)
        sub_app.register_blueprint(textflow.bp)
        sub_app.register_blueprint(comparison.bp)
        sub_app.register_blueprint(editor.bp)
        sub_app.register_blueprint(set_cover.bp)
        sub_app.register_blueprint(checks.bp)

        sub_app.config.dba = db_tools.PostgreSQLEngine(**sub_app.config)
        sub_app.config['SQLALCHEMY_DATABASE_URI'] = user_db_url

        do_init_app(sub_app)
        main.init_app(sub_app)
        textflow.init_app(sub_app)
        comparison.init_app(sub_app)
        editor.init_app(sub_app)
        set_cover.init_app(sub_app)
        checks.init_app(sub_app)

        instances[sub_app.config['APPLICATION_ROOT']] = sub_app

    info_app = flask.Flask(__name__)
    info_app.config.update(app.config)
    info_app.register_blueprint(info.bp)
    do_init_app(info_app)
    info.init_app(app, instances)

    instances[app.config['APPLICATION_ROOT']] = info_app

    d = DispatcherMiddleware(app, instances)
    d.config = app.config
    d.config['EXTRA_FILES'] = extra_files
    return d