Changeset f9321aa for buildhelpers
- Timestamp:
- Apr 26, 2020, 5:02:25 PM (7 years ago)
- Branches:
- debian/bullseye, master
- Children:
- 62569d9
- Parents:
- 691c4ca
- Location:
- buildhelpers
- Files:
-
- 3 edited
-
code_generator (modified) (1 diff)
-
codegen/templates/__init__test.mustache (modified) (1 diff)
-
codegen/templates/__main__.mustache (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
buildhelpers/code_generator
r691c4ca rf9321aa 1 #!/ bin/bash1 #!/usr/bin/python 2 2 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/" 3 import os 4 from pathlib import Path 5 import subprocess 6 import re 7 import shutil 8 import yaml 10 9 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 10 CURRENT_DIR = Path(os.path.dirname(__file__)) 11 SRC = CURRENT_DIR.joinpath('../src/gnuboat') 12 SRC_GEN = CURRENT_DIR.joinpath('../src/gnuboat/') 13 version_file = open(CURRENT_DIR.joinpath('../VERSION').resolve(), 'r') 14 VERSION = version_file.read().strip() 15 version_file.close() 18 16 19 echo "Preparing symlinks" 20 mkdir -p "${TARGET_TMP}" 17 PACKAGES=["mapservice", "deviceservice"] 21 18 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}" 19 print('Generating the {} services:'.format(len(PACKAGES))) 20 for package in PACKAGES: 21 print(' {}'.format(package)) 26 22 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}" 23 for 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 1 from flask_testing import TestCase 2 2 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 3 from {{packageName}}_impl.tests import ( 4 create_app as orig_create_app, 5 setUp as orig_setUp, 6 tearDown as orig_tearDown 18 7 ) 19 from {{packageName}}_impl.tests import db_test_setup20 8 21 9 class BaseTestCase(TestCase): 22 10 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) 42 12 43 13 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) 50 15 51 16 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) 64 18 65 19 def check_key(self, key, value, data): -
buildhelpers/codegen/templates/__main__.mustache
r691c4ca rf9321aa 9 9 10 10 from {{packageName}}_impl import ( 11 app, application, mail, celery,setup_app, config_object11 app, application, setup_app, config_object 12 12 ) 13 13
Note:
See TracChangeset
for help on using the changeset viewer.
