diff --git a/silecs-cli/info.py b/silecs-cli/info.py new file mode 100644 index 0000000000000000000000000000000000000000..b21fc069544a25b0deba8079d7f419ef7084368c --- /dev/null +++ b/silecs-cli/info.py @@ -0,0 +1,2 @@ +__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 diff --git a/silecs-cli/setup.py b/silecs-cli/setup.py new file mode 100644 index 0000000000000000000000000000000000000000..a4706dc8889d4bbcb39be81ce0eaa9413629b415 --- /dev/null +++ b/silecs-cli/setup.py @@ -0,0 +1,19 @@ +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 diff --git a/silecs-cli/silecs.py b/silecs-cli/silecs.py new file mode 100644 index 0000000000000000000000000000000000000000..a0818c4170927d95ff38f2421ffafe5d23729a44 --- /dev/null +++ b/silecs-cli/silecs.py @@ -0,0 +1,119 @@ +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