diff --git a/.nojekyll b/.nojekyll new file mode 100644 index 0000000..e69de29 diff --git a/python-launcher-docs/.buildinfo b/python-launcher-docs/.buildinfo new file mode 100644 index 0000000..c05ca8a --- /dev/null +++ b/python-launcher-docs/.buildinfo @@ -0,0 +1,4 @@ +# Sphinx build info version 1 +# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done. +config: ab06bdb9b7429c8e9fbfcc48055f2cec +tags: 645f666f9bcd5a90fca523b33c5a78b7 diff --git a/python-launcher-docs/_modules/index.html b/python-launcher-docs/_modules/index.html new file mode 100644 index 0000000..2bde254 --- /dev/null +++ b/python-launcher-docs/_modules/index.html @@ -0,0 +1,108 @@ + + +
+ + +
+# *************************************************************************
+# ** Copyright (c) 2024 CentraleSupélec & EDF.
+# ** All rights reserved. This program and the accompanying materials
+# ** are made available under the terms of the Eclipse Public License v2.0
+# ** which accompanies this distribution, and is available at
+# ** https://www.eclipse.org/legal/epl-v20.html
+# **
+# ** This file is part of the RiseClipse tool
+# **
+# ** Contributors:
+# ** Computer Science Department, CentraleSupélec
+# ** EDF R&D
+# ** Contacts:
+# ** dominique.marcadet@centralesupelec.fr
+# ** aurelie.dehouck-neveu@edf.fr
+# ** Web site:
+# ** https://riseclipse.github.io
+# *************************************************************************
+
+from abc import ABC
+from subprocess import run
+from shutil import which
+
+
+[docs]
+class JavaRunner(ABC):
+ """
+ Abstract class that carry out the execution of a ``jar`` file.
+
+ Attributes:
+ java_command (str): The path to the ``java`` command used to execute the jar file.
+ jar_file (str): The path to the ``jar`` file that will be executed.
+ result_code (None or int): The result code after execution of the ``jar`` file.
+ """
+
+
+[docs]
+ def __init__(self, jar_path: str):
+ """
+ Initialize the JavaRunner object.
+
+ The ``java`` command that will be used is initialized with ``shutil.which()``
+
+ Args:
+ jar_path: The path to the ``jar`` file.
+
+ """
+ self.jar_file = jar_path
+ self.java_command = which("java")
+ self.result_code = None
+
+
+
+[docs]
+ def set_jar_file(self, jar_path: str) -> None:
+ """
+ Change the ``jar`` file that will be executed.
+
+ Args:
+ jar_path: The path to the ``jar`` file.
+ """
+ self.jar_file = jar_path
+
+
+
+[docs]
+ def set_java_command(self, command: str) -> None:
+ """
+ Change the ``java`` command that will be used to execute the ``jar`` file.
+
+ Args:
+ command: The path to the ``java`` command.
+ """
+ self.java_command = command
+
+
+
+[docs]
+ def get_result_code(self) -> int:
+ """
+ Returns the result code after execution of the ``jar`` file.
+ Before execution, None is returned.
+
+ Returns:
+ The result code or None.
+ """
+ return self.result_code
+
+
+
+[docs]
+ def run(self, arguments: list[str]) -> str:
+ """
+ Executes the ``jar`` file using the current ``java`` command and the given arguments.
+
+ Args:
+ arguments: The arguments that are added to the command line.
+
+ Returns:
+ The text displayed on stdout while the ``jar`` executes.
+ """
+ command = [self.java_command, '-jar', self.jar_file] + [a for a in arguments]
+ result = run(command, capture_output=True, text=True)
+ self.result_code = result.returncode
+
+ return result.stdout
+
+
+
+
+# *************************************************************************
+# ** Copyright (c) 2024 CentraleSupélec & EDF.
+# ** All rights reserved. This program and the accompanying materials
+# ** are made available under the terms of the Eclipse Public License v2.0
+# ** which accompanies this distribution, and is available at
+# ** https://www.eclipse.org/legal/epl-v20.html
+# **
+# ** This file is part of the RiseClipse tool
+# **
+# ** Contributors:
+# ** Computer Science Department, CentraleSupélec
+# ** EDF R&D
+# ** Contacts:
+# ** dominique.marcadet@centralesupelec.fr
+# ** aurelie.dehouck-neveu@edf.fr
+# ** Web site:
+# ** https://riseclipse.github.io
+# *************************************************************************
+
+from urllib.request import urlopen, urlretrieve
+from urllib.error import URLError, HTTPError
+
+
+[docs]
+class RiseClipseDownload:
+
+ """
+ This class is used to download RiseClipse validator ``jar`` files.
+ """
+
+
+[docs]
+ def get_latest_version(self, repository: str) -> list[int]:
+ """
+ Get the latest version of the tool in the given repository of `RiseClipse organisation`_
+ on GitHub.
+
+ .. _RiseClipse organisation:
+ https://github.com/riseclipse
+
+ Example:
+ Get the latest version of RiseClipseValidatorSCL tool::
+
+ download = RiseClipseDownload()
+ download.get_latest_version('risceclipse_validator_scl2003')
+
+ Args:
+ repository: The repository of `RiseClipse organisation`_ dedicated to the wanted tool.
+
+ Returns:
+ A list of three integers giving the latest version.
+ """
+ url = 'https://github.com/riseclipse/' + repository + '/releases/latest'
+ page = None
+ try:
+ page = urlopen(url)
+ except HTTPError as e:
+ print('Getting ', url, ' failed, error code: ', e.code)
+ return None
+ except URLError as e:
+ print('Getting ', url, ' failed, reason: ', e.reason)
+ return None
+
+ title = None
+ for line in page:
+ line = line.lstrip().decode("utf-8")
+ if line.startswith('<title>'):
+ title = line
+ break
+
+ if title == None:
+ return None
+
+ start = '<title>Release ' + repository + ' v'
+ if not title.startswith(start):
+ return None
+ version = title[len(start):]
+ version = version.split()[0]
+ version = version.split('.')
+ for i in range(len(version)):
+ version[i] = int(version[i])
+ return version
+
+
+
+[docs]
+ def download_version(self, repository : str, name: str, version: list[int], output: str) -> None:
+ """
+ Download the ``jar`` of the tool in the given repository of `RiseClipse organisation`_
+ on GitHub, with the given name and version, put it in the file with the given path.
+
+ .. _RiseClipse organisation:
+ https://github.com/riseclipse
+
+ Example:
+ Get the latest version of RiseClipseValidatorSCL tool::
+
+ download = RiseClipseDownload()
+ download.download_version('risceclipse_validator_scl2003', 'RiseClipseValidatorSCL', [1, 2, 7], 'RiseClipseValidatorSCL.jar')
+
+ Args:
+ repository: The repository of `RiseClipse organisation`_ dedicated to the wanted tool.
+ name: the name of the ``jar`` file without the version number.
+ version: the requested version.
+ output: the path where the ``jar`` will be saved.
+ """
+ version = '%d.%d.%d' % (version[0], version[1], version[2])
+ url = 'https://github.com/riseclipse/' + repository + '/releases/download/'
+ url = url + repository + '-' + version + '/' + name + '-' + version + '.jar'
+ try:
+ urlretrieve(url, output)
+ except HTTPError as e:
+ print('Downloading ', url, ' failed, error code: ', e.code)
+ except URLError as e:
+ print('Downloading ', url, ' failed, reason: ', e.reason)
+
+
+
+
+#r = RiseClipseDownload()
+#r.get_latest_version('riseclipse-validator-scl2003')
+#r.get_latest_version('riseclipse-validator-cgmes-3-0-0')
+
+#r.download_version('riseclipse-validator-scl2003', 'RiseClipseValidatorSCL', [1, 2, 7], 'validator.jar')
+#r.download_version('riseclipse-validator-cgmes-3-0-0', 'RiseClipseValidatorCGMES3', [1, 0, 3], 'validator.jar')
+
+# *************************************************************************
+# ** Copyright (c) 2024 CentraleSupélec & EDF.
+# ** All rights reserved. This program and the accompanying materials
+# ** are made available under the terms of the Eclipse Public License v2.0
+# ** which accompanies this distribution, and is available at
+# ** https://www.eclipse.org/legal/epl-v20.html
+# **
+# ** This file is part of the RiseClipse tool
+# **
+# ** Contributors:
+# ** Computer Science Department, CentraleSupélec
+# ** EDF R&D
+# ** Contacts:
+# ** dominique.marcadet@centralesupelec.fr
+# ** aurelie.dehouck-neveu@edf.fr
+# ** Web site:
+# ** https://riseclipse.github.io
+# *************************************************************************
+
+from riseclipse_parser import RiseClipseParser
+import json
+import pandas as pd
+
+
+
+[docs]
+class RiseClipseOutput:
+ """
+ A class used to parse and categorize messages from the Validator in order to use them
+ in Python scripts.
+ """
+
+
+[docs]
+ def __init__(self, list_of_messages: list[str]):
+ """
+ Constructs all the necessary attributes for the RiseClipseOutput object.
+
+ Args:
+ list_of_messages: a list of messages to be parsed and categorized
+ """
+ self.errors = []
+ self.warnings = []
+ self.notices = []
+ self.infos = []
+ self.only_warnings = []
+ self.only_notices = []
+ self.only_infos = []
+ self.parsed_messages = RiseClipseParser(list_of_messages).parsed_messages
+
+
+
+[docs]
+ def get_errors(self) -> list[dict]:
+ """
+ Returns a list of parsed error messages (dictionaries). To see the exact format,
+ see :py:class:`~riseclipse_parser.RiseClipseParser`.
+
+ If the list of errors is not empty, it returns the list. Otherwise, it parses the
+ messages and appends any error messages to the list.
+
+ Returns:
+ a list of parsed error messages
+ """
+ if len(self.errors) > 0:
+ return self.errors
+ for message in self.parsed_messages:
+ if message["severity"] == "ERROR":
+ self.errors.append(message)
+ return self.errors
+
+
+
+[docs]
+ def get_warnings(self) -> list[dict]:
+ """
+ Returns a list of parsed warning and error messages (dictionaries). To see the exact
+ format, see :py:class:`~riseclipse_parser.RiseClipseParser`.
+
+ If the list of warnings and errors is not empty, it returns the list. Otherwise,
+ it parses the messages and appends any warning or error messages to the list.
+
+ Returns:
+ a list of parsed warning and error messages
+ """
+ if len(self.warnings) > 0:
+ return self.warnings
+ for message in self.parsed_messages:
+ if message["severity"] in ["WARNING","ERROR"]:
+ self.warnings.append(message)
+ return self.warnings
+
+
+
+[docs]
+ def get_notices(self) -> list[dict]:
+ """
+ Returns a list of parsed notice, warning and error messages (dictionaries).
+ To see the exact format, see :py:class:`~riseclipse_parser.RiseClipseParser`.
+
+ If the list of notices, warnings and errors is not empty, it returns the list.
+ Otherwise, it parses the messages and appends any notice, warning and error messages
+ to the list.
+
+ Returns:
+ a list of parsed notice, warning and error messages
+ """
+ if len(self.notices) > 0:
+ return self.notices
+ for message in self.parsed_messages:
+ if message["severity"] in ["WARNING","ERROR","NOTICE"]:
+ self.notices.append(message)
+ return self.notices
+
+
+
+[docs]
+ def get_infos(self) -> list[dict]:
+ """
+ Returns a list of parsed info, notices, warnings and errors messages (dictionaries).
+ To see the exact format, see :py:class:`~riseclipse_parser.RiseClipseParser`.
+
+ If the list of infos, notices, warnings and errors is not empty, it returns the
+ list. Otherwise, it parses the messages and appends any info, notice, warning and
+ error messages to the list.
+
+ Returns:
+ a list of parsed info, notice, warning and error messages
+ """
+ if len(self.infos) > 0:
+ return self.infos
+ for message in self.parsed_messages:
+ if message["severity"] in ["WARNING","ERROR","INFO","NOTICE"]:
+ self.infos.append(message)
+ return self.infos
+
+
+
+[docs]
+ def get_only_warnings(self) -> list[dict]:
+ """
+ Returns a list of parsed warning messages (dictionaries). To see the exact format,
+ see :py:class:`~riseclipse_parser.RiseClipseParser`.
+
+ If the list of warnings is not empty, it returns the list. Otherwise, it parses
+ the messages and appends any warning messages to the list.
+
+ Returns:
+ a list of parsed warning messages
+ """
+ if len(self.only_warnings) > 0:
+ return self.only_warnings
+ for message in self.parsed_messages:
+ if message["severity"] == "WARNING":
+ self.only_warnings.append(message)
+ return self.only_warnings
+
+
+
+[docs]
+ def get_only_notices(self) -> list[dict]:
+ """
+ Returns a list of parsed notice messages (dictionaries). To see the exact format,
+ see :py:class:`~riseclipse_parser.RiseClipseParser`.
+
+ If the list of notices is not empty, it returns the list. Otherwise, it parses the
+ messages and appends any notice messages to the list.
+
+ Returns:
+ a list of parsed notice messages
+ """
+ if len(self.notices) > 0:
+ return self.only_notices
+ for message in self.parsed_messages:
+ if message["severity"] == "NOTICE":
+ self.only_notices.append(message)
+ return self.only_notices
+
+
+
+[docs]
+ def get_only_infos(self) -> list[dict]:
+ """
+ Returns a list of parsed info messages (dictionaries). To see the exact format,
+ see :py:class:`~riseclipse_parser.RiseClipseParser`.
+
+ If the list of infos is not empty, it returns the list. Otherwise, it parses the
+ messages and appends any info messages to the list.
+
+ Returns:
+ a list of parsed info messages
+ """
+ if len(self.only_infos) > 0:
+ return self.only_infos
+ for message in self.parsed_messages:
+ if message["severity"] == "INFO":
+ self.only_infos.append(message)
+ return self.only_infos
+
+
+
+[docs]
+ def get_all_messages(self) -> list[dict]:
+ """
+ Returns a list of all parsed messages (dictionaries). To see the exact format,
+ see :py:class:`~riseclipse_parser.RiseClipseParser`.
+
+ Returns:
+ a list of all parsed messages
+ """
+ return self.parsed_messages
+
+
+
+[docs]
+ def get_messages_by_category(self, category: str) -> list[dict]:
+ """
+ Returns a list of messages, filtered by category.
+ The category does not have to be an exact match, it can be a substring of the category.
+
+ Args:
+ category: The category to filter the messages by
+
+ Returns:
+ a list of parsed messages filtered by category
+ """
+ messages = []
+ for message in self.parsed_messages:
+ if category in message["category"]:
+ messages.append(message)
+ return messages
+
+
+
+[docs]
+ def get_messages_by_specific_message(self, data: str) -> list[dict]:
+ """
+ Returns a list of messages, filtered by a specific part of message, named data.
+ The data does not have to be an exact match, it can be a substring of the message.
+
+ Args:
+ data: the "data" e.g. specific message to filter the messages by
+
+ Returns:
+ """
+ messages = []
+ for message in self.parsed_messages:
+ if data in message["data"]:
+ messages.append(message)
+ return messages
+
+
+
+[docs]
+ def get_messages_by_filename(self, filename: str) -> list[dict]:
+ """
+ Returns a list of messages, filtered by the file containing the error/warning/notice/info.
+
+ Args:
+ filename: The filename to filter the messages by
+
+ Returns:
+ a list of parsed messages filtered by filename
+ """
+ messages = []
+ for message in self.parsed_messages:
+ if message["filename"] == filename:
+ messages.append(message)
+ return messages
+
+
+
+[docs]
+ def get_messages_by_line(self, line) -> list[dict]:
+ """
+ Returns a list of messages, filtered by the line number in the file containing
+ the error/warning/notice/info.
+
+ Args:
+ line: the line number to filter the messages by
+
+ Returns:
+ a list of parsed messages filtered by line number
+ """
+ messages = []
+ for message in self.parsed_messages:
+ if message["line"] == line:
+ messages.append(message)
+ return messages
+
+
+
+[docs]
+ def get_messages_with_filter(self, filtering_dict: dict) -> list[dict]:
+ """
+ Returns a list of messages, filtered with a dictionnary containing informations on
+ which we want to filter messages in the file containing the error/warning/notice/info.
+
+ Args:
+ filtering_dict: the filter itself, fields of the dictionary are the the same as a parsed message
+
+ Returns:
+ a list of parsed messages filtered according to the filter
+ """
+ messages = []
+ for message in self.parsed_messages:
+ b = True
+ for filt in filtering_dict:
+ if filt == "category" or filt == "data":
+ b = b and (filtering_dict[filt] in message[filt])
+ else:
+ b = b and (filtering_dict[filt] == message[filt])
+
+
+
+ if b :
+ messages.append(message)
+ return messages
+
+
+
+[docs]
+ def to_csv(self, path: str, separator: str =",") -> str:
+ """
+ Writes the parsed messages to a CSV file and returns the CSV as a string.
+
+ Args:
+ path: The path to write the CSV file to
+ separator: The separator to use in the csv file
+
+ Returns:
+ a string of the CSV file
+ """
+ if len(self.parsed_messages) == 0:
+ print("No messages to write to CSV.")
+ return ""
+
+ csv = ""
+ message = self.parsed_messages[0]
+ for key in message:
+ if key != "message":
+ csv += key + separator
+ csv += "message\n"
+ for message in self.parsed_messages:
+ for key in message:
+ if key != "message":
+ csv += message[key] + separator
+ csv += message["message"] + "\n"
+ with open(path, "w") as f:
+ f.write(csv)
+ return csv
+
+
+
+[docs]
+ def to_json(self,path: str)-> dict:
+ """
+ Writes the parsed messages to a JSON file and returns the JSON as a dictionary.
+
+ Args:
+ path: The path to write the JSON file to
+
+ Returns:
+ a dictionary of the JSON file
+ """
+ json_dump = {}
+ for i in range(len(self.parsed_messages)):
+ json_dump[i] = self.parsed_messages[i]
+ with open(path, "w") as f:
+ json.dump(json_dump, f)
+ return json_dump
+
+
+
+[docs]
+ def to_dataframe(self) -> pd.DataFrame:
+ """
+ Returns a pandas DataFrame of the parsed messages.
+
+ Returns:
+ a pandas DataFrame of the parsed messages
+ """
+ import pandas as pd
+ dict_columns = {'message':[],'category':[],'line':[],'data':[],'filename':[],'severity':[]}
+ for message in self.parsed_messages:
+ dict_columns['message'].append(message['message'])
+ dict_columns['category'].append(message['category'])
+ dict_columns['line'].append(message['line'])
+ dict_columns['data'].append(message['data'])
+ dict_columns['filename'].append(message['filename'])
+ dict_columns['severity'].append(message['severity'])
+ return pd.DataFrame.from_dict(dict_columns)
+
+
+
+
+
+# *************************************************************************
+# ** Copyright (c) 2024 CentraleSupélec & EDF.
+# ** All rights reserved. This program and the accompanying materials
+# ** are made available under the terms of the Eclipse Public License v2.0
+# ** which accompanies this distribution, and is available at
+# ** https://www.eclipse.org/legal/epl-v20.html
+# **
+# ** This file is part of the RiseClipse tool
+# **
+# ** Contributors:
+# ** Computer Science Department, CentraleSupélec
+# ** EDF R&D
+# ** Contacts:
+# ** dominique.marcadet@centralesupelec.fr
+# ** aurelie.dehouck-neveu@edf.fr
+# ** Web site:
+# ** https://riseclipse.github.io
+# *************************************************************************
+
+import copy
+
+
+[docs]
+class RiseClipseParser:
+ """
+ A class used to parse messages from RiseClipseValidator.
+ This class is used to convert raw messages into a structured format that can be easily
+ processed or displayed.
+ """
+
+[docs]
+ def __init__(self, list_of_messages: list[str]):
+ """
+ Constructs all the necessary attributes for the RiseClipseParser object.
+
+ Args:
+ list_of_messages: The list of messages to be parsed
+ """
+ self.list_of_messages = list_of_messages
+ self.parsed_messages = []
+ if self.list_of_messages != None and len(self.list_of_messages) > 0:
+ self.parse_messages()
+ else:
+ print("No messages to parse.")
+
+
+
+[docs]
+ def get_parsed_messages(self) -> list[str]:
+ """
+ Returns the list of parsed messages.
+ """
+ return self.parsed_messages
+
+
+
+[docs]
+ def parse_messages(self):
+ """
+ Iterates over each message in the list and parses it using the parse_message method.
+ Appends the parsed message to the parsed_messages attribute.
+ """
+ for message in self.list_of_messages:
+ if len(message) > 0:
+ self.parsed_messages.append(self.parse_message(message))
+
+
+
+[docs]
+ def parse_message(self, message: str) -> dict:
+ """
+ Parses a single message into a dictionary with keys for ``message``, ``category``, ``line``, ``data``, ``filename``, and ``severity``.
+ Each key's value is extracted from the message by splitting the message string on commas and selecting the appropriate element.
+
+ Args:
+ message: A single message to be parsed i.e. a line from the standard output of the validator
+
+ Returns:
+ A dictionary containing the parsed message.
+ Keys of the dictionary are ``message``, ``category``, ``line``, ``data``, ``filename``, and ``severity``:
+
+ * the field ``message`` contains the original non-parsed message
+ * the field ``category`` contains the category of the message
+ * the field ``line`` contains the line number in the file targetted by the message
+ * the field ``data`` contains the part of the message that contains the actual error/warning/notice/info
+ * the field ``filename`` contains the name of the file targetted by the message
+ * the field ``severity`` contains the severity of the message (ERROR, WARNING, NOTICE, INFO, DEBUG)
+
+ """
+ import re
+ #print("Parsing message: " + message)
+ parsed_message = {}
+ parsed_message["message"] = message
+
+ regex_end = r'\((\w|\W)*\)'
+ regex_middle = r'\[(\w|\W)*\]'
+ match = re.search(regex_end, message)
+ filename = match[0].strip()[1:-1].split(":")[0]
+ line = match[0].strip()[1:-1].split(":")[1]
+ message = re.sub(regex_end, '', message)
+ match = re.search(regex_middle, message)
+ category = match[0].strip()[1:-1]
+ message = re.sub(regex_middle, '', message)
+ severity = message[:8].strip()
+ message = copy.copy(message[9:].strip())
+ data = message.strip()
+
+ parsed_message["category"] = category
+ parsed_message["line"] = line
+ parsed_message["data"] = data
+ parsed_message["filename"] = filename
+ parsed_message["severity"] = severity
+ return parsed_message
+
+
+
+
+
+# *************************************************************************
+# ** Copyright (c) 2024 CentraleSupélec & EDF.
+# ** All rights reserved. This program and the accompanying materials
+# ** are made available under the terms of the Eclipse Public License v2.0
+# ** which accompanies this distribution, and is available at
+# ** https://www.eclipse.org/legal/epl-v20.html
+# **
+# ** This file is part of the RiseClipse tool
+# **
+# ** Contributors:
+# ** Computer Science Department, CentraleSupélec
+# ** EDF R&D
+# ** Contacts:
+# ** dominique.marcadet@centralesupelec.fr
+# ** aurelie.dehouck-neveu@edf.fr
+# ** Web site:
+# ** https://riseclipse.github.io
+# *************************************************************************
+
+from java_runner import JavaRunner
+from riseclipse_output import RiseClipseOutput
+
+
+
+[docs]
+class RiseClipseValidator(JavaRunner) :
+ """
+ Base class for RiseClipse validators. It takes care of common options.
+
+ Attributes:
+ options (list[str]): The set of options that will be added when the validation is launched.
+ level (str): The level of displayed messages, initialized to ``"warning"``.
+ format_string (str): The format string used by the ``java.util.Formatter``.
+ use_color (bool): Whether colors are used when result is displayed on stdout, initialized to ``False``.
+ files (list[str]): The files that will be given to the validator.
+ """
+
+
+[docs]
+ def __init__(self, jarPath: str):
+ """
+ Initialize the RiseClipseValidator object.
+
+ Args:
+ jar_path: The path to the validator ``jar`` file
+ """
+ super().__init__(jarPath)
+ #
+ self.options = []
+ # specific field for output level
+ self.level = "warning"
+ # --format-string must not be used if the output is processed
+ self.format_string = ""
+ # --use-color only meaningful for validate_to_stdout
+ self.use_color = False
+ # path to files must be at the end
+ self.files = []
+
+
+
+[docs]
+ def get_output_level(self) -> str:
+ """
+ Returns:
+ the current output level, one of ``"debug"``, ``"info"``, ``"notice"``, ``"warning"`` or ``"error"``.
+ """
+ return self.level
+
+
+
+[docs]
+ def set_output_level(self, new_level: str) -> None:
+ """
+ Set the current output level.
+
+ Args:
+ new_level: The new output level.
+ Must be ``"debug"``, ``"info"``, ``"notice"``, ``"warning"`` or ``"error"``.
+ """
+ match level:
+ case "debug" | "info" | "notice" | "warning" | "error":
+ self.level = new_level
+
+
+
+[docs]
+ def get_output_format(self) -> str:
+ """
+ Returns the current format string used for output.
+
+ Returns:
+ The current format string.
+ """
+ return self.format_string
+
+
+
+[docs]
+ def set_output_format(self, format: str) -> None:
+ """
+ Set the current format string used for output.
+
+ Args:
+ format: The new format string, its validity is not checked.
+ """
+ # not checked
+ self.format_string = format
+
+
+
+[docs]
+ def get_use_color(self) -> bool:
+ """
+ Returns whether color is used.
+
+ Returns:
+ True if color will be used, False Otherwise.
+ """
+ return self.use_color
+
+
+
+[docs]
+ def set_use_color(self, use: bool=True) -> None:
+ """
+ Set whether color will be used for output.
+
+ Args:
+ use: If True, color will be used.
+ """
+ self.use_color = use
+
+
+ DO_NOT_DISPLAY_COPYRIGHT_OPTION = "--do-not-display-copyright"
+
+
+[docs]
+ def get_display_copyright(self) -> bool:
+ """
+ Returns whether the copyright is displayed.
+
+ Returns:
+ True if the copyright is displayed, False Otherwise.
+ """
+ return self.DO_NOT_DISPLAY_COPYRIGHT_OPTION not in self.options
+
+
+
+[docs]
+ def set_display_copyright(self, display: bool=True) -> None:
+ """
+ Set whether the copyright is displayed.
+
+ Args:
+ display: If True, copyright will be displayed.
+ """
+ if display:
+ self.options.remove(self.DO_NOT_DISPLAY_COPYRIGHT_OPTION)
+ elif self.get_display_copyright():
+ self.options.append(self.DO_NOT_DISPLAY_COPYRIGHT_OPTION)
+
+
+
+[docs]
+ def add_file(self, file: str) -> None:
+ """
+ Add a file to be processed by the validator.
+
+ Args:
+ file: The path to the file or directory to be processed.
+ """
+ self.files.append(file)
+
+
+
+[docs]
+ def _add_option(self, opt: str, value: str=None) -> None:
+ """
+ Add an option to the command line. An associated value may be specified.
+
+ Note:
+ This method is intended to be used by subclasses
+
+ Args:
+ opt: The option to be added.
+ value: The value to be added after the option.
+ """
+ if opt in self.options:
+ if value != None:
+ self.options[self.options.index(opt) + 1] = value
+ else:
+ self.options.append(opt)
+ if value != None:
+ self.options.append(value)
+
+
+
+[docs]
+ def _remove_option(self, opt:str, has_value=False) -> None:
+ """
+ Remove an option from the command line.
+
+ Note:
+ This method is intended to be used by subclasses
+
+ Args:
+ opt: The option to be removed.
+ has_value: Whether there was also an associated value.
+ """
+ if opt in self.options:
+ pos = self.options.index(opt)
+ self.options.pop(pos)
+ if has_value:
+ self.options.pop(pos)
+
+
+
+[docs]
+ def _compute_arguments(self, display_copyright: bool=True, use_format: bool=True, set_color: bool=False) -> list[str]:
+ """
+ Returns the arguments that will be passed to the run() method.
+
+ Note:
+ This method is intended to be internal
+
+ Args:
+ display_copyright: Whether the display_copyright setting must be taken into account. Default is True.
+ use_format: Whether the format_string setting must be taken into account. Default is True.
+ set_color: Whether the use_color setting must be taken into account. Default is False.
+
+ Returns:
+ The list of strings that will be passed to the run() method.
+ """
+ arguments = ['--' + self.level]
+ if use_format and self.format_string != "":
+ arguments.append("--format-string")
+ arguments.append(self.format_string)
+ if set_color:
+ if self.use_color:
+ arguments.append("--use-color")
+ if not display_copyright:
+ self.set_display_copyright(False)
+ for option in self.options:
+ arguments.append(option)
+ for file in self.files:
+ arguments.append(file)
+
+ return arguments
+
+
+
+
+
+[docs]
+ def validate(self) -> RiseClipseOutput:
+ """
+ Runs the validator with the current set of arguments and files.
+
+ Returns:
+ An object representing the result of validation.
+ """
+ arguments = self._compute_arguments(display_copyright=False, use_format=False)
+ return RiseClipseOutput(self.run(arguments).split('\n'))
+
+
+
+[docs]
+ def validate_to_str(self) -> str:
+ """
+ Runs the validator with the current set of arguments and files.
+
+ Returns:
+ The result of validation as a string.
+ """
+ arguments = self._compute_arguments()
+ return self.run(arguments)
+
+
+
+[docs]
+ def validate_to_stdout(self) -> None:
+ """
+ Runs the validator with the current set of arguments and files.
+ Display the result on stdout.
+ """
+ arguments = self._compute_arguments(set_color=True)
+ print(self.run(arguments))
+
+
+
+[docs]
+ def validate_to_txt(self, outputFile: str="riseclipse_output.txt") -> None:
+ """
+ Runs the validator with the current set of arguments and files.
+ Save the result in the given file.
+
+ Args:
+ outputFile: The path to the file where the result will be saved.
+ """
+ arguments = self._compute_arguments()
+ result = self.run(arguments)
+ output_file = open(outputFile, "w")
+ output_file.write(result)
+ output_file.close()
+
+
+
+[docs]
+ def get_current_version(self) -> list[int]:
+ """
+ Returns the current version of the ``jar`` file used by this object.
+
+ Returns:
+ A list of three integers giving the current version.
+ """
+ copyright = self.run(["--help"]).split('\n')[16]
+ version_pos = copyright.find("version: ")
+ version = copyright[version_pos + len("version: "):]
+ version = version.split()[0]
+ version = version.split('.')
+ for i in range(len(version)):
+ version[i] = int(version[i])
+ return version
+
+
+
+
+# *************************************************************************
+# ** Copyright (c) 2024 CentraleSupélec & EDF.
+# ** All rights reserved. This program and the accompanying materials
+# ** are made available under the terms of the Eclipse Public License v2.0
+# ** which accompanies this distribution, and is available at
+# ** https://www.eclipse.org/legal/epl-v20.html
+# **
+# ** This file is part of the RiseClipse tool
+# **
+# ** Contributors:
+# ** Computer Science Department, CentraleSupélec
+# ** EDF R&D
+# ** Contacts:
+# ** dominique.marcadet@centralesupelec.fr
+# ** aurelie.dehouck-neveu@edf.fr
+# ** Web site:
+# ** https://riseclipse.github.io
+# *************************************************************************
+
+from pathlib import Path
+from sys import argv
+
+from riseclipse_validator import RiseClipseValidator
+from riseclipse_download import RiseClipseDownload
+
+
+RISECLIPSE_VALIDATOR_SCL_JAR = "RiseClipseValidatorSCL.jar"
+
+
+
+[docs]
+class RiseClipseValidatorSCL(RiseClipseValidator) :
+ """
+ This class is a launcher for the ``RiseClipseValidatorSCL.jar`` tool.
+
+ It offers specific options for this validator.
+
+ Note:
+ The script ``riseclipse_validator_scl.py`` can also be executed directly, it allows to donwload or update the
+ validator ``jar`` file needed for this API.
+ """
+
+
+[docs]
+ def __init__(self):
+ """
+ Initialize the RiseClipseValidatorSCL object.
+
+ In the initial state, one can considered that the following methods have been called:
+ * :py:meth:`set_output_level("warning") <riseclipse_validator.RiseClipseValidator.set_output_level>`
+ * :py:meth:`set_output_format('%6$s%1$-7s%7$s: [%2$s] %4$s (%5$s:%3$d)') <riseclipse_validator.RiseClipseValidator.set_output_format>`
+ * :py:meth:`set_use_color(False) <riseclipse_validator.RiseClipseValidator.set_use_color>`
+ * :py:meth:`set_display_copyright(True) <riseclipse_validator.RiseClipseValidator.set_display_copyright>`
+ * :py:meth:`set_make_explicit_links`
+ * :py:meth:`unset_xml_schema`
+ * :py:meth:`unset_display_nsd_messages`
+ * :py:meth:`unset_use_different_exit_codes`
+ * :py:meth:`unset_use_filenames_starting_with_dot`
+
+ """
+ super().__init__(RISECLIPSE_VALIDATOR_SCL_JAR)
+ # by default, explicit links are created
+ self._add_option("--make-explicit-links")
+
+
+
+[docs]
+ def set_make_explicit_links(self):
+ """
+ Build explicit links before doing validation.
+ """
+ self._add_option("--make-explicit-links")
+
+
+
+[docs]
+ def unset_make_explicit_links(self):
+ """
+ Don't build explicit links before doing validation.
+ """
+ self.__remove_option("--make-explicit-links")
+
+
+
+[docs]
+ def set_xml_schema(self, schema_path: str):
+ """
+ Do an XMLSchema validation.
+
+ Args:
+ schema_path: The path to the XML Schema file
+ """
+ self._add_option("--xml-schema", schema_path)
+
+
+
+[docs]
+ def unset_xml_schema(self):
+ """
+ Don't do an XMLSchema validation.
+ """
+ self._remove_option("--xml-schema", True)
+
+
+
+[docs]
+ def set_display_nsd_messages(self):
+ """
+ Display messages concerning the loading of NSD files.
+ """
+ self._add_option("--display-nsd-messages")
+
+
+
+[docs]
+ def unset_display_nsd_messages(self):
+ """
+ Don't display messages concerning the loading of NSD files.
+ """
+ self._remove_option("--display-nsd-messages")
+
+
+
+[docs]
+ def set_use_different_exit_codes(self):
+ """
+ Returns different exit codes according to the higher severity in messages.
+ """
+ self._add_option("--use-different-exit-codes")
+
+
+
+[docs]
+ def unset_use_different_exit_codes(self):
+ """
+ Don't returns different exit codes according to the higher severity in messages.
+ """
+ self._remove_option("--use-different-exit-codes")
+
+
+
+[docs]
+ def set_use_filenames_starting_with_dot(self):
+ """
+ Take into account files starting with a dot.
+ """
+ self._add_option("--use-filenames-starting-with-dot")
+
+
+
+[docs]
+ def unset_use_filenames_starting_with_dot(self):
+ """
+ Don't take into account files starting with a dot.
+ """
+ self._remove_option("--use-filenames-starting-with-dot")
+
+
+
+
+
+if __name__ == '__main__':
+ if len(argv) == 1:
+ jar = Path(RISECLIPSE_VALIDATOR_SCL_JAR)
+
+ if not jar.exists():
+ print("It seems that the validator is missing.")
+ print("You can download one using '--download latest' command line option (or use a specific version instead of latest).")
+ exit(0)
+
+ validator = RiseClipseValidatorSCL()
+ current_version = validator.get_current_version()
+ download = RiseClipseDownload()
+ print("Your version is: %d.%d.%d" % (current_version[0], current_version[1], current_version[2]))
+ latest_version = download.get_latest_version("riseclipse-validator-scl2003")
+ if current_version < latest_version:
+ print("A new version is available: %d.%d.%d" % (latest_version[0], latest_version[1], latest_version[2]))
+ print("You can download it using '--download latest' command line option")
+ if current_version == latest_version:
+ print("Your version is the latest one")
+
+ if len(argv) == 3:
+ if argv[1] == "--download":
+ download = RiseClipseDownload()
+ if argv[2] == "latest":
+ version = download.get_latest_version("riseclipse-validator-scl2003")
+ if version == None:
+ exit()
+ version_str = "%d.%d.%d" % (version[0], version[1], version[2])
+ print("Latest version is ", version_str)
+ else:
+ version = argv[2].split('.')
+ for i in range(len(version)):
+ version[i] = int(version[i])
+
+ download.download_version("riseclipse-validator-scl2003", "RiseClipseValidatorSCL", version, RISECLIPSE_VALIDATOR_SCL_JAR)
+
+
+
+
+
' + + '' + + _("Hide Search Matches") + + "
" + ) + ); + }, + + /** + * helper function to hide the search marks again + */ + hideSearchWords: () => { + document + .querySelectorAll("#searchbox .highlight-link") + .forEach((el) => el.remove()); + document + .querySelectorAll("span.highlighted") + .forEach((el) => el.classList.remove("highlighted")); + localStorage.removeItem("sphinx_highlight_terms") + }, + + initEscapeListener: () => { + // only install a listener if it is really needed + if (!DOCUMENTATION_OPTIONS.ENABLE_SEARCH_SHORTCUTS) return; + + document.addEventListener("keydown", (event) => { + // bail for input elements + if (BLACKLISTED_KEY_CONTROL_ELEMENTS.has(document.activeElement.tagName)) return; + // bail with special keys + if (event.shiftKey || event.altKey || event.ctrlKey || event.metaKey) return; + if (DOCUMENTATION_OPTIONS.ENABLE_SEARCH_SHORTCUTS && (event.key === "Escape")) { + SphinxHighlight.hideSearchWords(); + event.preventDefault(); + } + }); + }, +}; + +_ready(() => { + /* Do not call highlightSearchWords() when we are on the search page. + * It will highlight words from the *previous* search query. + */ + if (typeof Search === "undefined") SphinxHighlight.highlightSearchWords(); + SphinxHighlight.initEscapeListener(); +}); diff --git a/python-launcher-docs/genindex.html b/python-launcher-docs/genindex.html new file mode 100644 index 0000000..2f531bb --- /dev/null +++ b/python-launcher-docs/genindex.html @@ -0,0 +1,439 @@ + + + + + ++ | + |
+ |
+ | + |
+ | + |
+ |
|
+
+ |
|
+
+ |
+ | + |
|
+
|
+
+ | + |
+ | + |
+ | + |
Bases: ABC
Abstract class that carry out the execution of a jar
file.
The path to the java
command used to execute the jar file.
str
+The path to the jar
file that will be executed.
str
+The result code after execution of the jar
file.
None or int
+Initialize the JavaRunner object.
+The java
command that will be used is initialized with shutil.which()
jar_path – The path to the jar
file.
Change the jar
file that will be executed.
jar_path – The path to the jar
file.
Change the java
command that will be used to execute the jar
file.
command – The path to the java
command.
RiseClipseOutput
RiseClipseOutput.__init__()
RiseClipseOutput.get_errors()
RiseClipseOutput.get_warnings()
RiseClipseOutput.get_notices()
RiseClipseOutput.get_infos()
RiseClipseOutput.get_only_warnings()
RiseClipseOutput.get_only_notices()
RiseClipseOutput.get_only_infos()
RiseClipseOutput.get_all_messages()
RiseClipseOutput.get_messages_by_category()
RiseClipseOutput.get_messages_by_specific_message()
RiseClipseOutput.get_messages_by_filename()
RiseClipseOutput.get_messages_by_line()
RiseClipseOutput.get_messages_with_filter()
RiseClipseOutput.to_csv()
RiseClipseOutput.to_json()
RiseClipseOutput.to_dataframe()
RiseClipseValidator
RiseClipseValidator.options
RiseClipseValidator.level
RiseClipseValidator.format_string
RiseClipseValidator.use_color
RiseClipseValidator.files
RiseClipseValidator.__init__()
RiseClipseValidator.get_output_level()
RiseClipseValidator.set_output_level()
RiseClipseValidator.get_output_format()
RiseClipseValidator.set_output_format()
RiseClipseValidator.get_use_color()
RiseClipseValidator.set_use_color()
RiseClipseValidator.DO_NOT_DISPLAY_COPYRIGHT_OPTION
RiseClipseValidator.get_display_copyright()
RiseClipseValidator.set_display_copyright()
RiseClipseValidator.add_file()
RiseClipseValidator._add_option()
RiseClipseValidator._remove_option()
RiseClipseValidator._compute_arguments()
RiseClipseValidator.validate()
RiseClipseValidator.validate_to_str()
RiseClipseValidator.validate_to_stdout()
RiseClipseValidator.validate_to_txt()
RiseClipseValidator.get_current_version()
RiseClipseValidatorSCL
RiseClipseValidatorSCL.__init__()
RiseClipseValidatorSCL.set_make_explicit_links()
RiseClipseValidatorSCL.unset_make_explicit_links()
RiseClipseValidatorSCL.set_xml_schema()
RiseClipseValidatorSCL.unset_xml_schema()
RiseClipseValidatorSCL.set_display_nsd_messages()
RiseClipseValidatorSCL.unset_display_nsd_messages()
RiseClipseValidatorSCL.set_use_different_exit_codes()
RiseClipseValidatorSCL.unset_use_different_exit_codes()
RiseClipseValidatorSCL.set_use_filenames_starting_with_dot()
RiseClipseValidatorSCL.unset_use_filenames_starting_with_dot()
+ j | ||
+ |
+ java_runner | + |
+ r | ||
+ |
+ riseclipse_download | + |
+ |
+ riseclipse_output | + |
+ |
+ riseclipse_parser | + |
+ |
+ riseclipse_validator | + |
+ |
+ riseclipse_validator_scl | + |
Bases: object
This class is used to download RiseClipse validator jar
files.
Get the latest version of the tool in the given repository of RiseClipse organisation +on GitHub.
+Example
+Get the latest version of RiseClipseValidatorSCL tool:
+download = RiseClipseDownload()
+download.get_latest_version('risceclipse_validator_scl2003')
+
repository – The repository of RiseClipse organisation dedicated to the wanted tool.
+A list of three integers giving the latest version.
+Download the jar
of the tool in the given repository of RiseClipse organisation
+on GitHub, with the given name and version, put it in the file with the given path.
Example
+Get the latest version of RiseClipseValidatorSCL tool:
+download = RiseClipseDownload()
+download.download_version('risceclipse_validator_scl2003', 'RiseClipseValidatorSCL', [1, 2, 7], 'RiseClipseValidatorSCL.jar')
+
repository – The repository of RiseClipse organisation dedicated to the wanted tool.
name – the name of the jar
file without the version number.
version – the requested version.
output – the path where the jar
will be saved.
Bases: object
A class used to parse and categorize messages from the Validator in order to use them +in Python scripts.
+Constructs all the necessary attributes for the RiseClipseOutput object.
+list_of_messages – a list of messages to be parsed and categorized
+Returns a list of parsed error messages (dictionaries). To see the exact format,
+see RiseClipseParser
.
If the list of errors is not empty, it returns the list. Otherwise, it parses the +messages and appends any error messages to the list.
+a list of parsed error messages
+Returns a list of parsed warning and error messages (dictionaries). To see the exact
+format, see RiseClipseParser
.
If the list of warnings and errors is not empty, it returns the list. Otherwise, +it parses the messages and appends any warning or error messages to the list.
+a list of parsed warning and error messages
+Returns a list of parsed notice, warning and error messages (dictionaries).
+To see the exact format, see RiseClipseParser
.
If the list of notices, warnings and errors is not empty, it returns the list. +Otherwise, it parses the messages and appends any notice, warning and error messages +to the list.
+a list of parsed notice, warning and error messages
+Returns a list of parsed info, notices, warnings and errors messages (dictionaries).
+To see the exact format, see RiseClipseParser
.
If the list of infos, notices, warnings and errors is not empty, it returns the +list. Otherwise, it parses the messages and appends any info, notice, warning and +error messages to the list.
+a list of parsed info, notice, warning and error messages
+Returns a list of parsed warning messages (dictionaries). To see the exact format,
+see RiseClipseParser
.
If the list of warnings is not empty, it returns the list. Otherwise, it parses +the messages and appends any warning messages to the list.
+a list of parsed warning messages
+Returns a list of parsed notice messages (dictionaries). To see the exact format,
+see RiseClipseParser
.
If the list of notices is not empty, it returns the list. Otherwise, it parses the +messages and appends any notice messages to the list.
+a list of parsed notice messages
+Returns a list of parsed info messages (dictionaries). To see the exact format,
+see RiseClipseParser
.
If the list of infos is not empty, it returns the list. Otherwise, it parses the +messages and appends any info messages to the list.
+a list of parsed info messages
+Returns a list of all parsed messages (dictionaries). To see the exact format,
+see RiseClipseParser
.
a list of all parsed messages
+Returns a list of messages, filtered by category. +The category does not have to be an exact match, it can be a substring of the category.
+category – The category to filter the messages by
+a list of parsed messages filtered by category
+Returns a list of messages, filtered by a specific part of message, named data. +The data does not have to be an exact match, it can be a substring of the message.
+data – the “data” e.g. specific message to filter the messages by
+Returns:
+Returns a list of messages, filtered by the file containing the error/warning/notice/info.
+filename – The filename to filter the messages by
+a list of parsed messages filtered by filename
+Returns a list of messages, filtered by the line number in the file containing +the error/warning/notice/info.
+line – the line number to filter the messages by
+a list of parsed messages filtered by line number
+Returns a list of messages, filtered with a dictionnary containing informations on +which we want to filter messages in the file containing the error/warning/notice/info.
+filtering_dict – the filter itself, fields of the dictionary are the the same as a parsed message
+a list of parsed messages filtered according to the filter
+Writes the parsed messages to a CSV file and returns the CSV as a string.
+path – The path to write the CSV file to
separator – The separator to use in the csv file
a string of the CSV file
+Bases: object
A class used to parse messages from RiseClipseValidator. +This class is used to convert raw messages into a structured format that can be easily +processed or displayed.
+Constructs all the necessary attributes for the RiseClipseParser object.
+list_of_messages – The list of messages to be parsed
+Iterates over each message in the list and parses it using the parse_message method. +Appends the parsed message to the parsed_messages attribute.
+Parses a single message into a dictionary with keys for message
, category
, line
, data
, filename
, and severity
.
+Each key’s value is extracted from the message by splitting the message string on commas and selecting the appropriate element.
message – A single message to be parsed i.e. a line from the standard output of the validator
+A dictionary containing the parsed message.
+Keys of the dictionary are message
, category
, line
, data
, filename
, and severity
:
the field message
contains the original non-parsed message
the field category
contains the category of the message
the field line
contains the line number in the file targetted by the message
the field data
contains the part of the message that contains the actual error/warning/notice/info
the field filename
contains the name of the file targetted by the message
the field severity
contains the severity of the message (ERROR, WARNING, NOTICE, INFO, DEBUG)
Bases: JavaRunner
Base class for RiseClipse validators. It takes care of common options.
+The set of options that will be added when the validation is launched.
+list[str]
+The level of displayed messages, initialized to "warning"
.
str
+The format string used by the java.util.Formatter
.
str
+Whether colors are used when result is displayed on stdout, initialized to False
.
bool
+The files that will be given to the validator.
+list[str]
+Initialize the RiseClipseValidator object.
+jar_path – The path to the validator jar
file
the current output level, one of "debug"
, "info"
, "notice"
, "warning"
or "error"
.
Set the current output level.
+new_level – The new output level.
+Must be "debug"
, "info"
, "notice"
, "warning"
or "error"
.
Returns the current format string used for output.
+The current format string.
+Set the current format string used for output.
+format – The new format string, its validity is not checked.
+Returns whether color is used.
+True if color will be used, False Otherwise.
+Set whether color will be used for output.
+use – If True, color will be used.
+Returns whether the copyright is displayed.
+True if the copyright is displayed, False Otherwise.
+Set whether the copyright is displayed.
+display – If True, copyright will be displayed.
+Add a file to be processed by the validator.
+file – The path to the file or directory to be processed.
+Add an option to the command line. An associated value may be specified.
+Note
+This method is intended to be used by subclasses
+opt – The option to be added.
value – The value to be added after the option.
Remove an option from the command line.
+Note
+This method is intended to be used by subclasses
+opt – The option to be removed.
has_value – Whether there was also an associated value.
Returns the arguments that will be passed to the run() method.
+Note
+This method is intended to be internal
+display_copyright – Whether the display_copyright setting must be taken into account. Default is True.
use_format – Whether the format_string setting must be taken into account. Default is True.
set_color – Whether the use_color setting must be taken into account. Default is False.
The list of strings that will be passed to the run() method.
+Runs the validator with the current set of arguments and files.
+An object representing the result of validation.
+Runs the validator with the current set of arguments and files.
+The result of validation as a string.
+Runs the validator with the current set of arguments and files. +Display the result on stdout.
+Bases: RiseClipseValidator
This class is a launcher for the RiseClipseValidatorSCL.jar
tool.
It offers specific options for this validator.
+Note
+The script riseclipse_validator_scl.py
can also be executed directly, it allows to donwload or update the
+validator jar
file needed for this API.
Initialize the RiseClipseValidatorSCL object.
+Do an XMLSchema validation.
+schema_path – The path to the XML Schema file
+Don’t display messages concerning the loading of NSD files.
+Returns different exit codes according to the higher severity in messages.
+