| 1 | '''
|
|---|
| 2 | Copyright (C) 2019 - 2020 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
|
|---|
| 3 |
|
|---|
| 4 | This program is free software: you can redistribute it and/or modify
|
|---|
| 5 | it under the terms of the GNU General Public License as published by
|
|---|
| 6 | the Free Software Foundation, either version 3 of the License, or
|
|---|
| 7 | (at your option) any later version.
|
|---|
| 8 |
|
|---|
| 9 | This program is distributed in the hope that it will be useful,
|
|---|
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 12 | GNU General Public License for more details.
|
|---|
| 13 |
|
|---|
| 14 | You should have received a copy of the GNU General Public License
|
|---|
| 15 | along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|---|
| 16 | '''
|
|---|
| 17 |
|
|---|
| 18 | from celery.schedules import crontab
|
|---|
| 19 | from pathlib import Path
|
|---|
| 20 | import os
|
|---|
| 21 | import yaml
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 | def load_from_file(config_file):
|
|---|
| 25 | config_from_file = yaml.safe_load(open(config_file))
|
|---|
| 26 | config = Config()
|
|---|
| 27 |
|
|---|
| 28 | for entry in config_from_file:
|
|---|
| 29 | setattr(config, entry, config_from_file[entry])
|
|---|
| 30 |
|
|---|
| 31 | return config
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 | class Config(object):
|
|---|
| 35 | DEBUG = False
|
|---|
| 36 | TESTING = False
|
|---|
| 37 | CREATE_TEST_DATABASE = False
|
|---|
| 38 | SQLALCHEMY_TRACK_MODIFICATIONS = False
|
|---|
| 39 | MAIL_SERVER = 'localhost'
|
|---|
| 40 | MAIL_PORT = 25
|
|---|
| 41 | MAIL_DEFAULT_SENDER = 'GNUBoat Mapservice <gnuboat@engsas.de>'
|
|---|
| 42 | MAPSERVICE_WEBCLIENT = '/'
|
|---|
| 43 | CELERY_BROKER_URL = 'pyamqp://guest@localhost//'
|
|---|
| 44 | CELERY_IMPORTS = ("gnuboat_mapservice.server_impl.tasks")
|
|---|
| 45 | CELERY_RESULT_BACKEND = "cache"
|
|---|
| 46 | CELERY_CACHE_BACKEND = 'memcached://127.0.0.1:11211'
|
|---|
| 47 | # pixel size of tiles to be generated
|
|---|
| 48 | TILES_SIZES = [256, 512]
|
|---|
| 49 | # Min required data points to get no nodata value in a raster pixel
|
|---|
| 50 | TILES_DENSITIES = [10, 100]
|
|---|
| 51 | TILES_DENSITY_BASEE = 100
|
|---|
| 52 | # How many years are data points allowed to be old, before they are excluded from calculations
|
|---|
| 53 | TILES_POINT_AGE_MAX = 10
|
|---|
| 54 | # log_process generates tiles for this zoom range. all lower zoomlevels (0 - x) are generated by a periodic task (s. TILES_LITTLE_ZOOM_SCHEDULE option).
|
|---|
| 55 | # Those zoomlevels are not rendered by log_process(), because they contain few details, but large areas
|
|---|
| 56 | TILES_ZOOM_RANGE = {'minimum': 10, 'maximum': 19}
|
|---|
| 57 | # schedule, when to run the job to generate tiles for low zoomlevels (0 - TILES_ZOOM_RANGE['minimum']),
|
|---|
| 58 | # As format see https://docs.celeryproject.org/en/stable/userguide/periodic-tasks.html#crontab-schedules
|
|---|
| 59 | # If TILES_ZOOM_RANGE['minimum'] = 10 it might need up to 4097 slice jobs per tile_size and density
|
|---|
| 60 | TILES_LITTLE_ZOOM_SCHEDULE = crontab(
|
|---|
| 61 | 0, 0, day_of_month='2'
|
|---|
| 62 | ) # execute every second day of each month
|
|---|
| 63 | TILES_SKIP_EMPTY = True
|
|---|
| 64 | # Maximum size of the raster files generated during tile process in bits
|
|---|
| 65 | TILES_RASTER_FILE_SIZE_MAX = 512 * 1024 * 1024 * 8
|
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 | class ProductionConfig(Config):
|
|---|
| 69 | SQLALCHEMY_DATABASE_URI = 'mysql+mysqldb://gnuboat:gnuboat@localhost/gnuboat_mapservice'
|
|---|
| 70 | # TEMPLATE_FOLDER could be used to use own templates residing in TEMPLATE_FOLDER
|
|---|
| 71 | TEMPLATE_FOLDER = '/usr/share/gnuboat/templates'
|
|---|
| 72 |
|
|---|
| 73 |
|
|---|
| 74 | class DevelopmentConfig(Config):
|
|---|
| 75 | DEBUG = True
|
|---|
| 76 | CREATE_TEST_DATABASE = True
|
|---|
| 77 | SQLALCHEMY_DATABASE_URI = 'sqlite:////tmp/test.db'
|
|---|
| 78 | MAPSERVICE_WEBCLIENT = 'http://localhost:8081'
|
|---|
| 79 | #SERVER_NAME = 'gnuboat-mapservice:8080'
|
|---|
| 80 | HOST = 'localhost'
|
|---|
| 81 | SERVER_NAME = 'localhost:8080'
|
|---|
| 82 | TILES_CACHE_PATH = os.path.join(Path.home(), '.cache/gnuboat/tiles')
|
|---|
| 83 | TILES_SIZES = [256]
|
|---|
| 84 |
|
|---|
| 85 |
|
|---|
| 86 | class TestingConfig(DevelopmentConfig):
|
|---|
| 87 | """
|
|---|
| 88 | Configuration for testing purposes only (like tox/nosetests)
|
|---|
| 89 | """
|
|---|
| 90 | TESTING = True
|
|---|
| 91 | DEBUG = False
|
|---|
| 92 | CELERY_BROKER_URL = ''
|
|---|
| 93 | SQLALCHEMY_DATABASE_URI = 'sqlite:////tmp/gnuboat-ci-tests.db'
|
|---|