Changeset f9321aa for buildhelpers/code_generator
- Timestamp:
- Apr 26, 2020, 5:02:25 PM (7 years ago)
- Branches:
- debian/bullseye, master
- Children:
- 62569d9
- Parents:
- 691c4ca
- File:
-
- 1 edited
-
buildhelpers/code_generator (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()])
Note:
See TracChangeset
for help on using the changeset viewer.
