Changeset f9321aa


Ignore:
Timestamp:
Apr 26, 2020, 5:02:25 PM (7 years ago)
Author:
Joachim Langenbach <joachim.langenbach@…>
Branches:
debian/bullseye, master
Children:
62569d9
Parents:
691c4ca
Message:
  • Adapted code_generator to
    • handle several packages
    • to configure the port from yaml specification
    • to use the VERSION used by setup.py
  • Added deviceservice.yaml with first version of webservice
  • Moved Config loader and HttpErrors to gnuboat.common
  • Moved rrd archive schema to gnuboat.common.device
Files:
14 added
14 edited
2 moved

Legend:

Unmodified
Added
Removed
  • buildhelpers/code_generator

    r691c4ca rf9321aa  
    1 #!/bin/bash
     1#!/usr/bin/python
    22
    3 DIR=`dirname "$0"`
    4 SRC="${DIR}/../src/gnuboat"
    5 SRC_GEN="${DIR}/../src/gnuboat/"
    6 PACKAGE_NAME="mapservice"
    7 PACKAGE_NAME_GEN="gnuboat.${PACKAGE_NAME}"
    8 PACKAGE_VERSION="0.5.90"
    9 TARGET_TMP="${SRC_GEN}/${PACKAGE_NAME}_tmp/"
     3import os
     4from pathlib import Path
     5import subprocess
     6import re
     7import shutil
     8import yaml
    109
    11 echo "Cleaning directory"
    12 if [ -d "${SRC_GEN}/${PACKAGE_NAME}" ]; then
    13         rm -R "${SRC_GEN}/${PACKAGE_NAME}"
    14 fi
    15 if [ -d "${TARGET_TMP}" ]; then
    16         rm -R "${TARGET_TMP}"
    17 fi
     10CURRENT_DIR = Path(os.path.dirname(__file__))
     11SRC = CURRENT_DIR.joinpath('../src/gnuboat')
     12SRC_GEN = CURRENT_DIR.joinpath('../src/gnuboat/')
     13version_file = open(CURRENT_DIR.joinpath('../VERSION').resolve(), 'r')
     14VERSION = version_file.read().strip()
     15version_file.close()
    1816
    19 echo "Preparing symlinks"
    20 mkdir -p "${TARGET_TMP}"
     17PACKAGES=["mapservice", "deviceservice"]
    2118
    22 echo "Generating backend API code"
    23 ${DIR}/codegen/openapi-generator-cli generate -i "${SRC}/mapservice.yaml" -g python-flask -t "${DIR}/codegen/templates/" --additional-properties=packageVersion=${PACKAGE_VERSION},packageName=${PACKAGE_NAME_GEN} -o "${TARGET_TMP}"
    24 mv "${TARGET_TMP}/gnuboat/${PACKAGE_NAME}" "${SRC_GEN}/${PACKAGE_NAME}"
    25 rm -R "${TARGET_TMP}"
     19print('Generating the {} services:'.format(len(PACKAGES)))
     20for package in PACKAGES:
     21    print('  {}'.format(package))
    2622
    27 # running yapf
    28 echo "Formatting the generated code accoring to style file"
    29 yapf --style "python-style.yapf" -r -i "${SRC_GEN}/${PACKAGE_NAME}"
     23for package in PACKAGES:
     24    package_name_gen = 'gnuboat.{}'.format(package)
     25    target = SRC_GEN.joinpath(package)
     26    target_tmp = SRC_GEN.joinpath('{}_tmp'.format(package))
     27    service_specification_file = SRC.joinpath('{}.yaml'.format(package)).resolve()
     28    server_port = 8080
     29   
     30    openapi_specification = yaml.safe_load(open(service_specification_file))
     31    if 'servers' in openapi_specification:
     32        for entry in openapi_specification['servers']:
     33            if 'description' in entry and 'development' in entry['description'].lower():
     34                result = re.search(r':([0-9]+)', entry['url'])
     35                if result is not None:
     36                    server_port = result.group(1)
     37
     38    print('Preparing package {} version {} using port {}'.format(package, VERSION, server_port))
     39    print('  Cleaning directory')
     40    if os.path.isdir(target):
     41        shutil.rmtree(target.resolve())
     42    if os.path.isdir(target_tmp):
     43        shutil.rmtree(target_tmp.resolve())
     44    os.mkdir(target_tmp)
     45
     46    print('  Generating backend API code')
     47    try:
     48        subprocess.run([
     49            CURRENT_DIR.joinpath('codegen/openapi-generator-cli').resolve(),
     50            'generate', '-i', service_specification_file,
     51            '-g', 'python-flask', '-t',
     52            CURRENT_DIR.joinpath('codegen/templates').resolve(),
     53            ('--additional-properties=packageVersion={},packageName={},'
     54             'serverPort={}').format(VERSION, package_name_gen, server_port),
     55            '-o', target_tmp.resolve()
     56            ],
     57            check=True,
     58            stdout=subprocess.PIPE,
     59            stderr=subprocess.PIPE)
     60    except subprocess.CalledProcessError as e:
     61        print('    openapi-generator-cli failed:')
     62        print('    STDOUT: {}'.format(e.stdout))
     63        print('    STDERR: {}'.format(e.stderr))
     64
     65    shutil.move(target_tmp.joinpath('gnuboat/{}'.format(package)).resolve(), target.resolve())
     66    shutil.rmtree(target_tmp.resolve())
     67
     68    # running yapf
     69    print('  Formatting the generated code accoring to style file')
     70    subprocess.run(['yapf', '--style', 'python-style.yapf', '-r', '-i',
     71        target.resolve()])
  • buildhelpers/codegen/templates/__init__test.mustache

    r691c4ca rf9321aa  
    1 import logging
     1from flask_testing import TestCase
    22
    3 import flask
    4 import connexion
    5 from flask_cors import CORS
    6 from flask_testing import TestCase
    7 from flask_mail import Mail
    8 from sqlalchemy.event import listen
    9 from celery import Celery
    10 import tempfile
    11 import os
    12 from PIL import Image
    13 import shutil
    14 
    15 from {{packageName}}.encoder import JSONEncoder
    16 from {{packageName}}_impl.database.Model import (
    17     db, db_setup, load_spatialite
     3from {{packageName}}_impl.tests import (
     4    create_app as orig_create_app,
     5    setUp as orig_setUp,
     6    tearDown as orig_tearDown
    187)
    19 from {{packageName}}_impl.tests import db_test_setup
    208
    219class BaseTestCase(TestCase):
    2210        def create_app(self):
    23                 logging.getLogger('connexion.operation').setLevel('ERROR')
    24                 app = connexion.App(__name__, specification_dir='../openapi/')
    25                 application = app.app
    26                 CORS(application)
    27                 mail = Mail()
    28                 application.json_encoder = JSONEncoder
    29                 app.add_api('openapi.yaml')
    30 
    31                 application.config.from_object('{{packageName}}_impl.Config.TestingConfig')
    32                 application.template_folder = os.path.join(os.path.dirname(__file__), '../../mapservice_impl/templates')
    33                 celery = Celery(__name__, broker=application.config['CELERY_BROKER_URL'])
    34                 celery.config_from_object(application.config)
    35                 mail.init_app(application)
    36                 db.init_app(application)
    37                 application.app_context().push()
    38                
    39                 self._create_test_tile(application)
    40                
    41                 return application
     11                return orig_create_app(self)
    4212
    4313        def setUp(self):
    44                 listen(db.engine, 'connect', load_spatialite)
    45                 db.drop_all()
    46                 # create the tables whether the database already exists or not
    47                 db_setup(True)
    48                 self.db_content = db_test_setup.DatabaseContent()
    49                 self.db_content.setup()
     14                orig_setUp(self)
    5015       
    5116        def tearDown(self):
    52                 db.session.remove()
    53                 db.drop_all()
    54                 shutil.rmtree(self.tiles_cache)
    55 
    56         def _create_test_tile(self, application):
    57                 self.tiles_cache = tempfile.mkdtemp(prefix='gnuboat-tests')
    58                 application.config['TILES_CACHE_PATH'] = self.tiles_cache
    59                
    60                 tile_path = os.path.join(self.tiles_cache, '100_100/256/15/17298/')
    61                 os.makedirs(tile_path)
    62                 img = Image.new('RGBA', (100, 100), (255, 0, 0, 0))
    63                 img.save(os.path.join(tile_path, "21435.png"), "PNG")
     17                orig_tearDown(self)
    6418               
    6519        def check_key(self, key, value, data):
  • buildhelpers/codegen/templates/__main__.mustache

    r691c4ca rf9321aa  
    99
    1010from {{packageName}}_impl import (
    11     app, application, mail, celery, setup_app, config_object
     11    app, application, setup_app, config_object
    1212)
    1313
  • setup.py

    r691c4ca rf9321aa  
    55
    66NAME = 'gnuboat'
    7 VERSION = '0.5.99'
     7version = open('VERSION', 'r')
     8VERSION = version.read().strip()
     9version.close()
    810
    911# shapely is required by geoalchemy2
  • src/gnuboat/common/tests/test_config.py

    r691c4ca rf9321aa  
    2121import os
    2222
    23 from gnuboat.mapservice_impl import Config
     23from gnuboat.common.webservice import Config as configure
     24
     25
     26class Config(object):
     27    TEST = 'blabla'
    2428
    2529
    … …  
    2933        """
    3034        new_config = {'TESTING': True, 'DOES_NOT_EXISTS': 1234}
    31 
    32         config = Config.Config()
    33         assert config.TESTING is False
    3435
    3536        config_file = tempfile.NamedTemporaryFile(
    … …  
    4546        config_file = os.path.join(tempfile.gettempdir(), config_file.name)
    4647
    47         config = Config.load_from_file(config_file)
     48        config = configure.config_from_file(config_file, Config())
     49        assert config.TEST == 'blabla'
    4850        assert config.TESTING is True
    4951        assert config.DOES_NOT_EXISTS == 1234
  • src/gnuboat/common/webservice/HttpErrors.py

    r691c4ca rf9321aa  
    2222
    2323
    24 class MapserviceBadRequest(ProblemException, BadRequest):
     24class GnuboatBadRequest(ProblemException, BadRequest):
    2525    def __init__(
    2626        self,
    … …  
    3131        **kwargs
    3232    ):
    33         super(MapserviceBadRequest, self).__init__(
     33        super(GnuboatBadRequest, self).__init__(
    3434            status=400,
    3535            title="Bad Request",
    … …  
    4141
    4242
    43 class MapserviceUnauthorized(ProblemException, Unauthorized):
     43class GnuboatUnauthorized(ProblemException, Unauthorized):
    4444    def __init__(
    4545        self,
    … …  
    5050        **kwargs
    5151    ):
    52         super(MapserviceUnauthorized, self).__init__(
     52        super(GnuboatUnauthorized, self).__init__(
    5353            status=401,
    5454            title=title,
    … …  
    6060
    6161
    62 class MapserviceNotFound(ProblemException, NotFound):
     62class GnuboatNotFound(ProblemException, NotFound):
    6363    def __init__(
    6464        self,
    … …  
    6969        **kwargs
    7070    ):
    71         super(MapserviceNotFound, self).__init__(
     71        super(GnuboatNotFound, self).__init__(
    7272            status=404,
    7373            title=title,
    … …  
    7979
    8080
    81 class MapserviceInternalServerError(ProblemException, InternalServerError):
     81class GnuboatInternalServerError(ProblemException, InternalServerError):
    8282    def __init__(
    8383        self,
    … …  
    8888        **kwargs
    8989    ):
    90         super(MapserviceInternalServerError, self).__init__(
     90        super(GnuboatInternalServerError, self).__init__(
    9191            status=500,
    9292            title="Internal Server Error",
  • src/gnuboat/device/daemon/rrdhandler.py

    r691c4ca rf9321aa  
    11# -*- coding: utf-8 -*-
    22'''
    3     Copyright (C) 2016 - 2017 EngSaS - Langenbach. All rights reserved.
     3    Copyright (C) 2016 - 2020 EngSaS - Langenbach. All rights reserved.
    44
    55    This program is free software: you can redistribute it and/or modify
    … …  
    2121import traceback
    2222
     23import gnuboat.common.device.rrdschema as rrdschema
    2324
    2425def rrd_create_database(database_file, logperiod, start_time='N'):
    … …  
    3233    step = logperiod
    3334    # durations: each archive should contain values for in seconds
    34     archives = [
    35         {
    36             "duration": 240,
    37             "resolution": 2
    38         },
    39         {
    40             "duration": 3600,
    41             "resolution": 10
    42         },
    43         {
    44             "duration": 86400,
    45             "resolution": 60
    46         },
    47     ]
     35    archives = rrdschema.archives
    4836    rrd_archives = []
    4937    for i in range(0, len(archives)):
    5038        rrd_archives += [
    5139            'RRA:AVERAGE:0.5:{:d}:{:d}'.format(
    52                 _steps(archives[i]["resolution"], step),
     40                _steps(archives[i].resolution, step),
    5341                _rows(
    54                     archives[i]["duration"], archives[i]["resolution"], step
     42                    archives[i].duration, archives[i].resolution, step
    5543                )
    5644            )
  • src/gnuboat/deviceservice.yaml

    r691c4ca rf9321aa  
    1212  description: API for GNUBoat devices
    1313servers:
    14   - url: 'http://gnuboat/{version}'
     14  - url: 'http://gnuboat/deviceservice/{version}'
    1515    description: The production API server
    1616    variables:
    1717      version:
    1818        default: v1
    19   - url: 'http://localhost:8090/device/{version}'
     19  - url: 'http://localhost:8090/deviceservice/{version}'
    2020    description: The local flask development url
    2121    variables:
    … …  
    6060      operationId: shutdown
    6161      responses:
    62         '200':
    63           description: OK
    64           content:
    65             application/json:
    66               schema:
    67                 type: boolean
     62        '204':
     63          description: Shutdown initiated
    6864        '500':
    6965          $ref: '#/components/responses/InternalServerError'
    … …  
    7268      description: List of local logfiles
    7369      tags:
    74         - device
     70        - deviceLogs
    7571      operationId: logfilesGet
    7672      responses:
    … …  
    8379        '500':
    8480          $ref: '#/components/responses/InternalServerError'
    85   '/logfiles/{id*}':
     81  '/logfiles/{id}':
    8682    get:
    8783      description: Download local logfiles
    … …  
    9086      operationId: logsGet
    9187      parameters:
    92         - name: id*
     88        - name: id
    9389          in: path
    9490          description: Logfiles to download
    … …  
    9692          schema:
    9793            type: string
     94          style: simple
     95          explode: true
    9896          example: 'nmea0183.log,replay-test.log'
    9997      responses:
    … …  
    181179        '500':
    182180          $ref: '#/components/responses/InternalServerError'
    183   '/maps/{map}[zoom}/{x_tile}/{y_tile}.png':
     181  '/maps/{map}/{zoom}/{x_tile}/{y_tile}.png':
    184182    get:
    185183      description: Get tiles of a map with help of it's tiles urls
    … …  
    413411      items:
    414412        $ref: '#/components/schemas/Logfile'
    415     Map:
     413    map:
    416414      title: Represents a Map
    417415      description: Following the tilejson specification https://github.com/mapbox Version 2.0.0
    … …  
    494492      type: array
    495493      items:
    496         $ref: '#/components/schemas/Map'
     494        $ref: '#/components/schemas/map'
    497495    itemName:
    498496      title: Item Name
  • src/gnuboat/mapservice_impl/Config.py

    r691c4ca rf9321aa  
    1919from pathlib import Path
    2020import 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
    3221
    3322
  • src/gnuboat/mapservice_impl/__init__.py

    r691c4ca rf9321aa  
    4444    config_object = load_config_object(os.environ['FLASK_ENV'].title())
    4545elif os.path.isfile(config_file):
    46     from . import Config as configure
    47     config_object = configure.load_from_file(config_file)
     46    from gnuboat.common.webservice import Config as configure
     47    config_object = configure.config_from_file(config_file,
     48        load_config_object(''))
    4849else:
    4950    config_object = load_config_object('Production')
  • src/gnuboat/mapservice_impl/controllers/DevicesController.py

    r691c4ca rf9321aa  
    11'''
    2     Copyright (C) 2019 EngSaS - Langenbach. All rights reserved.
     2    Copyright (C) 2019 - 2020 EngSaS - Langenbach. All rights reserved.
    33
    44    This program is free software: you can redistribute it and/or modify
    … …  
    1818
    1919from gnuboat.mapservice_impl.database.Model import User, Device, db
    20 from gnuboat.mapservice_impl.HttpErrors import (
    21     MapserviceBadRequest, MapserviceUnauthorized, MapserviceNotFound
     20from gnuboat.common.webservice.HttpErrors import (
     21    GnuboatBadRequest, GnuboatUnauthorized, GnuboatNotFound
    2222)
    2323
    … …  
    2828    user = User.loggedin_user()
    2929    if user is None:
    30         raise MapserviceUnauthorized
     30        raise GnuboatUnauthorized
    3131
    3232    query = Device.query.filter_by(owner=user)
    … …  
    4343    user = User.loggedin_user()
    4444    if user is None:
    45         raise MapserviceUnauthorized
     45        raise GnuboatUnauthorized
    4646
    4747    device = Device.query.filter_by(owner=user).filter_by(id=id).all()
    4848    if len(device) != 1:
    49         raise MapserviceNotFound
     49        raise GnuboatNotFound
    5050    return device[0].to_dict()
    5151
    … …  
    5454    user = User.loggedin_user()
    5555    if user is None:
    56         raise MapserviceUnauthorized
     56        raise GnuboatUnauthorized
    5757
    5858    comment = ""
    … …  
    7474    user = User.loggedin_user()
    7575    if user is None:
    76         raise MapserviceUnauthorized
     76        raise GnuboatUnauthorized
    7777
    7878    if not Device.query.filter_by(owner=user).filter_by(id=id).delete():
    79         raise MapserviceBadRequest(
     79        raise GnuboatBadRequest(
    8080            detail="Could not delete device with id {}".format(id)
    8181        )
  • src/gnuboat/mapservice_impl/controllers/LogsController.py

    r691c4ca rf9321aa  
    2121    Water, Device, Gauge, ProcessingStatus, Queue, db
    2222)
    23 from gnuboat.mapservice_impl.HttpErrors import (
    24     MapserviceBadRequest, MapserviceUnauthorized, MapserviceNotFound
     23from gnuboat.common.webservice.HttpErrors import (
     24    GnuboatBadRequest, GnuboatUnauthorized, GnuboatNotFound
    2525)
    2626from gnuboat.mapservice_impl.tasks.tasks import log_process
    … …  
    3333        submitter = User.query.filter_by(username=submitter).all()
    3434        if len(submitter) != 1:
    35             raise MapserviceNotFound(
     35            raise GnuboatNotFound(
    3636                detail="Could not find the submitter with id {}".
    3737                format(submitter)
    … …  
    5555    log = Log.query.filter_by(id=id).all()
    5656    if len(log) != 1:
    57         raise MapserviceNotFound
     57        raise GnuboatNotFound
    5858    if connexion.request.headers['Accept'] == "application/geo+json":
    5959        return log[0].to_geojson(), 200, {
    … …  
    6666    user = User.loggedin_user()
    6767    if user is None:
    68         raise MapserviceUnauthorized
     68        raise GnuboatUnauthorized
    6969
    7070    water = Water.query.filter_by(id=log_creation.water).all()
    7171    if len(water) != 1:
    72         raise MapserviceBadRequest(
     72        raise GnuboatBadRequest(
    7373            detail='Water {} not found database'.format(log_creation.water)
    7474        )
    … …  
    7777    device = Device.query.filter_by(id=log_creation.device).all()
    7878    if len(device) != 1:
    79         raise MapserviceBadRequest(
     79        raise GnuboatBadRequest(
    8080            detail='Device {} not found in database'.
    8181            format(log_creation.device)
    … …  
    8585    gauge = Gauge.query.filter_by(id=log_creation.gauge).all()
    8686    if len(gauge) != 1:
    87         raise MapserviceBadRequest(
     87        raise GnuboatBadRequest(
    8888            detail='Gauge {} not found in database'.format(log_creation.gauge)
    8989        )
    … …  
    9191
    9292    if log_creation.gauge_height is None:
    93         raise MapserviceBadRequest(detail='Gauge Height (Stage) missing')
     93        raise GnuboatBadRequest(detail='Gauge Height (Stage) missing')
    9494    else:
    9595        try:
    9696            float(log_creation.gauge_height)
    9797        except ValueError:
    98             raise MapserviceBadRequest(
     98            raise GnuboatBadRequest(
    9999                detail='Gauge Height (Stage) {} is no number'.
    100100                format(log_creation.gauge_height)
    … …  
    122122    user = User.loggedin_user()
    123123    if user is None:
    124         raise MapserviceUnauthorized
     124        raise GnuboatUnauthorized
    125125
    126126    if body is None or not body:
    127         raise MapserviceBadRequest(detail='No log data')
     127        raise GnuboatBadRequest(detail='No log data')
    128128
    129129    processing_state = ProcessingStatus.query.filter_by(
    … …  
    131131    ).all()
    132132    if len(processing_state) != 1:
    133         raise MapserviceBadRequest(
     133        raise GnuboatBadRequest(
    134134            detail='Processing status Queued for Parsing not found database'
    135135        )
    … …  
    138138    log = Log.query.filter_by(id=log_id).all()
    139139    if len(log) != 1:
    140         raise MapserviceBadRequest(
     140        raise GnuboatBadRequest(
    141141            detail='Log {} not found database'.format(log_id)
    142142        )
    … …  
    145145    # check if Log has already log entries
    146146    if LogEntry.query.filter_by(log=log).count() > 0:
    147         raise MapserviceBadRequest(
     147        raise GnuboatBadRequest(
    148148            detail='Log {} has already log entries. Aborting'.format(log_id)
    149149        )
    … …  
    164164    user = User.loggedin_user()
    165165    if user is None:
    166         raise MapserviceUnauthorized
     166        raise GnuboatUnauthorized
    167167
    168168    if not Log.query.filter_by(submitter=user).filter_by(id=id).delete():
    169         raise MapserviceBadRequest(
     169        raise GnuboatBadRequest(
    170170            detail="Could not delete log with id {}".format(id)
    171171        )
  • src/gnuboat/mapservice_impl/controllers/TilesController.py

    r691c4ca rf9321aa  
    2020import os
    2121
    22 from gnuboat.mapservice_impl.HttpErrors import (
    23     MapserviceInternalServerError, MapserviceBadRequest, MapserviceNotFound
     22from gnuboat.common.webservice.HttpErrors import (
     23    GnuboatInternalServerError, GnuboatBadRequest, GnuboatNotFound
    2424)
    2525
    … …  
    2929        flask.current_app.config['TILES_CACHE_PATH'], os.R_OK
    3030    ):
    31         raise MapserviceInternalServerError(
     31        raise GnuboatInternalServerError(
    3232            detail='TILES_CACHE_PATH not configured or not accessible'
    3333        )
    … …  
    3535
    3636    if 'TILES_DENSITIES' not in flask.current_app.config:
    37         raise MapserviceInternalServerError(
    38             details='TILES_DENSITIES not configured'
     37        raise GnuboatInternalServerError(
     38            detail='TILES_DENSITIES not configured'
    3939        )
    4040    tiles_densities = flask.current_app.config['TILES_DENSITIES']
    4141
    4242    if 'TILES_DENSITY_BASEE' not in flask.current_app.config:
    43         raise MapserviceInternalServerError(
    44             details='TILES_DENSITY_BASEE not configured'
     43        raise GnuboatInternalServerError(
     44            detail='TILES_DENSITY_BASEE not configured'
    4545        )
    4646    tiles_densitiy_base = flask.current_app.config['TILES_DENSITY_BASEE']
    4747
    4848    if 'TILES_SKIP_EMPTY' not in flask.current_app.config:
    49         raise MapserviceInternalServerError(
    50             details='TILES_SKIP_EMPTY not configured'
     49        raise GnuboatInternalServerError(
     50            detail='TILES_SKIP_EMPTY not configured'
    5151        )
    5252    tiles_skip_empty = flask.current_app.config['TILES_SKIP_EMPTY']
    … …  
    5757        accuracy = '{}_{}'.format(min(tiles_densities), tiles_densitiy_base)
    5858    else:
    59         raise MapserviceBadRequest(
    60             details=('No valid accuracy requested. '
     59        raise GnuboatBadRequest(
     60            detail=('No valid accuracy requested. '
    6161                     'Valid are high, low. Requested was: {}')
    6262            .format(accuracy)
    … …  
    7373    if not os.path.isfile(tile_path):
    7474        if not tiles_skip_empty or not os.path.isfile(tile__empty_path):
    75             raise MapserviceNotFound(
     75            raise GnuboatNotFound(
    7676                detail=('Tile ({}, {}) for accuracy {} with resolution {} '
    7777                        'at zoomlevel {} not found')
  • src/gnuboat/mapservice_impl/controllers/UsersController.py

    r691c4ca rf9321aa  
    2626from gnuboat.mapservice_impl import mail
    2727from gnuboat.mapservice_impl.database.Model import User, ApiKey, db
    28 from gnuboat.mapservice_impl.HttpErrors import (
    29     MapserviceBadRequest, MapserviceUnauthorized, MapserviceNotFound
     28from gnuboat.common.webservice.HttpErrors import (
     29    GnuboatBadRequest, GnuboatUnauthorized, GnuboatNotFound
    3030)
    3131
    … …  
    5151    user = User.loggedin_user()
    5252    if user is None:
    53         raise MapserviceUnauthorized
     53        raise GnuboatUnauthorized
    5454
    5555    api_key = hashlib.md5(
    … …  
    7070    user = User.loggedin_user()
    7171    if user is None:
    72         raise MapserviceUnauthorized
     72        raise GnuboatUnauthorized
    7373
    7474    if not ApiKey.query.filter_by(key=api_key).delete():
    75         raise MapserviceBadRequest(
     75        raise GnuboatBadRequest(
    7676            detail="Could not delete api key {}".format(api_key)
    7777        )
    … …  
    8787    user = User.loggedin_user()
    8888    if user is None:
    89         raise MapserviceUnauthorized
     89        raise GnuboatUnauthorized
    9090
    9191    return user_to_dict(user)
    … …  
    9494def users_register(user_creation):
    9595    if user_creation is None:
    96         raise MapserviceBadRequest(detail='No data specified')
     96        raise GnuboatBadRequest(detail='No data specified')
    9797    if user_creation.username is None or not user_creation.username:
    98         raise MapserviceBadRequest(detail='No username given')
     98        raise GnuboatBadRequest(detail='No username given')
    9999    if user_creation.password is None or not user_creation.password:
    100         raise MapserviceBadRequest(detail='No password given')
     100        raise GnuboatBadRequest(detail='No password given')
    101101    if user_creation.first_name is None or not user_creation.first_name:
    102         raise MapserviceBadRequest(detail='No first name given')
     102        raise GnuboatBadRequest(detail='No first name given')
    103103    if user_creation.last_name is None or not user_creation.last_name:
    104         raise MapserviceBadRequest(detail='No last name given')
     104        raise GnuboatBadRequest(detail='No last name given')
    105105    if user_creation.email is None or not user_creation.email:
    106         raise MapserviceBadRequest(detail='No email given')
     106        raise GnuboatBadRequest(detail='No email given')
    107107    if not mail_regex.match(user_creation.email):
    108         raise MapserviceBadRequest(
     108        raise GnuboatBadRequest(
    109109            detail='Email contains more than one @, no @ or no .'
    110110        )
    111111    if (user_creation.license_accepted is None or
    112112            not user_creation.license_accepted):
    113         raise MapserviceBadRequest(
     113        raise GnuboatBadRequest(
    114114            detail='You must accept the license to register an account'
    115115        )
  • src/gnuboat/mapservice_impl/controllers/WatersController.py

    r691c4ca rf9321aa  
    11'''
    2     Copyright (C) 2019 EngSaS - Langenbach. All rights reserved.
     2    Copyright (C) 2019 - 2020 EngSaS - Langenbach. All rights reserved.
    33
    44    This program is free software: you can redistribute it and/or modify
    … …  
    1818
    1919from gnuboat.mapservice_impl.database.Model import User, Water, Gauge, Log, db
    20 from gnuboat.mapservice_impl.HttpErrors import (
    21     MapserviceBadRequest,
    22     MapserviceUnauthorized, MapserviceNotFound
     20from gnuboat.common.webservice.HttpErrors import (
     21    GnuboatBadRequest,
     22    GnuboatUnauthorized, GnuboatNotFound
    2323)
    2424
    … …  
    3737        manager = User.query.filter_by(username=manager).all()
    3838        if len(manager) != 1:
    39             raise MapserviceNotFound(
     39            raise GnuboatNotFound(
    4040                detail="Could not find the manager with id {}".format(manager)
    4141            )
    … …  
    5656        stakeholder = User.query.filter_by(username=stakeholder).all()
    5757        if len(stakeholder) != 1:
    58             raise MapserviceNotFound(details='Stakeholder not found')
     58            raise GnuboatNotFound(detail='Stakeholder not found')
    5959        stakeholder = stakeholder[0]
    6060
    … …  
    9191    water = Water.query.filter_by(id=id).all()
    9292    if len(water) != 1:
    93         raise MapserviceNotFound
     93        raise GnuboatNotFound
    9494    return water[0].to_dict()
    9595
    … …  
    9898    user = User.loggedin_user()
    9999    if user is None:
    100         raise MapserviceUnauthorized
     100        raise GnuboatUnauthorized
    101101
    102102    water = Water(
    … …  
    114114    water = Water.query.filter_by(id=water_id).all()
    115115    if len(water) != 1:
    116         raise MapserviceBadRequest(
     116        raise GnuboatBadRequest(
    117117            detail="Water with id {} not found".format(water_id)
    118118        )
    … …  
    121121    gauge = Gauge.query.filter_by(water=water).filter_by(id=gauge_id).all()
    122122    if len(gauge) != 1:
    123         raise MapserviceNotFound(
     123        raise GnuboatNotFound(
    124124            detail="Did not find gauge with id {} for water {}".
    125125            format(gauge_id, water.name)
    … …  
    135135    user = User.loggedin_user()
    136136    if user is None:
    137         raise MapserviceUnauthorized
     137        raise GnuboatUnauthorized
    138138
    139139    water = Water.query.filter_by(id=water_id).all()
    140140    if len(water) != 1:
    141         raise MapserviceBadRequest(
     141        raise GnuboatBadRequest(
    142142            detail="Did not find water with id {}".format(water_id)
    143143        )
    … …  
    164164    water = Water.query.filter_by(id=water_id).all()
    165165    if len(water) != 1:
    166         raise MapserviceBadRequest(
     166        raise GnuboatBadRequest(
    167167            detail="Did not find water with id {}".format(water_id)
    168168        )
    … …  
    173173        manager = User.query.filter_by(username=manager).all()
    174174        if len(manager) != 1:
    175             raise MapserviceNotFound(
     175            raise GnuboatNotFound(
    176176                detail="Could not find the manager with id {}".format(manager)
    177177            )
  • src/gnuboat/mapservice_impl/demo/DbSetup.py

    r691c4ca rf9321aa  
    2323    db, User, ApiKey, Water,
    2424    OsmType, Gauge, Device, Log, Queue, ProcessingStatus, db_setup
     25)
     26from gnuboat.common.webservice.HttpErrors import (
     27    GnuboatBadRequest
    2528)
    2629from gnuboat.mapservice_impl.tasks.tasks import log_process
    … …  
    200203    ).all()
    201204    if len(processing_state) != 1:
    202         raise MapserviceBadRequest(
     205        raise GnuboatBadRequest(
    203206            detail='Processing status Queued for Parsing not found database'
    204207        )
Note: See TracChangeset for help on using the changeset viewer.