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

Create silecs design files

parent baca1712
No related branches found
No related tags found
No related merge requests found
......@@ -4,22 +4,54 @@ import os
import sys
from info import __version__, __description__
from lxml import etree
import getpass
SILECS_VERSION = "2.3.0"
DESIGN_SHEMA_PATH = "../silecs-model/src/xml/DesignSchema.xsd"
DEPLOY_SHEMA_PATH = "../silecs-model/src/xml/DeploySchema.xsd"
SILECSDESIGN = "silecsdesign"
SILECSDEPLOY = "silecsdeploy"
DESIGN = "design"
DEPLOY = "deploy"
USER = getpass.getuser()
def get_extension(path):
return path.split('.')[-1]
def get_project_name(path):
return os.path.basename(path)
def get_project_dir(path):
return os.path.dirname(path)
def get_schema_path(path):
extension = get_extension(path)
if extension == 'silecsdesign':
if extension == SILECSDESIGN:
return DESIGN_SHEMA_PATH
elif extension == 'silecsdeploy':
elif extension == SILECSDEPLOY:
return DEPLOY_SHEMA_PATH
else:
raise Exception("Error: Passed file for validation needs to have the extension '.silecsdesign' or '.silecsdeploy")
def get_silecs_new_file_path(path):
extension = get_extension(path)
project_name = get_project_name(path)
project_dir = get_project_dir(path)
new_file = project_name
if extension == DESIGN:
extension = SILECSDESIGN
elif extension == DEPLOY:
extension = SILECSDEPLOY
else:
raise Exception("Error: Passed FESA file needs to have the extension '.design' or '.deploy'")
return os.path.join(project_dir, project_name + "." + extension)
def validate(xml_path, xsd_path):
try:
......@@ -51,13 +83,48 @@ def silecs_validate(file_paths):
print(e)
def create_silecs_design(filepath):
date = datetime.today().strftime('%m/%d/%Y')
design_template = f"""DESIGN_TEMPLATE='<?xml version="1.0" encoding="UTF-8"?>
<SILECS-Design silecs-version="{SILECS_VERSION}" created="{date}" updated="{date}"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="'$SCHEMA_PATH'">
<Information>
<Owner user-login="{USER}"/>
<Editor user-login="{USER}"/>
</Information>
<SILECS-Class name="'$PROJECT_NAME'" version="0.1.0" domain="OPERATIONAL" >
<Acquisition-Block name="MyBlock" generateFesaProperty="true">
<Acquisition-Register name="myRegister" generateFesaValueItem="true">
<scalar format="int32"/>
</Acquisition-Register>
</Acquisition-Block>
</SILECS-Class>
</SILECS-Design>"""
def create(filepath):
extension = get_extension(filepath)
def silecs_create(file_paths):
if extension == SILECSDESIGN:
create_silecs_design(filepath)
elif extension == SILECSDEPLOY:
create_silecs_deploy(filepath)
def silecs_create(file_paths):
for path in file_paths:
try:
new_file_path = get_silecs_new_file_path(path)
val_result = create(path, xsd_path)
if val_result:
print("File is valid")
else:
print("File is not valid. Check errors above.")
except Exception as e:
print(e)
def _parse_arguments():
parser = argparse.ArgumentParser(
......@@ -107,9 +174,8 @@ def run():
except:
sys.exit(0)
if options.create:
silecs_validate(options.create)
silecs_create(options.create)
if options.validate:
silecs_validate(options.validate)
if options.generate:
......
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