Index: buildhelpers/code_generator
===================================================================
--- buildhelpers/code_generator	(revision 2052b72d52cd0d4f828d7361675c19915d1b7e49)
+++ buildhelpers/code_generator	(revision 2c86c99faebc50aa781a108806451527b7942d88)
@@ -1,29 +1,71 @@
-#!/bin/bash
+#!/usr/bin/python
 
-DIR=`dirname "$0"`
-SRC="${DIR}/../src/gnuboat"
-SRC_GEN="${DIR}/../src/gnuboat/"
-PACKAGE_NAME="mapservice"
-PACKAGE_NAME_GEN="gnuboat.${PACKAGE_NAME}"
-PACKAGE_VERSION="0.5.90"
-TARGET_TMP="${SRC_GEN}/${PACKAGE_NAME}_tmp/"
+import os
+from pathlib import Path
+import subprocess
+import re
+import shutil
+import yaml
 
-echo "Cleaning directory"
-if [ -d "${SRC_GEN}/${PACKAGE_NAME}" ]; then
-	rm -R "${SRC_GEN}/${PACKAGE_NAME}"
-fi
-if [ -d "${TARGET_TMP}" ]; then
-	rm -R "${TARGET_TMP}"
-fi
+CURRENT_DIR = Path(os.path.dirname(__file__))
+SRC = CURRENT_DIR.joinpath('../src/gnuboat')
+SRC_GEN = CURRENT_DIR.joinpath('../src/gnuboat/')
+version_file = open(CURRENT_DIR.joinpath('../VERSION').resolve(), 'r')
+VERSION = version_file.read().strip()
+version_file.close()
 
-echo "Preparing symlinks"
-mkdir -p "${TARGET_TMP}"
+PACKAGES=["mapservice", "deviceservice"]
 
-echo "Generating backend API code"
-${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}"
-mv "${TARGET_TMP}/gnuboat/${PACKAGE_NAME}" "${SRC_GEN}/${PACKAGE_NAME}"
-rm -R "${TARGET_TMP}"
+print('Generating the {} services:'.format(len(PACKAGES)))
+for package in PACKAGES:
+    print('  {}'.format(package))
 
-# running yapf
-echo "Formatting the generated code accoring to style file"
-yapf --style "python-style.yapf" -r -i "${SRC_GEN}/${PACKAGE_NAME}"
+for package in PACKAGES:
+    package_name_gen = 'gnuboat.{}'.format(package)
+    target = SRC_GEN.joinpath(package)
+    target_tmp = SRC_GEN.joinpath('{}_tmp'.format(package))
+    service_specification_file = SRC.joinpath('{}.yaml'.format(package)).resolve()
+    server_port = 8080
+    
+    openapi_specification = yaml.safe_load(open(service_specification_file))
+    if 'servers' in openapi_specification:
+        for entry in openapi_specification['servers']:
+            if 'description' in entry and 'development' in entry['description'].lower():
+                result = re.search(r':([0-9]+)', entry['url'])
+                if result is not None:
+                    server_port = result.group(1)
+
+    print('Preparing package {} version {} using port {}'.format(package, VERSION, server_port))
+    print('  Cleaning directory')
+    if os.path.isdir(target):
+        shutil.rmtree(target.resolve())
+    if os.path.isdir(target_tmp):
+        shutil.rmtree(target_tmp.resolve())
+    os.mkdir(target_tmp)
+
+    print('  Generating backend API code')
+    try:
+        subprocess.run([
+            CURRENT_DIR.joinpath('codegen/openapi-generator-cli').resolve(),
+            'generate', '-i', service_specification_file,
+            '-g', 'python-flask', '-t',
+            CURRENT_DIR.joinpath('codegen/templates').resolve(),
+            ('--additional-properties=packageVersion={},packageName={},'
+             'serverPort={}').format(VERSION, package_name_gen, server_port),
+            '-o', target_tmp.resolve()
+            ],
+            check=True,
+            stdout=subprocess.PIPE,
+            stderr=subprocess.PIPE)
+    except subprocess.CalledProcessError as e:
+        print('    openapi-generator-cli failed:')
+        print('    STDOUT: {}'.format(e.stdout))
+        print('    STDERR: {}'.format(e.stderr))
+
+    shutil.move(target_tmp.joinpath('gnuboat/{}'.format(package)).resolve(), target.resolve())
+    shutil.rmtree(target_tmp.resolve())
+
+    # running yapf
+    print('  Formatting the generated code accoring to style file')
+    subprocess.run(['yapf', '--style', 'python-style.yapf', '-r', '-i',
+        target.resolve()])
Index: buildhelpers/codegen/templates/__init__test.mustache
===================================================================
--- buildhelpers/codegen/templates/__init__test.mustache	(revision 2052b72d52cd0d4f828d7361675c19915d1b7e49)
+++ buildhelpers/codegen/templates/__init__test.mustache	(revision 2c86c99faebc50aa781a108806451527b7942d88)
@@ -1,65 +1,19 @@
-import logging
+from flask_testing import TestCase
 
