plcopen/InstanceTagnameCollector.py
author Edouard Tisserant <edouard.tisserant@gmail.com>
Mon, 16 Oct 2023 23:50:58 +0200
changeset 3868 e9807c28a788
parent 3751 a80a66ba52d6
permissions -rw-r--r--
Fix template conflict in XSLT with lxml>=4.9.0 again

Earlier attempt was fixing conflict with -1.0 priority attribute,
as a side effect of such low priority, SFC Actions were not
editable anymore.

This time move template around instead of using explicit priority.
1950
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
     1
#!/usr/bin/env python
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
     3
# This file is part of Beremiz.
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
     4
# See COPYING file for copyrights details.
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
     5
3750
f62625418bff automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents: 1953
diff changeset
     6
3751
a80a66ba52d6 fixed plcopen imports
GP Orcullo <kinsamanka@gmail.com>
parents: 3750
diff changeset
     7
from . XSLTModelQuery import XSLTModelQuery
a80a66ba52d6 fixed plcopen imports
GP Orcullo <kinsamanka@gmail.com>
parents: 3750
diff changeset
     8
from . types_enums import *
1950
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
     9
1953
5736d25bb393 PEP8 and PyLint conformance: whitespaces and stuff
Edouard Tisserant
parents: 1952
diff changeset
    10
1950
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    11
class InstanceTagName(object):
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    12
    """Helpers object for generating instance tagname"""
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    13
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    14
    def __init__(self):
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    15
        self.TagName = None
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    16
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    17
    def GetTagName(self):
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    18
        return self.TagName
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    19
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    20
    def ConfigTagName(self, context, *args):
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    21
        self.TagName = ComputeConfigurationName(args[0][0])
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    22
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    23
    def ResourceTagName(self, context, *args):
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    24
        self.TagName = ComputeConfigurationResourceName(args[0][0], args[1][0])
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    25
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    26
    def PouTagName(self, context, *args):
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    27
        self.TagName = ComputePouName(args[0][0])
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    28
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    29
    def ActionTagName(self, context, *args):
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    30
        self.TagName = ComputePouActionName(args[0][0], args[0][1])
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    31
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    32
    def TransitionTagName(self, context, *args):
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    33
        self.TagName = ComputePouTransitionName(args[0][0], args[0][1])
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    34
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    35
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    36
class InstanceTagnameCollector(XSLTModelQuery):
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    37
    """ object for collecting instances path list"""
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    38
    def __init__(self, controller):
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    39
        XSLTModelQuery.__init__(self,
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    40
                                controller,
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    41
                                "instance_tagname.xslt",
1953
5736d25bb393 PEP8 and PyLint conformance: whitespaces and stuff
Edouard Tisserant
parents: 1952
diff changeset
    42
                                [(name, self.FactoryCaller(name))
5736d25bb393 PEP8 and PyLint conformance: whitespaces and stuff
Edouard Tisserant
parents: 1952
diff changeset
    43
                                 for name in ["ConfigTagName",
5736d25bb393 PEP8 and PyLint conformance: whitespaces and stuff
Edouard Tisserant
parents: 1952
diff changeset
    44
                                              "ResourceTagName",
5736d25bb393 PEP8 and PyLint conformance: whitespaces and stuff
Edouard Tisserant
parents: 1952
diff changeset
    45
                                              "PouTagName",
5736d25bb393 PEP8 and PyLint conformance: whitespaces and stuff
Edouard Tisserant
parents: 1952
diff changeset
    46
                                              "ActionTagName",
5736d25bb393 PEP8 and PyLint conformance: whitespaces and stuff
Edouard Tisserant
parents: 1952
diff changeset
    47
                                              "TransitionTagName"]])
1950
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    48
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    49
    def FactoryCaller(self, funcname):
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    50
        def CallFactory(*args):
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    51
            return getattr(self.factory, funcname)(*args)
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    52
        return CallFactory
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    53
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    54
    def Collect(self, root, debug, instance_path):
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    55
        self.factory = InstanceTagName()
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    56
        self._process_xslt(root, debug, instance_path=instance_path)
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    57
        res = self.factory.GetTagName()
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    58
        self.factory = None
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    59
        return res