beremiz

Dirty fix for error '_object_has_no_attribute_'getSlave' in EtherCAT extension

traceback:
File "/home/developer/WorkData/PLC/beremiz/beremiz/IDEFrame.py", line 1433, in OnPouSelectedChanged
window.RefreshView()
File "/home/developer/WorkData/PLC/beremiz/beremiz/etherlab/ConfigEditor.py", line 837, in RefreshView
self.RefreshProcessVariables()
File "/home/developer/WorkData/PLC/beremiz/beremiz/etherlab/ConfigEditor.py", line 886, in RefreshProcessVariables
slaves = self.Controler.GetSlaves(**self.CurrentNodesFilter)
File "/home/developer/WorkData/PLC/beremiz/beremiz/etherlab/EthercatMaster.py", line 341, in GetSlaves
for slave in self.Config.getConfig().getSlave():
:_'lxml.etree._Element'_object_has_no_attribute_'getSlave'

Steps to reproduce problem:

- Add new EtherCAT master
- Add new EthercatNode to the master
- double click on


this is looks like dirty hack to fix strange problem with initial[0]
changing its type after returning from _init_ method to lxml.etree._Element
As a result all methods generated by class factory are lost.

For example, in function initMethod initial[0].__class__ points to
xmlclass.xmlclass.Config. After map(self.append, initial)
self.Config.__class__ is 'xmlclass.xmlclass.Config' as well.
But after returning from initMethod (_init) in CreateElement
self.Config.__class__ has changed to lxml.etree._Element.


I've noticed similar behavior if copy/deepcopy is used for any child
of etree.ElementBase. See simple example below.
[-------------------------------------------------------------]
#!/usr/bin/python

from __future__ import print_function
from lxml import etree
import copy

class DefaultElementClass(etree.ElementBase):
def getLocalTag(self):
return etree.QName(self.tag).localname


def printInformation(x):
print(x, x.__class__, "getLocalTag" in dir(x))


a = DefaultElementClass()
printInformation(a)

#
printInformation(copy.copy(a))
printInformation(copy.deepcopy(a))
[-------------------------------------------------------------]
include yslt_noindent.yml2
istylesheet xmlns:ppx="http://www.plcopen.org/xml/tc6_0201"
xmlns:xhtml="http://www.w3.org/1999/xhtml"
xmlns:ns="beremiz"
extension-element-prefixes="ns"
exclude-result-prefixes="ns" {
param "instance_path";
variable "project", "ns:GetProject()";
variable "stdlib", "ns:GetStdLibs()";
variable "extensions", "ns:GetExtensions()";
variable "all_types", "($project | $stdlib | $extensions)/ppx:types";
function "element_name" {
param "path";
choose {
when "contains($path,'.')" > «substring-before($path,'.')»
otherwise > «$path»
}
}
function "next_path" {
param "path";
choose {
when "contains($path,'.')" > «substring-after($path,'.')»
}
}
template "ppx:project" {
variable "config_name" {
call "element_name" {
with "path", "$instance_path";
}
}
apply "ppx:instances/ppx:configurations/ppx:configuration[@name=$config_name]" {
with "element_path" {
call "next_path" {
with "path", "$instance_path";
}
}
}
}
template "ppx:configuration" {
param "element_path";
choose {
when "$element_path!=''" {
variable "child_name" {
call "element_name" {
with "path", "$element_path";
}
}
apply "ppx:resource[@name=$child_name] | ppx:globalVars/ppx:variable[@name=$child_name]/ppx:type/*[self::ppx:derived or self::ppx:struct or self::ppx:array]" {
with "element_path" {
call "next_path" {
with "path", "$element_path";
}
}
}
}
otherwise {
value "ns:ConfigTagName(@name)";
}
}
}
template "ppx:resource" {
param "element_path";
choose {
when "$element_path!=''" {
variable "child_name" {
call "element_name" {
with "path" > «$element_path»
}
}
apply "ppx:pouInstance[@name=$child_name] | ppx:task/ppx:pouInstance[@name=$child_name] | ppx:globalVars/ppx:variable[@name=$child_name]/ppx:type/*[self::ppx:derived or self::ppx:struct or self::ppx:array]" {
with "element_path" {
call "next_path" {
with "path", "$element_path";
}
}
}
}
otherwise {
value "ns:ResourceTagName(ancestor::ppx:configuration/@name, @name)";
}
}
}
template "ppx:pouInstance" {
param "element_path";
variable "type_name" > «@typeName»
apply """$all_types/ppx:pous/ppx:pou[@name=$type_name] | \
$all_types/ppx:dataTypes/ppx:dataType[@name=$type_name]""" {
with "element_path", "$element_path";
}
}
template "ppx:pou" {
param "element_path";
choose {
when "$element_path!=''" {
variable "child_name" {
call "element_name" {
with "path", "$element_path";
}
}
apply "ppx:interface/*/ppx:variable[@name=$child_name]/ppx:type/*[self::ppx:derived or self::ppx:struct or self::ppx:array]" {
with "element_path" {
call "next_path" {
with "path", "$element_path";
}
}
}
apply "ppx:actions/ppx:action[@name=$child_name] | ppx:transitions/ppx:transition[@name=$child_name]";
}
otherwise {
variable "name" > «@name»
value "ns:PouTagName($name)";
}
}
}
template "ppx:action" {
value "ns:ActionTagName(ancestor::ppx:pou/@name, @name)";
}
template "ppx:transition" {
value "ns:TransitionTagName(ancestor::ppx:pou/@name, @name)";
}
template "ppx:dataType" {
param "element_path";
apply "ppx:baseType/*[self::ppx:derived or self::ppx:struct or self::ppx:array]" {
with "element_path", "$element_path";
}
}
template "ppx:derived" {
param "element_path";
variable "type_name" > «@name»
apply """$all_types/ppx:pous/ppx:pou[@name=$type_name] | \
$all_types/ppx:dataTypes/ppx:dataType[@name=$type_name]""" {
with "element_path", "$element_path";
}
}
template "ppx:array" {
param "element_path";
apply "ppx:baseType/*[self::ppx:derived or self::ppx:struct or self::ppx:array]" {
with "element_path", "$element_path";
}
}
template "ppx:struct" {
param "element_path";
variable "child_name" {
call "element_name" {
with "path", "$element_path";
}
}
apply "ppx:variable[@name=$child_name]/ppx:type/*[self::ppx:derived or self::ppx:struct or self::ppx:array]" {
with "element_path" {
call "next_path" {
with "path", "$element_path";
}
}
}
}
}