Skip to content
Snippets Groups Projects
Commit 7ab98cbd authored by Nabywaniec's avatar Nabywaniec
Browse files

Generate deploy code

parent a322cd96
No related branches found
No related tags found
1 merge request!2Port silecs cli to Python
......@@ -2,10 +2,12 @@ import argparse
import os
import sys
from info import __version__, __description__
import lxml.etree
import getpass
import datetime
import shutil
from info import __version__, __description__
SILECS_VERSION = "2.3.0"
DESIGN_SHEMA_PATH = "../silecs-model/src/xml/DesignSchema.xsd"
......@@ -16,18 +18,38 @@ DESIGN = "design"
DEPLOY = "deploy"
USER = getpass.getuser()
# FESA specific variables
FESA_VERSION="7.4.0"
FESA_BASE=f"/opt/fesa/fesa-fwk/{FESA_VERSION}"
FESA_XSD=f"{FESA_BASE}/fesa-model-gsi/xml/deployment/deployment-gsi.xsd"
FESA_GSI_TEMPLATE=f"{FESA_BASE}/fesa-model-gsi/xml/design/templates/GSIClassTemplate.xml"
# silecs specific variables
try:
SILECS_BASE=(os.environ['SILECS_BASE'])
except:
SILECS_BASE=f"/common/usr/cscofe/silecs/${SILECS_VERSION}"
SILECS_CODEGEN_BASE=f"{SILECS_BASE}/silecs-codegen/xml/"
SILECS_CODEGEN_MIGRATION=f"{SILECS_BASE}/silecs-codegen/xml/migration"
# TODO: Check for concrete fesa version - See here for details: https://gitlab.com/al.schwinn/silecs-cli/-/issues/4
SILECS_CODEGEN_FESA=f"{SILECS_BASE}/silecs-codegen/xml/fesa/fesa_7_3_0/"
sys.path.append(SILECS_CODEGEN_BASE)
sys.path.append(SILECS_CODEGEN_MIGRATION)
sys.path.append(SILECS_CODEGEN_FESA)
import generateFesaDesign
print(f"using sileces base path: {SILECS_BASE}")
FESA_VERSION="7.4.0"
FESA_BASE=f"/opt/fesa/fesa-fwk/{FESA_VERSION}"
FESA_XSD=f"{FESA_BASE}/fesa-model-gsi/xml/deployment/deployment-gsi.xsd"
FESA_GSI_TEMPLATE=f"{FESA_BASE}/fesa-model-gsi/xml/design/templates/GSIClassTemplate.xml"
"""
####### Helper functions #######
"""
def get_extension(filepath):
return filepath.split('.')[-1]
......@@ -66,6 +88,16 @@ def get_silecs_new_file_path(fesa_design_deploy_path):
return os.path.join(project_dir, project_name + "." + extension)
def create_backup_file(filepath):
backup_file = filepath + ".backup"
with open(backup_file, 'w+'):
shutil.copyfile(src=filepath, dst=backup_file)
"""
####### Validation #######
"""
def validate(silecs_design_deploy_path, xsd_path):
try:
print("validating {}".format(silecs_design_deploy_path))
......@@ -81,6 +113,8 @@ def validate(silecs_design_deploy_path, xsd_path):
print(e)
return False
# TODO: Implement jave-rules - See here for details: https://gitlab.com/al.schwinn/silecs-cli/-/issues/3
def silecs_validate(file_paths):
for path in file_paths:
......@@ -94,6 +128,9 @@ def silecs_validate(file_paths):
except Exception as e:
print(e)
"""
####### Create #######
"""
def create_silecs_design(filepath, project_name):
date = datetime.datetime.today().strftime('%m/%d/%Y')
......@@ -171,39 +208,78 @@ def silecs_create(file_paths):
except Exception as e:
print(e)
"""
####### Generation #######
"""
def silecs_generate_silecsdesign(silecs_design_path):
project_name = get_project_name(silecs_design_path)
project_dir = get_project_dir(silecs_design_path)
print(silecs_design_path)
print(project_dir)
def silecs_generate_silecsdeploy(silecs_deploy_path):
project_name = get_project_name(silecs_deploy_path)
project_dir = get_project_dir(silecs_deploy_path)
workspace_path = os.path.abspath(os.path.join(project_dir, os.pardir))
fesa_deploy_file = os.path.abspath(os.path.join(project_dir, project_name + ".depoy"))
SILECS_DEPLOY_VERSION="unused_parameter"
print(f"generating code for {project_name} ...\n")
print(fesa_deploy_file)
if os.path.isfile(fesa_deploy_file):
info = f"Please note that old, obsolete xml-elements are not deleted automatically! Sometimes this can lead to an invalid FESA document! \n" \
f"If this is the case, please remove the obsolete elements by hand. \n" \
f"Creating a backup of the existing FESA file at: {fesa_deploy_file}.backup \n"
print(info)
create_backup_file(fesa_deploy_file)
SILECS_CODEGEN_BASE=f"{SILECS_BASE}/silecs-codegen/xml/"
SILECS_CODEGEN_MIGRATION=f"{SILECS_BASE}/silecs-codegen/xml/migration"
SILECS_CODEGEN_FESA=f"{SILECS_BASE}/silecs-codegen/xml/fesa/fesa_7_3_0/"
genparam.genParam(workspace_path, project_name, SILECS_DEPLOY_VERSION, SILECS_VERSION)
genplcsrc.genPlcSrc(workspace_path, project_name, SILECS_VERSION)
genduwrapper.genDuWrapper(workspace_path, project_name, SILECS_DEPLOY_VERSION)
fillFESADeployUnit.fillDeployUnit(workspace_path, project_name, FESA_XSD, FESA_VERSION)
info = "Please note that you need to add the dependency to the silecs library to your Makefile. \n" \
"Here an example: https://www-acc.gsi.de/wiki/Frontend/Silecs_1_0_0_CodeSnippets#Dependency_in_Makefile.specific !\n"
print(info)
print("Code generation finished")
#FESA_DEPLOY_FILE=$PROJECT_PATH/src/$PROJECT_NAME.deploy
# SILECS_LIBRARY_BASE=f"{SILECS_BASE}/silecs-communication-cpp"
# FESA_XSD=f"{FESA_BASE}/fesa-model-gsi/xml/design/design-gsi.xsd"
def silecs_generate_silecsdesign(silecs_design_path):
fesa_deploy_file = os.path.abspath(os.path.join(project_dir, project_name + ".deploy"))
project_name = get_project_name(silecs_design_path)
project_dir = get_project_dir(silecs_design_path)
workspace_path = os.path.abspath(os.path.join(project_dir, os.pardir))
fesa_design_file = os.path.abspath(os.path.join(project_dir, project_name + ".design"))
print(f"generating code for {project_name} ...\n")
print(fesa_deploy_file)
if os.path.isfile(fesa_deploy_file):
info = "Please note that old, obsolete xml-elements are not deleted automatically! Sometimes this can lead to an invalid FESA document!" \
"If this is the case, please remove the obsolete elements by hand." \
"Creating a backup of the existing FESA file at: $FESA_DEPLOY_FILE.backup"
print(info)
print(fesa_design_file)
if os.path.isfile(fesa_design_file):
info = f"Please note that old, obsolete xml-elements are not deleted automatically! Sometimes this can lead to an invalid FESA document! \n" \
f"If this is the case, please remove the obsolete elements by hand. \n" \
f"Creating a backup of the existing FESA file at: {fesa_design_file}.backup \n"
print(info)
create_backup_file(fesa_design_file)
info = "Please not that you need to add the dependency to the silecs library to your Makefile. \n" \
"Here an example: https://www-acc.gsi.de/wiki/Frontend/Silecs_1_0_0_CodeSnippets#Dependency_in_Makefile.specific !\n"
print(info)
import sys
sys.path.append(SILECS_CODEGEN_BASE)
sys.path.append(SILECS_CODEGEN_MIGRATION)
sys.path.append(SILECS_CODEGEN_FESA)
import generateFesaDesign
generateFesaDesign.fillDesignFile(FESA_VERSION, project_name, workspace_path, FESA_XSD)
generateSourceCode.genCppFiles(project_name, workspace_path, silecs_design_path)
print("Code generation finished")
def generate(silecs_design_deploy_path):
extension = get_extension(silecs_design_deploy_path)
silecs_design_deploy_path = os.path.abspath(silecs_design_deploy_path)
if extension == SILECSDESIGN:
silecs_generate_silecsdesign(silecs_design_deploy_path)
......@@ -230,6 +306,9 @@ def silecs_generate(file_paths):
except Exception as e:
print(e)
"""
####### Parse arguments #######
"""
def _parse_arguments():
parser = argparse.ArgumentParser(
......@@ -271,6 +350,9 @@ def _parse_arguments():
return parser
"""
####### Entrz point #######
"""
def run():
parser = _parse_arguments()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment