plcopen/InstanceTagnameCollector.py
author Edouard Tisserant <edouard.tisserant@gmail.com>
Fri, 12 Aug 2022 13:35:59 +0200
branchwxPython4
changeset 3581 5a0f7fcf9a8f
parent 1953 5736d25bb393
child 3750 f62625418bff
permissions -rw-r--r--
tests: fix load_and_build_tests.pytest

Leftover import from previously commented-out tests. Commented out as well.
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
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
     6
from __future__ import absolute_import
1953
5736d25bb393 PEP8 and PyLint conformance: whitespaces and stuff
Edouard Tisserant
parents: 1952
diff changeset
     7
from plcopen.XSLTModelQuery import XSLTModelQuery
1950
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
     8
from plcopen.types_enums import *
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