Tekvel Magic
|
Classes | |
class | ICD |
ICD file manipulation. More... | |
class | NSD |
Namespace definition processing. More... | |
class | RSD |
RSD file manipulation. More... | |
class | SCD |
SCD file manipulation. More... | |
class | SCL |
Common SCL-file manipulation class. More... | |
class | SclValidationResult |
SCL validation result. More... | |
class | SICS |
Class for SCL Implementation Conformance Statement (SICS). More... | |
class | SSD |
SSD file manipulation. More... | |
Functions | |
def | xmlTreeMerge (a, b) |
Merge two XML trees. More... | |
def | check_nsd_conditions (nsd_spec, scl_impl, **kwargs) |
Check NSD conditions for element specification. More... | |
def | normalize_mac (mac_string) |
Normalize MAC address to SCL format. More... | |
def | clone (element) |
Creates a full (deep) copy of an element. More... | |
def | add_default_namespace_to_element (namespace_str, element_str) |
Adds namespace to an element. More... | |
def | get_tag_without_namespace (element) |
Get element tag with no Namespace prefix. More... | |
def | scl_element_from_string (scl_element_str, scl_namespace='http://www.iec.ch/61850/2003/SCL') |
Create SCL element from string. More... | |
def | get_one_or_raise (element_list, element_identifier='Undefined') |
Get the first element from a list or raise an error if not exactly one element exists. More... | |
def | get_element_by_attribute (dom, element_namespace, element_tag, attribute_value, attribute_name="name", strict=False) |
Get element by attribute. More... | |
def | get_p_element_value (connected_ap, p_type) |
Get value of. More... | |
def | get_p_element_list (connected_ap) |
Get list of. More... | |
def | get_p_osi_element_list (connected_ap) |
Get list of. More... | |
def | get_gse_maxtime (gse) |
Get MaxTime element for GSE. More... | |
def | get_gse_mintime (gse) |
Get MinTime element for GSE. More... | |
def | get_gse_maxtime_value (gse) |
Get MaxTime value for GSE. More... | |
def | get_gse_mintime_value (gse) |
Get MinTime value for GSE. More... | |
def | get_reference_for_element (element, ref_type=ReferenceType.ObjectReference) |
Get reference for element. More... | |
def | get_dataset_fcda_list (et_dataset) |
Get FCDA list for DataSet. More... | |
def | get_reference_for_fcda (et_fcda, ref_type=ReferenceType.ObjectReference) |
Form FCDA reference. More... | |
def | get_LNodeType_element_by_id (dom, lnType) |
Get LNodeType element by ID. More... | |
def | get_LN_element_by_name (dom, lnName) |
Get LN element by name. More... | |
def | compare_ln_elements_by_path (ln1_name, ln2_name) |
Compare LN elements by path. More... | |
def | get_DOI_element_by_name (et_LN, doi_name) |
Get DOI element by name. More... | |
def | get_DOI_by_name (et_LN, doi_name) |
Get DOI element by name. More... | |
def | get_SDI_element_by_seq_name (et_DOI, sdiSeq) |
Get SDI element by sequence name. More... | |
def | get_DAI_element_by_name (et_DOI, dai_name) |
Get DAI element by name. More... | |
def | get_sdo_type_recursive (et_root, et_element, sdo_seq_list) |
Get final element in DO/SDO/DA chain. More... | |
def | get_regex_by_enumtype (enum_type) |
Get regex by EnumType. More... | |
def | convert_mms_to_scl_ref (mms_ref) |
Converts MMSReference to ObjectReference. More... | |
def | compare_data_models (model1, model2) |
def | compare_elements (domNode1, domNode2, queryElementSet1, queryElementSet2) |
def | remove_scl_element (element) |
Removes an SCL element. More... | |
def | convertNodeToJSON (jsonNodeArray, sclNode) |
Converts an SCL node to JSON format. More... | |
def | convertNodesToJSON (sclNodes) |
Converts list of XML nodes to JSON. More... | |
def | get_name_for_ln (et_LN) |
Returns the full name for an LN / LN0 element. More... | |
def | get_ancestors_tree_to_element (root, et_element, descendants) |
Get the tree of ancestors up to a specific element. More... | |
def | equality_two_elements (element_1, element_2) |
Compare two XML elements. More... | |
def | merge_two_axis (axis_1, axis_2, NSMAP) |
Merge two parent-child axis. More... | |
def | check_string_template_conformance (string, template_string) |
Check if a string conforms to a given template. More... | |
def | get_type_element (dom, xmlns, tag, type_id) |
Get type element from DOM by tag and ID. More... | |
def | get_applicable_conditions () |
FIXME: THIS IS A PLACEHOLDER FUNCTON, IT ALWAYS RETURNS ["M", "AtLeastOne"]. More... | |
def | check_type_recursive (scl, nsd, element, nsd_element=None, **kwargs) |
Check element type recursive. More... | |
def | compare_sections (model1, model2, section_name=None, exceptions=None) |
Compare sections between two models. More... | |
Variables | |
NSD_7_4 = NSD(NSD_7_4_2007A2_PATH) | |
NSD_7_4_2007A2 = NSD(NSD_7_4_2007A2_PATH) | |
NSD_7_4_2007B = NSD(NSD_7_4_2007B_PATH) | |
NSD_7_4_2007B3 = NSD(NSD_7_4_2007B3_PATH) | |
NSD_7_4_FSK2020A = NSD(NSD_7_4_FSK2020A_PATH) | |
SICS = SICS() | |
def add_default_namespace_to_element | ( | namespace_str, | |
element_str | |||
) |
Adds namespace to an element.
Creates an XML element from string and adds namespace to it.
namespace_str | Namespace ID |
element_str | Element name |
def check_nsd_conditions | ( | nsd_spec, | |
scl_impl, | |||
** | kwargs | ||
) |
Check NSD conditions for element specification.
The function takes NSD specification and it's SCL implementation as paramters and compares the SCL implementation against NSD specification. The function is specifically designed for check_type_recursive() function, but, however, might be used separately if required.
nsd_spec | NSD specification for the elment. Specification is presented as the list of child elements of the element. The example form is shown below: [{'name': 'NamPlt', 'type': 'LPL', 'descID': 'IEC61850_7_4.LNGroupL::LLN0.NamPlt.desc',
'presCond': 'MOrootLD', 'dsPresCond': 'na', 'elementType': 'DataObject'},
{'name': 'Beh', 'type': 'ENS', 'underlyingType': 'BehaviourModeKind',
'descID': 'IEC61850_7_4.LNGroupL::LLN0.Beh.desc', 'presCond': 'M', 'dsPresCond': 'na',
'elementType': 'DataObject'}, ... ]
|
scl_impl | SCL implemenetation of the element in the form of dict object. Note that unlike the NSD specification, the SCL implementation is in the form of dict, not list. The keys are names of the elements. xmlElement attribute contains lxml.etree Element representation of specific element. {'Mod': {'name': 'Mod', 'type': 'ENC_Mod_DOes', 'desc': 'Режим работы',
'xmlElement': <Element {http://www.iec.ch/61850/2003/SCL}DO at 0x7f9728088be0>,
'proprietary': False}, 'Beh': {'name': 'Beh', 'type': 'ENS_Beh', 'desc': 'Индикация поведения',
'xmlElement': <Element {http://www.iec.ch/61850/2003/SCL}DO at 0x7f9728088b90>,
'proprietary': False}, ... }
|
**kwargs | Additional keyword arguments specific for particular elements and conditions. Specifically the following presence conditions can be passed as kwargs:
|
def check_string_template_conformance | ( | string, | |
template_string | |||
) |
Check if a string conforms to a given template.
Performs a check to see if the provided string matches the given template string.
string | The string to be checked. |
template_string | The regular expression template as a string. |
def check_type_recursive | ( | scl, | |
nsd, | |||
element, | |||
nsd_element = None , |
|||
** | kwargs | ||
) |
Check element type recursive.
Allows to check the element type recursively iterating child-elements and their templates
scl | the SCL class instance object (e.g. ICD, SCD) |
nsd | NSD class instance object |
element | et.Element-type element of the datamodel. Allowed elements are: LN0, LN, DO, SDO, DA, BDA |
nsd_element | an NSD element to be used to check the element if context is required. The nsd_element parameter is mandatory if the DA/BDA is passed element parameter. |
**kwargs | keyword arguments object. The following keywords are accepted:
|
def clone | ( | element | ) |
Creates a full (deep) copy of an element.
Wrapper around copy.deepcopy()
element | The XML element to be deeply copied. |
def compare_data_models | ( | model1, | |
model2 | |||
) |
def compare_elements | ( | domNode1, | |
domNode2, | |||
queryElementSet1, | |||
queryElementSet2 | |||
) |
def compare_ln_elements_by_path | ( | ln1_name, | |
ln2_name | |||
) |
Compare LN elements by path.
Compares two logical node (LN) elements by their path and returns a list of differing attributes.
ln1_name | Name of the first logical node (LN) to be compared |
ln2_name | Name of the second logical node (LN) to be compared |
Exception | if the format of ln1_name or ln2_name is invalid |
def compare_sections | ( | model1, | |
model2, | |||
section_name = None , |
|||
exceptions = None |
|||
) |
Compare sections between two models.
This function compares the SCL sections of two models, model1
and model2
, based on a specified section name or by comparing all sections if no name is provided. The function identifies differences in attributes and elements between the two models. It supports the exclusion of certain elements and attributes and handles complex cases with optional exception handling for certain XML elements like FCDA
and ExtRef
. The result is returned as a dictionary of mismatched elements.
model1 | The first model (SCL) for comparison. |
model2 | The second model (SCL) for comparison. |
section_name | (optional) The section name to restrict the comparison to a specific SCL section. If not provided, all sections are compared. |
exceptions | (optional) A list of element names to exclude from the comparison. |
Exception | Raised when an error occurs in parsing, or during element or attribute removal from the comparison lists. |
def convert_mms_to_scl_ref | ( | mms_ref | ) |
Converts MMSReference to ObjectReference.
The function converts MMSReference to ObjectReference (SCL-type) reference
mms_ref | MMS-style reference to an element |
Exception | Raised if the reference does not match MMSReference format for any object type |
def convertNodesToJSON | ( | sclNodes | ) |
Converts list of XML nodes to JSON.
Converts each node in the provided list of XML nodes to its JSON representation and returns a list of these JSON objects.
sclNodes | List of XML nodes to be converted. |
def convertNodeToJSON | ( | jsonNodeArray, | |
sclNode | |||
) |
Converts an SCL node to JSON format.
This function converts an SCL node and its children to a JSON format suitable for further processing.
jsonNodeArray | Array to which the JSON representation of the node will be appended |
sclNode | SCL node to be converted |
def equality_two_elements | ( | element_1, | |
element_2 | |||
) |
Compare two XML elements.
Compares two XML elements to check if they are equal. Elements are considered equal if their tags, attributes, and text content are identical.
element_1 | The first XML element to compare. |
element_2 | The second XML element to compare. |
def get_ancestors_tree_to_element | ( | root, | |
et_element, | |||
descendants | |||
) |
Get the tree of ancestors up to a specific element.
Constructs and returns an XML tree containing all ancestors from the root element to the specified element. The descendant elements are also included.
root | The root element from which to start the tree. |
et_element | The target element for which the ancestor tree is being built. |
descendants | An existing tree of descendant elements to be included in the ancestor tree. |
ExceptionType | Name of exception and exception conditions. |
def get_applicable_conditions | ( | ) |
FIXME: THIS IS A PLACEHOLDER FUNCTON, IT ALWAYS RETURNS ["M", "AtLeastOne"].
def get_DAI_element_by_name | ( | et_DOI, | |
dai_name | |||
) |
Get DAI element by name.
Returns the DAI element within the context of a DOI/SDI element by its name attribute.
et_DOI | The DOI or SDI element context |
dai_name | The name attribute of the DAI element |
def get_dataset_fcda_list | ( | et_dataset | ) |
Get FCDA list for DataSet.
Returns a list of FCDA elements for the specified DataSet.
et_dataset | Element of type et._Element representing the DataSet |
def get_DOI_by_name | ( | et_LN, | |
doi_name | |||
) |
Get DOI element by name.
Returns the DOI element within the context of an LNode element by its name attribute.
et_LN | The LNode element context |
doi_name | The name attribute of the DOI element to be returned |
def get_DOI_element_by_name | ( | et_LN, | |
doi_name | |||
) |
Get DOI element by name.
Returns the DOI element within the context of an LNode element by its name attribute.
et_LN | The LNode element context |
doi_name | The name attribute of the DOI element to be returned |
Exception | if the DOI element with the specified name is not found or if there are multiple elements with the same name |
def get_element_by_attribute | ( | dom, | |
element_namespace, | |||
element_tag, | |||
attribute_value, | |||
attribute_name = "name" , |
|||
strict = False |
|||
) |
Get element by attribute.
Returns the first element by tag, name, and attribute value.
dom | DOM object of the XML |
element_namespace | Namespace of the element |
element_tag | Tag of the element |
attribute_value | Value of the attribute to search for |
attribute_name | Name of the attribute to search for (default: "name") |
strict | Boolean flag to specify if the search should be strict (default: False) |
def get_gse_maxtime | ( | gse | ) |
Get MaxTime element for GSE.
Returns the MaxTime element for a given GSE element.
gse | GSE element |
Exception | Raises an exception if the MaxTime element is not found. |
def get_gse_maxtime_value | ( | gse | ) |
Get MaxTime value for GSE.
Returns the MaxTime value in milliseconds for a given GSE element.
gse | GSE element |
Exception | Raises an exception if the MaxTime element is not found. |
def get_gse_mintime | ( | gse | ) |
Get MinTime element for GSE.
Returns the MinTime element for a given GSE element.
gse | GSE element |
Exception | Raises an exception if the MinTime element is not found. |
def get_gse_mintime_value | ( | gse | ) |
Get MinTime value for GSE.
Returns the MinTime value in milliseconds for a given GSE element.
gse | GSE element |
Exception | Raises an exception if the MinTime element is not found. |
def get_LN_element_by_name | ( | dom, | |
lnName | |||
) |
Get LN element by name.
Returns the LN or LN0 element with the specified lnName.
dom | Element of type et._Element representing the DOM |
lnName | Name of the logical node (LN) to be retrieved |
Exception | if the lnName format is invalid or if the LN/LN0 element is not found |
def get_LNodeType_element_by_id | ( | dom, | |
lnType | |||
) |
Get LNodeType element by ID.
Returns the LNodeType element with the specified ID.
dom | Element of type et._Element representing the DOM |
lnType | ID of the LNodeType to be retrieved |
Exception | if the LNodeType element is not found or if multiple elements are found |
def get_name_for_ln | ( | et_LN | ) |
Returns the full name for an LN / LN0 element.
Constructs and returns the full name of a Logical Node (LN) or Logical Node 0 (LN0) element based on its prefix, class, and instance attributes.
et_LN | The LN or LN0 element of type et._Element. |
def get_one_or_raise | ( | element_list, | |
element_identifier = 'Undefined' |
|||
) |
Get the first element from a list or raise an error if not exactly one element exists.
This function returns the first element of the list if the list contains exactly one element. If the list is empty, it raises an exception indicating that the element was not found. If the list contains more than one element, it raises an exception indicating that multiple elements were found.
element_list | The list of elements. |
element_identifier | An optional identifier for the element, used in error messages. |
Exception | if the element is not found or if multiple elements are found. |
def get_p_element_list | ( | connected_ap | ) |
Get list of.
elements
Returns all
elements of the ConnectedAP element.
connected_ap | ConnectedAP element |
elements.
def get_p_element_value | ( | connected_ap, | |
p_type | |||
) |
Get value of.
element by type
Returns the value of the
element of a specified type.
connected_ap | ConnectedAP element |
p_type | Type of the |
element to search for
element as a string.
def get_p_osi_element_list | ( | connected_ap | ) |
Get list of.
elements of type OSI-*
Returns all
elements with a type starting with OSI-.
connected_ap | ConnectedAP element |
elements of type OSI-*.
def get_reference_for_element | ( | element, | |
ref_type = ReferenceType.ObjectReference |
|||
) |
Get reference for element.
Returns the path (ObjectReference, MMSReference) to the element.
element | The element for which to get the reference |
ref_type | Type of reference to return (ObjectReference or MMSReference) |
Exception | Raises an exception if the element type is unknown. |
def get_reference_for_fcda | ( | et_fcda, | |
ref_type = ReferenceType.ObjectReference |
|||
) |
Form FCDA reference.
Forms an ObjectReference or MMSReference from the attributes of an FCDA element.
et_fcda | Element of type et._Element representing the FCDA |
ref_type | Type of reference to be formed (ObjectReference or MMSReference) |
def get_regex_by_enumtype | ( | enum_type | ) |
Get regex by EnumType.
Returns a regular expression based on the EnumType element.
enum_type | The EnumType element to generate the regex from |
def get_SDI_element_by_seq_name | ( | et_DOI, | |
sdiSeq | |||
) |
Get SDI element by sequence name.
Returns the final SDI element by recursively traversing the sdiSeq chain.
et_DOI | The DOI element context |
sdiSeq | The sequence of SDI names separated by dots |
def get_sdo_type_recursive | ( | et_root, | |
et_element, | |||
sdo_seq_list | |||
) |
Get final element in DO/SDO/DA chain.
Returns the final element in the DO/SDO/DA chain based on names from sdo_seq_list.
et_root | The root element for the search |
et_element | The current element in the chain |
sdo_seq_list | The sequence list of SDO names |
Exception | Raised if BDA type has nested elements |
def get_tag_without_namespace | ( | element | ) |
Get element tag with no Namespace prefix.
Returns tag of an XML element without namespace ID in front (i.e. string only).
element | Element of type et.Element |
def get_type_element | ( | dom, | |
xmlns, | |||
tag, | |||
type_id | |||
) |
Get type element from DOM by tag and ID.
Retrieves a type element from the DOM using the specified tag and ID.
dom | The DOM object to search within. |
xmlns | The namespace to use for the search. |
tag | The tag of the element to find. |
type_id | The ID of the element to find. |
Exception | Raised if no element or more than one element is found. |
def merge_two_axis | ( | axis_1, | |
axis_2, | |||
NSMAP | |||
) |
Merge two parent-child axis.
Merges two parent-child axis and returns a new tree. If no matches are found, returns an empty list.
axis_1 | The first parent-child axis (et.Element). |
axis_2 | The second parent-child axis (et.Element). |
NSMAP | The namespace map used in the XML elements. |
def normalize_mac | ( | mac_string | ) |
def remove_scl_element | ( | element | ) |
def scl_element_from_string | ( | scl_element_str, | |
scl_namespace = 'http://www.iec.ch/61850/2003/SCL' |
|||
) |
Create SCL element from string.
Creates an SCL element from pure string, parsing the string and adding required namespaces to element and attributes.
scl_element_str | SCL string with required element |
scl_namespace | SCL NamespaceID (default: http://www.iec.ch/61850/2003/SCL) |
def xmlTreeMerge | ( | a, | |
b | |||
) |
Merge two XML trees.
Merge two XML trees A and B, so that each recursively found leaf element of B is added to A. If the element already exists in A, it is replaced with B's version. Tree structure is created in A as required to reflect the position of the leaf element in B. Given <top><first></first></top> and <top><first></first></top>, a merge results in <top><first>
</first></top> (order not guaranteed).
a | The first XML tree (et.Element) to be merged. |
b | The second XML tree (et.Element) to merge into the first. |
NSD_7_4 = NSD(NSD_7_4_2007A2_PATH) |
NSD_7_4_2007A2 = NSD(NSD_7_4_2007A2_PATH) |
NSD_7_4_2007B = NSD(NSD_7_4_2007B_PATH) |
NSD_7_4_2007B3 = NSD(NSD_7_4_2007B3_PATH) |
NSD_7_4_FSK2020A = NSD(NSD_7_4_FSK2020A_PATH) |