-import flask
-import connexion
-from flask_cors import CORS
-from flask_testing import TestCase
-from flask_mail import Mail
-from sqlalchemy.event import listen
-from celery import Celery
-import tempfile
-import os
-from PIL import Image
-import shutil
-
-from {{packageName}}.encoder import JSONEncoder
-from {{packageName}}_impl.database.Model import (
-    db, db_setup, load_spatialite
+from {{packageName}}_impl.tests import (
+    create_app as orig_create_app,
+    setUp as orig_setUp,
+    tearDown as orig_tearDown
 )
-from {{packageName}}_impl.tests import db_test_setup
 
 class BaseTestCase(TestCase):
 	def create_app(self):
-		logging.getLogger('connexion.operation').setLevel('ERROR')
-		app = connexion.App(__name__, specification_dir='../openapi/')
-		application = app.app
-		CORS(application)
-		mail = Mail()
-		application.json_encoder = JSONEncoder
-		app.add_api('openapi.yaml')
-
-		application.config.from_object('{{packageName}}_impl.Config.TestingConfig')
-		application.template_folder = os.path.join(os.path.dirname(__file__), '../../mapservice_impl/templates')
-		celery = Celery(__name__, broker=application.config['CELERY_BROKER_URL'])
-		celery.config_from_object(application.config)
-		mail.init_app(application)
-		db.init_app(application)
-		application.app_context().push()
-		
-		self._create_test_tile(application)
-		
-		return application
+		return orig_create_app(self)
 
 	def setUp(self):
-		listen(db.engine, 'connect', load_spatialite)
-		db.drop_all()
-		# create the tables whether the database already exists or not
-		db_setup(True)
-		self.db_content = db_test_setup.DatabaseContent()
-		self.db_content.setup()
+		orig_setUp(self)
         
 	def tearDown(self):
-		db.session.remove()
-		db.drop_all()
-		shutil.rmtree(self.tiles_cache)
-
-	def _create_test_tile(self, application):
-		self.tiles_cache = tempfile.mkdtemp(prefix='gnuboat-tests')
-		application.config['TILES_CACHE_PATH'] = self.tiles_cache
-		
-		tile_path = os.path.join(self.tiles_cache, '100_100/256/15/17298/')
-		os.makedirs(tile_path)
-		img = Image.new('RGBA', (100, 100), (255, 0, 0, 0))
-		img.save(os.path.join(tile_path, "21435.png"), "PNG")
+		orig_tearDown(self)
 		
 	def check_key(self, key, value, data):
Index: buildhelpers/codegen/templates/__main__.mustache
===================================================================
--- buildhelpers/codegen/templates/__main__.mustache	(revision 2052b72d52cd0d4f828d7361675c19915d1b7e49)
+++ buildhelpers/codegen/templates/__main__.mustache	(revision 2c86c99faebc50aa781a108806451527b7942d88)
@@ -9,5 +9,5 @@
 
 from {{packageName}}_impl import (
-    app, application, mail, celery, setup_app, config_object
+    app, application, setup_app, config_object
 )
 
