36 from lxml import etree |
36 from lxml import etree |
37 |
37 |
38 import util.paths as paths |
38 import util.paths as paths |
39 from util.TranslationCatalogs import NoTranslate |
39 from util.TranslationCatalogs import NoTranslate |
40 from plcopen import * |
40 from plcopen import * |
|
41 from plcopen.XSLTModelQuery import XSLTModelQuery |
41 from graphics.GraphicCommons import * |
42 from graphics.GraphicCommons import * |
42 from PLCGenerator import * |
43 from PLCGenerator import * |
43 |
44 |
44 duration_model = re.compile("(?:([0-9]{1,2})h)?(?:([0-9]{1,2})m(?!s))?(?:([0-9]{1,2})s)?(?:([0-9]{1,3}(?:\.[0-9]*)?)ms)?") |
45 duration_model = re.compile("(?:([0-9]{1,2})h)?(?:([0-9]{1,2})m(?!s))?(?:([0-9]{1,2})s)?(?:([0-9]{1,3}(?:\.[0-9]*)?)ms)?") |
45 |
46 |
264 self.Root.variables.append(_VariablesTreeItemInfos( |
265 self.Root.variables.append(_VariablesTreeItemInfos( |
265 *(_translate_args( |
266 *(_translate_args( |
266 [_StringValue, class_extraction, _StringValue] + |
267 [_StringValue, class_extraction, _StringValue] + |
267 [_BoolValue] * 2, args) + [[]]))) |
268 [_BoolValue] * 2, args) + [[]]))) |
268 |
269 |
269 |
|
270 class XSLTModelQuery(object): |
|
271 """ a class to handle XSLT queries on project and libs """ |
|
272 def __init__(self, controller, xsltpath, ext = []): |
|
273 # arbitrary set debug to false, updated later |
|
274 self.debug = False |
|
275 |
|
276 # merge xslt extensions for library access to query specific ones |
|
277 xsltext = [ |
|
278 ("GetProject", lambda *_ignored: |
|
279 controller.GetProject(self.debug)), |
|
280 ("GetStdLibs", lambda *_ignored: |
|
281 [lib for lib in StdBlckLibs.values()]), |
|
282 ("GetExtensions", lambda *_ignored: |
|
283 [ctn["types"] for ctn in controller.ConfNodeTypes]) |
|
284 ] + ext |
|
285 |
|
286 # parse and compile. "beremiz" arbitrary namespace for extensions |
|
287 self.xslt = etree.XSLT( |
|
288 etree.parse( |
|
289 os.path.join(ScriptDirectory, "plcopen", xsltpath), |
|
290 etree.XMLParser()), |
|
291 extensions={ ("beremiz", name):call for name, call in xsltext}) |
|
292 |
|
293 def _process_xslt(self, root, debug, **kwargs): |
|
294 self.debug = debug |
|
295 return self.xslt(root,**{k:etree.XSLT.strparam(v) for k,v in kwargs.iteritems()}) |
|
296 |
270 |
297 class InstancesPathCollector(XSLTModelQuery): |
271 class InstancesPathCollector(XSLTModelQuery): |
298 """ object for collecting instances path list""" |
272 """ object for collecting instances path list""" |
299 def __init__(self, controller): |
273 def __init__(self, controller): |
300 self.Instances = [] |
274 self.Instances = [] |