Changeset 5c9c247 for src


Ignore:
Timestamp:
Apr 10, 2020, 7:50:13 PM (7 years ago)
Author:
Joachim Langenbach <joachim.langenbach@…>
Branches:
debian/bullseye, master
Children:
a2b8052
Parents:
ae2ff15
Message:

To find the template files, when started per installed package and per module from src-gen

  • Folder for templates is now set (in the descending priority)
    • per Config option TEMPLATE_FOLDER
    • per template_folder optional argument to setup_app(). The option is set by main.py (see mustache)

For tests the template_folder is set by init.py from test folder (s. inittest.mustache)

Location:
src/mapservice
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/mapservice/codegen/code_generator

    rae2ff15 r5c9c247  
    5757chmod +x "${CELERY_WORKER_SCRIPT}"
    5858
     59# bash script to install gnuboat_common from this repository before other dependencies
    5960echo "#!/bin/bash" > "${TOX_INSTALL_COMMAND}"
    6061echo 'pip install --editable=file:///`pwd`/../../common' >> "${TOX_INSTALL_COMMAND}"
    … …  
    6263chmod 0755 "${TOX_INSTALL_COMMAND}"
    6364
    64 echo "include gnuboat_mapservice/openapi/*.yaml gnuboat_mapservice/templates/*" > "${SRC_GEN}/MANIFEST.in"
     65# create MANIFEST.in to package openapi-spec and templates
     66echo "include gnuboat_mapservice/openapi/*.yaml" > "${SRC_GEN}/MANIFEST.in"
     67echo "graft gnuboat_mapservice/templates" >> "${SRC_GEN}/MANIFEST.in"
     68echo "global-exclude *.pyc" >> "${SRC_GEN}/MANIFEST.in"
    6569
    6670########
  • src/mapservice/codegen/templates/__init__test.mustache

    rae2ff15 r5c9c247  
    2828
    2929                application.config.from_object('{{packageName}}.server_impl.Config.TestingConfig')
     30                application.template_folder = os.path.join(os.path.dirname(__file__), '../templates')
    3031                celery = Celery(__name__, broker=application.config['CELERY_BROKER_URL'])
    3132                celery.config_from_object(application.config)
  • src/mapservice/codegen/templates/__main__.mustache

    rae2ff15 r5c9c247  
    66{{/supportPython2}}
    77
     8import os
     9
    810from {{packageName}}.server_impl import app, application, mail, celery, setup_app, config_object
    911
    1012def main():
    11         setup_app('{{appName}}', config_object)
     13        setup_app('{{appName}}', config_object, template_folder = os.path.join(os.path.dirname(__file__), 'templates'))
    1214        app.run(host=application.config.get("HOST", "localhost"), port=application.config.get("PORT", {{serverPort}}))
    1315
  • src/mapservice/server_impl/Config.py

    rae2ff15 r5c9c247  
    6363class ProductionConfig(Config):
    6464        SQLALCHEMY_DATABASE_URI = 'mysql://gnuboat:gnuboat@localhost/gnuboat_mapservice'
     65        # TEMPLATE_FOLDER could be used to use own templates residing in TEMPLATE_FOLDER
     66        TEMPLATE_FOLDER='/usr/share/gnuboat/templates'
    6567
    6668class DevelopmentConfig(Config):
  • src/mapservice/server_impl/__init__.py

    rae2ff15 r5c9c247  
    6565        return render_template('index.html')
    6666
    67 def setup_app(app_name, config):
     67def setup_app(app_name, config, template_folder = None):
    6868        application.json_encoder = encoder.JSONEncoder
    6969        app.add_api('openapi.yaml', arguments={'title': app_name}, validate_responses=True, strict_validation=True, validator_map={'response': ValidatorWorkaround})
    7070        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
    7176
    7277        db.init_app(application)
Note: See TracChangeset for help on using the changeset viewer.