Ignore:
Timestamp:
Apr 11, 2020, 4:46:15 PM (7 years ago)
Author:
Joachim Langenbach <joachim.langenbach@…>
Branches:
debian/bullseye, master
Children:
3db3d13
Parents:
da2be70
Message:
  • Added yapf style config (src/python-style.yapf)
    • Updated all files to the yapf formatted version
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/mapservice/server_impl/__init__.py

    rda2be70 r7be94aa  
    2929from .ValidatorWorkaround import ValidatorWorkaround
    3030
     31
    3132def load_config_object(config_name):
    32         return import_string('gnuboat_mapservice.server_impl.Config.{}Config'.format(config_name))
     33    return import_string(
     34        'gnuboat_mapservice.server_impl.Config.{}Config'.format(config_name)
     35    )
     36
    3337
    3438# determine requested configuration
    3539config_file = '/etc/gnuboat/mapservice.conf'
    3640if 'FLASK_ENV' in os.environ and os.environ['FLASK_ENV']:
    37         config_object = load_config_object(os.environ['FLASK_ENV'].title())
     41    config_object = load_config_object(os.environ['FLASK_ENV'].title())
    3842elif os.path.isfile(config_file):
    39         from . import Config as configure
    40         config_object = configure.load_from_file(config_file)
     43    from . import Config as configure
     44    config_object = configure.load_from_file(config_file)
    4145else:
    42         config_object = load_config_object('Production')
     46    config_object = load_config_object('Production')
    4347
    4448app = connexion.App(__name__, specification_dir='../openapi/')
    … …  
    4852celery = Celery(__name__, broker=config_object.CELERY_BROKER_URL)
    4953
     54
    5055@application.before_first_request
    5156def create_database():
    52         @event.listens_for(db.engine, "connect")
    53         def load_spatialite_extension(dbapi_conn, connection_record):
    54                 load_spatialite(dbapi_conn, connection_record)
    55                        
     57    @event.listens_for(db.engine, "connect")
     58    def load_spatialite_extension(dbapi_conn, connection_record):
     59        load_spatialite(dbapi_conn, connection_record)
    5660
    57         if flask.current_app.config['CREATE_TEST_DATABASE'] == True:
    58                 from .demo import DbSetup as demoDbSetup
    59                 demoDbSetup.setup()
    60         else:
    61                 db_setup()
     61    if flask.current_app.config['CREATE_TEST_DATABASE'] == True:
     62        from .demo import DbSetup as demoDbSetup
     63        demoDbSetup.setup()
     64    else:
     65        db_setup()
     66
    6267
    6368@application.route("/mapservice/")
    6469def index():
    65         return render_template('index.html')
     70    return render_template('index.html')
    6671
    67 def setup_app(app_name, config, template_folder = None):
    68         application.json_encoder = encoder.JSONEncoder
    69         app.add_api('openapi.yaml', arguments={'title': app_name}, validate_responses=True, strict_validation=True, validator_map={'response': ValidatorWorkaround})
    70         application.config.from_object(config)
    71        
    72         if 'TEMPLATE_FOLDER' in application.config:
    73                 application.template_folder = application.config['TEMPLATE_FOLDER']
    74         elif template_folder:
    75                 application.template_folder = template_folder
    7672
    77         db.init_app(application)
    78         mail.init_app(application)
    79         celery.config_from_object(config)
     73def setup_app(app_name, config, template_folder=None):
     74    application.json_encoder = encoder.JSONEncoder
     75    app.add_api(
     76        'openapi.yaml',
     77        arguments={'title': app_name},
     78        validate_responses=True,
     79        strict_validation=True,
     80        validator_map={'response': ValidatorWorkaround}
     81    )
     82    application.config.from_object(config)
     83
     84    if 'TEMPLATE_FOLDER' in application.config:
     85        application.template_folder = application.config['TEMPLATE_FOLDER']
     86    elif template_folder:
     87        application.template_folder = template_folder
     88
     89    db.init_app(application)
     90    mail.init_app(application)
     91    celery.config_from_object(config)
Note: See TracChangeset for help on using the changeset viewer.