This should really help GetInstanceList to perform better: resolver removed, no more deepcopy, no more useless xml serialization, no more node-set() calls.
--- a/PLCControler.py Fri Feb 16 01:48:48 2018 +0100
+++ b/PLCControler.py Fri Feb 16 02:29:10 2018 +0100
@@ -271,11 +271,10 @@
""" object for collecting instances path list"""
def __init__(self, controller):
self.Instances = []
-
+ self.controller = controller
parser = etree.XMLParser()
# arbitrary set debug to false, updated later
- self.resolver = LibraryResolver(controller, debug=False)
- parser.resolvers.add(self.resolver)
+ self.debug = False
# TODO compile XSLT once for all at __init__
self.instances_path_xslt_tree = etree.XSLT(
@@ -283,13 +282,25 @@
os.path.join(ScriptDirectory, "plcopen", "instances_path.xslt"),
parser),
extensions={
- ("instances_ns", "AddInstance"): self.AddInstance})
+ ("instances_ns", "AddInstance"): self.AddInstance,
+ ("instances_ns", "GetProject"): self.GetProject,
+ ("instances_ns", "GetStdLibs"): self.GetStdLibs,
+ ("instances_ns", "GetExtensions"): self.GetExtensions})
def AddInstance(self, context, *args):
self.Instances.append(args[0][0])
+ def GetProject(self, context, *args):
+ return self.controller.GetProject(self.debug)
+
+ def GetStdLibs(self, context, *args):
+ return [lib for lib in StdBlckLibs.values()]
+
+ def GetExtensions(self, context, *args):
+ return [ctn["types"] for ctn in self.controller.ConfNodeTypes]
+
def Collect(self, root, name, debug):
- self.resolver.debug = debug
+ self.debug = debug
self.instances_path_xslt_tree(
root, instance_type=etree.XSLT.strparam(name))
res = self.Instances
--- a/plcopen/instances_path.xslt Fri Feb 16 01:48:48 2018 +0100
+++ b/plcopen/instances_path.xslt Fri Feb 16 02:29:10 2018 +0100
@@ -3,15 +3,10 @@
<xsl:output method="xml"/>
<xsl:param name="instance_type"/>
<xsl:template match="text()"/>
- <xsl:variable name="project">
- <xsl:copy-of select="document('project')/project/*"/>
- </xsl:variable>
- <xsl:variable name="stdlib">
- <xsl:copy-of select="document('stdlib')/stdlib/*"/>
- </xsl:variable>
- <xsl:variable name="extensions">
- <xsl:copy-of select="document('extensions')/extensions/*"/>
- </xsl:variable>
+ <xsl:variable name="project" select="ns:GetProject()"/>
+ <xsl:variable name="stdlib" select="ns:GetStdLibs()"/>
+ <xsl:variable name="extensions" select="ns:GetExtensions()"/>
+ <xsl:variable name="all" select="$project | $stdlib | $extensions"/>
<xsl:template match="ppx:project">
<instances>
<xsl:apply-templates select="ppx:instances/ppx:configurations/ppx:configuration"/>
@@ -52,7 +47,7 @@
<xsl:variable name="type_name">
<xsl:value-of select="@typeName"/>
</xsl:variable>
- <xsl:apply-templates select="exsl:node-set($project)/ppx:project/ppx:types/ppx:pous/ppx:pou[@name=$type_name] | exsl:node-set($project)/ppx:project/ppx:types/ppx:dataTypes/ppx:dataType[@name=$type_name] | exsl:node-set($stdlib)/ppx:project/ppx:types/ppx:pous/ppx:pou[@name=$type_name] | exsl:node-set($stdlib)/ppx:project/ppx:types/ppx:dataTypes/ppx:dataType[@name=$type_name] | exsl:node-set($extensions)/ppx:project/ppx:types/ppx:pous/ppx:pou[@name=$type_name] | exsl:node-set($extensions)/ppx:project/ppx:types/ppx:dataTypes/ppx:dataType[@name=$type_name]">
+ <xsl:apply-templates select="$all/ppx:project/ppx:types/ppx:pous/ppx:pou[@name=$type_name] | $all/ppx:project/ppx:types/ppx:dataTypes/ppx:dataType[@name=$type_name]">
<xsl:with-param name="instance_path">
<xsl:value-of select="$pou_instance_path"/>
</xsl:with-param>
@@ -99,7 +94,7 @@
<xsl:variable name="type_name">
<xsl:value-of select="@name"/>
</xsl:variable>
- <xsl:apply-templates select="exsl:node-set($project)/ppx:project/ppx:types/ppx:pous/ppx:pou[@name=$type_name] | exsl:node-set($project)/ppx:project/ppx:types/ppx:dataTypes/ppx:dataType[@name=$type_name] | exsl:node-set($stdlib)/ppx:project/ppx:types/ppx:pous/ppx:pou[@name=$type_name] | exsl:node-set($stdlib)/ppx:project/ppx:types/ppx:dataTypes/ppx:dataType[@name=$type_name] | exsl:node-set($extensions)/ppx:project/ppx:types/ppx:pous/ppx:pou[@name=$type_name] | exsl:node-set($extensions)/ppx:project/ppx:types/ppx:dataTypes/ppx:dataType[@name=$type_name]">
+ <xsl:apply-templates select="$all/ppx:project/ppx:types/ppx:pous/ppx:pou[@name=$type_name] | $all/ppx:project/ppx:types/ppx:dataTypes/ppx:dataType[@name=$type_name]">
<xsl:with-param name="instance_path">
<xsl:value-of select="$variable_path"/>
</xsl:with-param>
--- a/plcopen/instances_path.ysl2 Fri Feb 16 01:48:48 2018 +0100
+++ b/plcopen/instances_path.ysl2 Fri Feb 16 02:29:10 2018 +0100
@@ -9,16 +9,13 @@
template "text()";
- variable "project" {
- copy "document('project')/project/*";
- }
+ variable "project", "ns:GetProject()";
- variable "stdlib" {
- copy "document('stdlib')/stdlib/*";
- }
- variable "extensions" {
- copy "document('extensions')/extensions/*";
- }
+ variable "stdlib", "ns:GetStdLibs()";
+
+ variable "extensions", "ns:GetExtensions()";
+
+ variable "all", "$project | $stdlib | $extensions";
template "ppx:project" {
instances {
@@ -49,12 +46,8 @@
}
otherwise {
variable "type_name" > «@typeName»
- apply """exsl:node-set($project)/ppx:project/ppx:types/ppx:pous/ppx:pou[@name=$type_name] |
- exsl:node-set($project)/ppx:project/ppx:types/ppx:dataTypes/ppx:dataType[@name=$type_name] |
- exsl:node-set($stdlib)/ppx:project/ppx:types/ppx:pous/ppx:pou[@name=$type_name] |
- exsl:node-set($stdlib)/ppx:project/ppx:types/ppx:dataTypes/ppx:dataType[@name=$type_name] |
- exsl:node-set($extensions)/ppx:project/ppx:types/ppx:pous/ppx:pou[@name=$type_name] |
- exsl:node-set($extensions)/ppx:project/ppx:types/ppx:dataTypes/ppx:dataType[@name=$type_name]""" {
+ apply """$all/ppx:project/ppx:types/ppx:pous/ppx:pou[@name=$type_name] |
+ $all/ppx:project/ppx:types/ppx:dataTypes/ppx:dataType[@name=$type_name]""" {
with "instance_path" > «$pou_instance_path»
}
}
@@ -91,12 +84,8 @@
}
otherwise {
variable "type_name" > «@name»
- apply """exsl:node-set($project)/ppx:project/ppx:types/ppx:pous/ppx:pou[@name=$type_name] |
- exsl:node-set($project)/ppx:project/ppx:types/ppx:dataTypes/ppx:dataType[@name=$type_name] |
- exsl:node-set($stdlib)/ppx:project/ppx:types/ppx:pous/ppx:pou[@name=$type_name] |
- exsl:node-set($stdlib)/ppx:project/ppx:types/ppx:dataTypes/ppx:dataType[@name=$type_name] |
- exsl:node-set($extensions)/ppx:project/ppx:types/ppx:pous/ppx:pou[@name=$type_name] |
- exsl:node-set($extensions)/ppx:project/ppx:types/ppx:dataTypes/ppx:dataType[@name=$type_name]""" {
+ apply """$all/ppx:project/ppx:types/ppx:pous/ppx:pou[@name=$type_name] |
+ $all/ppx:project/ppx:types/ppx:dataTypes/ppx:dataType[@name=$type_name]""" {
with "instance_path" > «$variable_path»
}
}