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

Create python script and add validation

parent 59e75091
No related branches found
No related tags found
1 merge request!2Port silecs cli to Python
__version__ = "0.1.0"
__description__ = "Script in order to model PLC devices in FESA by using the Silecs framework"
\ No newline at end of file
import setuptools
from info import __version__, __description__
setuptools.setup(
name="silecs-cli",
version=__version__,
description=__description__,
url="https://git.gsi.de/silecs/opensilecs/-/tree/master/silecs-cli-client"
author="GSI",
license="",
install_requires=[
'lxml',
],
entry_points={
'console_scripts': [
'silecs-cli=silecs-cli.silecs:run'
]
},
)
\ No newline at end of file
import argparse
import os
import sys
from info import __version__, __description__
from lxml import etree
DESIGN_SHEMA_PATH = "../silecs-model/src/xml/DesignSchema.xsd"
DEPLOY_SHEMA_PATH = "../silecs-model/src/xml/DeploySchema.xsd"
def get_extension(path):
return path.split('.')[-1]
def get_schema_path(path):
extension = get_extension(path)
if extension == 'silecsdesign':
return DESIGN_SHEMA_PATH
elif extension == 'silecsdeploy':
return DEPLOY_SHEMA_PATH
else:
raise Exception("Error: Passed file for validation needs to have the extension '.silecsdesign' or '.silecsdeploy")
def validate(xml_path, xsd_path):
try:
print("validating {}".format(xml_path))
xmlschema_doc = etree.parse(xsd_path)
xmlschema = etree.XMLSchema(xmlschema_doc)
xml_doc = etree.parse(xml_path)
result = xmlschema.validate(xml_doc)
print(result)
return result
except OSError as e:
print(e)
return False
except Exception as e:
print(e)
return False
def silecs_validate(file_paths):
for path in file_paths:
try:
xsd_path = get_schema_path(path)
val_result = validate(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 silecs_create(file_paths):
def _parse_arguments():
parser = argparse.ArgumentParser(
description=__description__)
parser.add_argument(
"-c",
"--create",
nargs="+",
help="create new .silecsdesign/.silecsdeploy file for the specified FESA .design/.deplox file"
)
parser.add_argument(
"-v",
"--validate",
nargs="+",
help="validate silecs xml file"
)
parser.add_argument(
"-g",
"--generate",
nargs="+",
help="generate source code for silecs xml file"
)
parser.add_argument(
"-d",
"--diagnostic",
help="start diagnostic tool for silecs xml file"
)
parser.add_argument(
"-m",
"--migrate",
help="migrate silecs design/deploy to new silecs version (TODO)"
)
return parser
def run():
parser = _parse_arguments()
try:
options = parser.parse_args()
except:
sys.exit(0)
if options.create:
silecs_validate(options.create)
if options.validate:
silecs_validate(options.validate)
if options.generate:
pass
if __name__ == "__main__":
run()
\ No newline at end of file
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