120 def __init__(self, controller, debug=False): |
120 def __init__(self, controller, debug=False): |
121 self.Controller = controller |
121 self.Controller = controller |
122 self.Debug = debug |
122 self.Debug = debug |
123 |
123 |
124 def resolve(self, url, pubid, context): |
124 def resolve(self, url, pubid, context): |
|
125 # TODO stop deepcopy |
125 lib_name = os.path.basename(url) |
126 lib_name = os.path.basename(url) |
126 if lib_name in ["project", "stdlib", "extensions"]: |
127 if lib_name in ["project", "stdlib", "extensions"]: |
127 lib_el = etree.Element(lib_name) |
128 lib_el = etree.Element(lib_name) |
128 if lib_name == "project": |
129 if lib_name == "project": |
129 lib_el.append(deepcopy(self.Controller.GetProject(self.Debug))) |
130 lib_el.append(deepcopy(self.Controller.GetProject(self.Debug))) |
264 *(_translate_args( |
265 *(_translate_args( |
265 [_StringValue, class_extraction, _StringValue] + |
266 [_StringValue, class_extraction, _StringValue] + |
266 [_BoolValue] * 2, args) + [[]]))) |
267 [_BoolValue] * 2, args) + [[]]))) |
267 |
268 |
268 |
269 |
269 class InstancesPathFactory(object): |
270 class InstancesPathCollector(object): |
270 """Helpers object for generating instances path list""" |
271 """ object for collecting instances path list""" |
271 def __init__(self, instances): |
272 def __init__(self, controller): |
272 self.Instances = instances |
273 self.Instances = [] |
|
274 |
|
275 parser = etree.XMLParser() |
|
276 # arbitrary set debug to false, updated later |
|
277 self.resolver = LibraryResolver(controller, debug=False) |
|
278 parser.resolvers.add(self.resolver) |
|
279 |
|
280 # TODO compile XSLT once for all at __init__ |
|
281 self.instances_path_xslt_tree = etree.XSLT( |
|
282 etree.parse( |
|
283 os.path.join(ScriptDirectory, "plcopen", "instances_path.xslt"), |
|
284 parser), |
|
285 extensions={ |
|
286 ("instances_ns", "AddInstance"): self.AddInstance}) |
273 |
287 |
274 def AddInstance(self, context, *args): |
288 def AddInstance(self, context, *args): |
275 self.Instances.append(args[0][0]) |
289 self.Instances.append(args[0][0]) |
|
290 |
|
291 def Collect(self, root, name, debug): |
|
292 self.resolver.debug = debug |
|
293 self.instances_path_xslt_tree( |
|
294 root, instance_type=etree.XSLT.strparam(name)) |
|
295 res = self.Instances |
|
296 self.Instances = [] |
|
297 return res |
276 |
298 |
277 |
299 |
278 class InstanceTagName(object): |
300 class InstanceTagName(object): |
279 """Helpers object for generating instance tagname""" |
301 """Helpers object for generating instance tagname""" |
280 |
302 |
801 return factory.GetRoot() |
824 return factory.GetRoot() |
802 |
825 |
803 return None |
826 return None |
804 |
827 |
805 def GetInstanceList(self, root, name, debug=False): |
828 def GetInstanceList(self, root, name, debug=False): |
806 instances = [] |
829 project = self.GetProject(debug) |
807 project = self.GetProject(debug) |
830 if project is not None: |
808 if project is not None: |
831 return self.InstancesPathCollector.Collect(root, name, debug) |
809 factory = InstancesPathFactory(instances) |
832 return [] |
810 |
|
811 parser = etree.XMLParser() |
|
812 parser.resolvers.add(LibraryResolver(self, debug)) |
|
813 |
|
814 instances_path_xslt_tree = etree.XSLT( |
|
815 etree.parse( |
|
816 os.path.join(ScriptDirectory, "plcopen", "instances_path.xslt"), |
|
817 parser), |
|
818 extensions={ |
|
819 ("instances_ns", "AddInstance"): factory.AddInstance}) |
|
820 |
|
821 instances_path_xslt_tree( |
|
822 root, instance_type=etree.XSLT.strparam(name)) |
|
823 |
|
824 return instances |
|
825 |
833 |
826 def SearchPouInstances(self, tagname, debug=False): |
834 def SearchPouInstances(self, tagname, debug=False): |
827 project = self.GetProject(debug) |
835 project = self.GetProject(debug) |
828 if project is not None: |
836 if project is not None: |
829 words = tagname.split("::") |
837 words = tagname.split("::") |