コード例 #1
0
ファイル: __init__.py プロジェクト: vistone/building-server
def create_app(env='Defaults'):
    """
    Creates application.
    :returns: flask application instance
    """
    app = Flask(__name__)
    cfgfile = os.environ.get('BUILDING_SETTINGS')
    if cfgfile:
        app.config.update(load_yaml_config(cfgfile))
    else:
        try:
            cfgfile = (Path(__file__).parent / '..' / 'conf' /
                       'building.yml').resolve()
        except FileNotFoundError:
            logger.warning('no config file found !!')
            sys.exit(1)
    app.config.update(load_yaml_config(str(cfgfile)))
    print(str(cfgfile))
    set_level(app.config['LOG_LEVEL'])
    logger.debug('loading config from {}'.format(cfgfile))

    # load extensions
    if 'URL_PREFIX' in app.config:
        blueprint = Blueprint('api',
                              __name__,
                              url_prefix=app.config['URL_PREFIX'])
    else:
        blueprint = Blueprint('api', __name__)

    api.init_app(blueprint)
    app.register_blueprint(blueprint)
    Session.init_app(app)
    CitiesConfig.init(str(cfgfile))

    return app
コード例 #2
0
ファイル: __init__.py プロジェクト: Oslandia/building-server
def create_app(env='Defaults'):
    """
    Creates application.
    :returns: flask application instance
    """
    app = Flask(__name__)
    cfgfile = os.environ.get('BUILDING_SETTINGS')
    if cfgfile:
        app.config.update(load_yaml_config(cfgfile))
    else:
        try:
            cfgfile = (Path(__file__).parent / '..' / 'conf' / 'building.yml').resolve()
        except FileNotFoundError:
            logger.warning('no config file found !!')
            sys.exit(1)
    app.config.update(load_yaml_config(str(cfgfile)))
    print(str(cfgfile))
    set_level(app.config['LOG_LEVEL'])
    logger.debug('loading config from {}'.format(cfgfile))

    # load extensions
    if 'URL_PREFIX' in app.config:
        blueprint = Blueprint('api', __name__, url_prefix=app.config['URL_PREFIX'])
    else:
        blueprint = Blueprint('api', __name__)

    api.init_app(blueprint)
    app.register_blueprint(blueprint)
    Session.init_app(app)
    CitiesConfig.init(str(cfgfile))

    return app
コード例 #3
0
    # check if the city is within the configuration
    if args.city not in ymlconf_cities:
        print(("ERROR: '{0}' city not defined in configuration file '{1}'"
               .format(args.city, args.cfg)))
        sys.exit()

    # get city configuration
    cityconf = ymlconf_cities[args.city]

    # check if the configuration is well defined for the city
    if (("tablename" not in cityconf) or ("extent" not in cityconf)
            or ("maxtilesize" not in cityconf)):
        print(("ERROR: '{0}' city is not properly defined in '{1}'"
              .format(args.city, args.cfg)))
        sys.exit()

    # open database
    app = type('', (), {})()
    app.config = ymlconf_db
    Session.init_app(app)
    utils.CitiesConfig.init(str(args.cfg))

    # reinitialize the database
    tablename = cityconf['tablename']
    Session.drop_column(tablename, "quadtile")
    Session.drop_column(tablename, "weight")
    Session.drop_bbox_table(tablename)

    # fill the database
    initDB(args.city, cityconf, args.score)
コード例 #4
0
    if args.city not in ymlconf_cities:
        print((
            "ERROR: '{0}' city not defined in configuration file '{1}'".format(
                args.city, args.cfg)))
        sys.exit()

    # get city configuration
    cityconf = ymlconf_cities[args.city]

    # check if the configuration is well defined for the city
    if (("tablename" not in cityconf) or ("extent" not in cityconf)
            or ("maxtilesize" not in cityconf)):
        print(("ERROR: '{0}' city is not properly defined in '{1}'".format(
            args.city, args.cfg)))
        sys.exit()

    # open database
    app = type('', (), {})()
    app.config = ymlconf_db
    Session.init_app(app)
    utils.CitiesConfig.init(str(args.cfg))

    # reinitialize the database
    tablename = cityconf['tablename']
    Session.drop_column(tablename, "quadtile")
    Session.drop_column(tablename, "weight")
    Session.drop_bbox_table(tablename)

    # fill the database
    initDB(args.city, cityconf, args.score)