1
2
3
4 """
5 A class for writting a Python IceTrayConfig object to XML
6
7 copyright (c) 2005 the icecube collaboration
8
9 @version: $Revision: 1.0 $
10 @date: $Date: $
11 @author: Juan Carlos Diaz Velez <juancarlos@icecube.wisc.edu>
12
13 @todo: Many of the same todo items on xmlparser.py
14 """
15
16 import sys,os
17 import string
18 import re
19 import types
20 import logging
21 import logger
22 from iceprod.core import ipxml
23 from dataclasses import *
24 from iceprod.core.metadata import *
25 from os.path import expandvars
26
27
28 SupportedTypes = ['bool', 'int', 'long', 'float', 'double', 'string','OMKey']
29 VectorTypes = ['boolv', 'intv', 'longv', 'floatv', 'doublev', 'stringv','OMKeyv']
30
32
33 - def __init__(self,
34 steering,uri='http://x2100.icecube.wisc.edu/dtd/iceprod.v2.dtd',
35 add_descriptions=False,
36 parser=None):
37 """
38 Initialize and build DOM tree
39 from IceTrayConfig object
40 """
41 self.steering = steering
42 self.parser = parser
43 dom = ipxml.getDOMImplementation()
44 self.logger = logging.getLogger('XMLWriter')
45 self.substitutions = {}
46
47 doctype = dom.createDocumentType("configuration",
48 "-//W3C//DTD XML 1.0 Strict//EN", uri)
49
50 self.doc = dom.createDocument( None, "configuration", doctype )
51 config = self.doc.documentElement
52 if steering.GetParentId():
53 config.setAttribute('parentid', str(steering.GetParentId()))
54 if steering.GetVersion():
55 config.setAttribute('version', str(steering.GetVersion()))
56 config.setAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance')
57 config.setAttribute('xsi:noNamespaceSchemaLocation','config.xsd')
58
59
60 if steering.HasDIFPlus():
61 mw = MetadataWriter(steering.GetDIFPlus(),False)
62 mw.AddDIFPlus(self.doc,config)
63
64 self.LoadSteering(config,steering)
65 for tray in steering.GetTrays():
66 trayElement = self.AddTray(config,tray)
67 self.AddIceProdPres(trayElement,tray)
68 self.AddServices(trayElement,tray,add_descriptions)
69 self.AddModules(trayElement,tray,add_descriptions)
70 self.AddConnections(trayElement,tray)
71 self.AddIceProdPosts(trayElement,tray)
72 self.AddMetaProjects(trayElement,tray)
73 self.AddProjects(trayElement,tray)
74
76 """
77 Substitute parameter values
78 Useful for changing URLs, etc.
79 @param substitutions: map of key,value pairs to substitute
80 """
81 self.substitutions = substitutions
82
84 """
85 Read Steering parameters from IceTrayConfig tree
86 and generate the entries in DOM tree.
87 """
88
89 doc = self.doc
90
91 steeringElement = doc.createElement( 'steering' )
92 docNode.appendChild(steeringElement)
93
94 category = steering.GetCategory()
95 categoryElement = doc.createElement( 'category' )
96 if category:
97 categoryElement.appendChild(doc.createTextNode(category))
98 steeringElement.appendChild(categoryElement)
99
100 for ex in steering.GetExterns():
101 externalElement = doc.createElement( 'external' )
102 steeringElement.appendChild(externalElement)
103 nameElement = doc.createElement('name')
104 nameElement.appendChild(doc.createTextNode(ex.GetName()))
105 externalElement.appendChild(nameElement)
106
107 if ex.GetDescription():
108 descElement = doc.createElement('description')
109 descElement.appendChild(doc.createTextNode(ex.GetDescription()))
110 externalElement.appendChild(descElement)
111 if ex.GetVersion():
112 versionElement = doc.createElement('version')
113 versionElement.appendChild(doc.createTextNode(ex.GetVersion()))
114 externalElement.appendChild(versionElement)
115 execElement = doc.createElement('executable')
116 execElement.appendChild(doc.createTextNode(ex.GetExec()))
117 externalElement.appendChild(execElement)
118 if ex.GetArgs():
119 argElement = doc.createElement('args')
120 argElement.appendChild(doc.createTextNode(ex.GetArgs()))
121 externalElement.appendChild(argElement)
122 if ex.GetInFile():
123 inElement = doc.createElement('in')
124 inElement.appendChild(doc.createTextNode(ex.GetInFile()))
125 externalElement.appendChild(inElement)
126 if ex.GetOutFile():
127 outElement = doc.createElement('out')
128 outElement.appendChild(doc.createTextNode(ex.GetOutFile()))
129 externalElement.appendChild(outElement)
130 if ex.GetErrFile():
131 errElement = doc.createElement('err')
132 errElement.appendChild(doc.createTextNode(ex.GetErrFile()))
133 externalElement.appendChild(errElement)
134
135
136 for es in ex.GetSteering():
137 esteerElement = doc.createElement('extern-steering')
138
139 esNameElement = doc.createElement('name')
140 esNameElement.appendChild(doc.createTextNode(es.GetName()))
141 esteerElement.appendChild(esNameElement)
142
143 esTextElement = doc.createElement('text')
144 esTextElement.appendChild(doc.createTextNode(es.GetText()))
145 esteerElement.appendChild(esTextElement)
146
147 externalElement.appendChild(esteerElement)
148
149
150
151
152 of = steering.GetOF()
153 if of:
154 filtElement = doc.createElement( 'OF' )
155 steeringElement.appendChild(filtElement)
156 if of.GetPrefix():
157 filtElement.setAttribute('prefix',of.GetPrefix())
158 filtElement.setAttribute('search',str(of.search))
159 for path in of.GetPaths():
160 pathElement = doc.createElement( 'path' )
161 if path.GetRegex():
162 pathElement.setAttribute('regex',path.regex)
163 pathElement.appendChild(doc.createTextNode(path.path))
164 filtElement.appendChild(pathElement)
165
166
167
168 steeringParams = doc.createElement( 'parameters' )
169 steeringElement.appendChild(steeringParams)
170 for par in steering.GetParameters():
171
172 ptype = par.GetType()
173 if not ptype in SupportedTypes:
174 self.logger.error('In steering, found unsupported type: %s' % ptype)
175 sys.exit(1)
176 pTypeElement = doc.createElement( ptype )
177 steeringParams.appendChild(pTypeElement)
178
179 pname = par.GetName()
180 pNameElement = doc.createElement( 'name' )
181 pNameElement.appendChild(doc.createTextNode(pname))
182 pTypeElement.appendChild(pNameElement)
183
184 pvalue = par.GetValue()
185 pValueElement = doc.createElement( 'value' )
186 if self.parser: pvalue = self.parser.parse(pvalue)
187 for rkey,rvalue in self.substitutions.items():
188 print rkey,rvalue
189 print re.match(rkey,pvalue)
190 print re.sub(rkey, rvalue, pvalue)
191 if re.match(rkey,pvalue):
192 pvalue = re.sub(rkey, rvalue, pvalue)
193 if self.parser: pvalue = self.parser.parse(pvalue)
194
195 pValueElement.appendChild(doc.createTextNode(pvalue))
196 pTypeElement.appendChild(pValueElement)
197
198 systemElement = doc.createElement( 'system' )
199 steeringElement.appendChild(systemElement)
200 for opt in steering.GetBatchOpts():
201
202 batchoptElement = doc.createElement( 'batchopt' )
203
204 bname = opt.GetName()
205 bNameElement = doc.createElement( 'name' )
206 bNameElement.appendChild(doc.createTextNode(bname))
207 batchoptElement.appendChild(bNameElement)
208
209 btype = opt.GetType()
210 bTypeElement = doc.createElement( 'type' )
211 bTypeElement.appendChild(doc.createTextNode(btype))
212 batchoptElement.appendChild(bTypeElement)
213
214 bvalue = opt.GetValue()
215 bValueElement = doc.createElement( 'value' )
216 bValueElement.appendChild(doc.createTextNode(bvalue))
217 batchoptElement.appendChild(bValueElement)
218
219 systemElement.appendChild(batchoptElement)
220
221 for opt in steering.GetSysOpts():
222 sysoptElement = doc.createElement( 'sysopt' )
223
224 sname = opt.GetName()
225 sNameElement = doc.createElement( 'name' )
226 sNameElement.appendChild(doc.createTextNode(sname))
227 sysoptElement.appendChild(sNameElement)
228
229 svalue = opt.GetValue()
230 sValueElement = doc.createElement( 'value' )
231 sValueElement.appendChild(doc.createTextNode(str(svalue)))
232 sysoptElement.appendChild(sValueElement)
233 systemElement.appendChild(sysoptElement)
234
235
236
237 statisticsElement = doc.createElement( 'statistics' )
238 for stat in steering.GetStatistics():
239 statElement = doc.createElement( 'item' )
240 statElement.appendChild(doc.createTextNode(stat))
241 statisticsElement.appendChild(statElement)
242 steeringElement.appendChild(statisticsElement)
243
244
245 for depend in steering.GetDependencies():
246 dependencyElement = doc.createElement( 'dependency' )
247 if self.parser: depend = self.parser.parse(depend)
248 if type(depend) in types.StringTypes:
249 dependencyElement.appendChild(doc.createTextNode(depend))
250 else:
251 dependencyElement.appendChild(doc.createTextNode(depend.GetName()))
252 steeringElement.appendChild(dependencyElement)
253
254 for jobdepend in steering.GetJobDependencies():
255 inputElement = doc.createElement( 'JobDependency' )
256 datasetElement = doc.createElement( 'dataset' )
257 jobElement = doc.createElement( 'job' )
258 datasetElement.appendChild(doc.createTextNode(str(jobdepend.dataset)))
259 jobElement.appendChild(doc.createTextNode(str(jobdepend.job)))
260 inputElement.appendChild(datasetElement)
261 inputElement.appendChild(jobElement)
262 steeringElement.appendChild(inputElement)
263
264 desc = steering.GetDescription()
265 if desc:
266 descElement = doc.createElement( 'description' )
267 descElement.appendChild(doc.createTextNode(desc))
268 steeringElement.appendChild(descElement)
269
270
271 tasks = steering.GetTaskDefinitions()
272 if tasks:
273 tasksElement = doc.createElement( 'tasks' )
274
275
276 for name,task in tasks.items():
277 logger.debug("found task %s" % name)
278 taskElement = doc.createElement( 'task' )
279 taskElement.setAttribute('id', name)
280 if task.ParallelExecutionEnabled():
281 taskElement.setAttribute('parallel', 'true')
282
283 trays = task.GetTrays().items()
284 for idx,tray in task.GetTrays().items():
285 trayElement = doc.createElement( 'taskTray' )
286 trayElement.setAttribute('tray', str(idx))
287 iters = ",".join(map(str, tray.GetIters()))
288 trayElement.setAttribute('iters', iters)
289 msg = "task %s has tray %u, iters %s"
290 logger.debug(msg % (name,idx,tray.GetIters()))
291 if tray.RunExternsEnabled():
292 trayElement.setAttribute('externs', 'true')
293 taskElement.appendChild(trayElement)
294
295 if task.GetRequirements():
296 reqsElement = doc.createElement( 'taskReqs' )
297 reqsElement.appendChild(doc.createTextNode(task.GetRequirements()))
298 taskElement.appendChild(reqsElement)
299 if task.GetBatchOpts():
300 optsElement = doc.createElement( 'taskOpts' )
301 optsElement.appendChild(doc.createTextNode(task.GetBatchOpts()))
302 taskElement.appendChild(optsElement)
303 tasksElement.appendChild(taskElement)
304
305 gridsElement = doc.createElement( 'grids' )
306 taskElement.appendChild(gridsElement)
307 for tgrid in task.GetGrids():
308 tgridElement = doc.createElement( 'gridsite' )
309 tgridElement.appendChild(doc.createTextNode(tgrid))
310 gridsElement.appendChild(tgridElement)
311
312
313 for name,task in tasks.items():
314 for parent in task.GetParents():
315 logger.debug("task %s has parent %s" % (name, parent))
316 relElement = doc.createElement( 'taskRel' )
317 parentElement = doc.createElement( 'taskParent' )
318 parentElement.setAttribute('taskId', parent)
319 childElement = doc.createElement( 'taskChild' )
320 childElement.setAttribute('taskId', name)
321
322 relElement.appendChild(parentElement)
323 relElement.appendChild(childElement)
324 tasksElement.appendChild(relElement)
325
326 logger.debug("finished processing all tasks")
327 steeringElement.appendChild(tasksElement)
328
329 - def AddTray(self,docElement,tray):
330 """
331 Adds icetray project libraries from IceTrayConfig to DOM tree
332 and sets them as attributes to <icetray> tag.
333 """
334 doc = self.doc
335 icetrayElement = doc.createElement( 'icetray' )
336 icetrayElement.setAttribute('events',str(tray.GetEvents()))
337 icetrayElement.setAttribute('iter',str(tray.GetIterations()))
338
339
340 python = tray.GetPython()
341 if python:
342 icetrayElement.setAttribute('python',python)
343
344 if tray.GetName():
345 icetrayNameElement = doc.createElement( 'name' )
346 icetrayNameNode = doc.createTextNode( tray.GetName() )
347 icetrayNameElement.appendChild( icetrayNameNode )
348 icetrayElement.appendChild( icetrayNameElement )
349
350 file_types = ('input', 'output')
351 icetrayFilesElement = doc.createElement( 'files' )
352 for file_type in file_types:
353 if file_type == 'input':
354 func = tray.GetInputFiles
355 else:
356 func = tray.GetOutputFiles
357 iofElement = doc.createElement( file_type )
358 for file in func():
359 fileElement = doc.createElement( 'file' )
360 if file.IsPhotonicsTable():
361 fileElement.setAttribute( 'photonics', 'true' )
362 fileNode = doc.createTextNode( file.GetName() )
363 fileElement.appendChild( fileNode )
364 iofElement.appendChild( fileElement )
365 logger.debug("Added %s as an %s file" % (file.GetName(), file_type))
366 if func():
367 icetrayFilesElement.appendChild(iofElement)
368
369 icetrayElement.appendChild(icetrayFilesElement)
370 docElement.appendChild(icetrayElement)
371 return icetrayElement
372
373
414
416 """
417 Load projects from IceTrayConfig and add the to DOM tree
418 """
419
420 doc = self.doc
421 projects = i3config.GetProjectList()
422
423 for p in projects:
424
425 projElement = doc.createElement( 'project' )
426 if p.GetDependencies():
427 projElement.setAttribute('dependencies',','.join(p.GetDependencies()))
428 icetray.appendChild(projElement)
429
430 nameElement = doc.createElement( 'name' )
431 nameNode = doc.createTextNode( p.GetName() )
432 nameElement.appendChild(nameNode)
433 projElement.appendChild(nameElement)
434
435 versionElement = doc.createElement( 'version' )
436 versionNode = doc.createTextNode( p.GetVersion() )
437 versionElement.appendChild(versionNode)
438 projElement.appendChild(versionElement)
439
441 """
442 Create a value element depending on the type
443 """
444 if ptype.startswith("OMKey"):
445 if default_value:
446 pValueElement = doc.createElement( 'defaultmap' )
447 else:
448 pValueElement = doc.createElement( 'map' )
449 pEntryElement0 = doc.createElement( 'cvalue' )
450 pEntryElement0.appendChild(doc.createTextNode(str(pvalue.stringid)))
451 pEntryElement0.setAttribute('label', 'stringid' )
452 pValueElement.appendChild(pEntryElement0)
453 pEntryElement1 = doc.createElement( 'cvalue' )
454 pEntryElement1.appendChild(doc.createTextNode(str(pvalue.omid)))
455 pEntryElement1.setAttribute('label', 'omid' )
456 pValueElement.appendChild(pEntryElement1)
457 else:
458 if default_value:
459 pValueElement = doc.createElement( 'default' )
460 else:
461 pValueElement = doc.createElement( 'value' )
462 pValueElement.appendChild(doc.createTextNode(str(pvalue.value)))
463 if pvalue.unit:
464 pValueElement.setAttribute('unit', pvalue.unit )
465 return pValueElement
466
467 - def AddServices(self,icetray,i3config,add_descriptions=False):
468 """
469 Load services from IceTrayConfig and add the to DOM tree
470 """
471
472 doc = self.doc
473 services = i3config.GetServices()
474
475 for s in services:
476
477 servElement = doc.createElement( 'service' )
478 servElement.setAttribute('class',s.GetClass())
479 projects = ','.join( [p.GetName() for p in s.GetProjectList()] )
480 projects = projects.strip()
481 if projects:
482 servElement.setAttribute('projects',projects)
483 icetray.appendChild(servElement)
484
485 nameElement = doc.createElement( 'name' )
486 nameNode = doc.createTextNode( s.GetName() )
487 nameElement.appendChild(nameNode)
488 servElement.appendChild(nameElement)
489 if s.GetDescription():
490 servElement.appendChild(doc.createComment(s.GetDescription()))
491
492 paramsElement = doc.createElement( 'parameters' )
493 servElement.appendChild(paramsElement)
494
495 for param in s.GetParameters():
496
497 ptype = param.GetType()
498 pTypeElement = doc.createElement( param.GetType() )
499 paramsElement.appendChild(pTypeElement)
500
501 pNameElement = doc.createElement( 'name' )
502 pNameNode = doc.createTextNode( param.GetName() )
503 pNameElement.appendChild(pNameNode)
504 pTypeElement.appendChild(pNameElement)
505
506 if add_descriptions:
507 pDescriptionElement = doc.createElement( 'description' )
508 pDescriptionNode = doc.createTextNode( param.GetDescription() )
509 pDescriptionElement.appendChild(pDescriptionNode)
510 pTypeElement.appendChild(pDescriptionElement)
511
512
513 if ptype in VectorTypes:
514 for pvalue in param.GetValue():
515 if self.parser: pvalue.value = self.parser.parse(pvalue.value)
516 pValueElement = self.mkValueElement(ptype,pvalue,doc)
517 pTypeElement.appendChild(pValueElement)
518 else:
519 pValueElement = self.mkValueElement(ptype,param.GetValue(),doc)
520 pTypeElement.appendChild(pValueElement)
521 if param.GetDefault():
522 if ptype in VectorTypes:
523
524
525
526 pass
527 else:
528 pValueElement = self.mkValueElement(ptype,param.GetDefault(),doc,True)
529 pTypeElement.appendChild(pValueElement)
530
531
532
533 - def AddModules(self,icetray,i3config,add_descriptions=False):
534 """
535 Load modules from IceTrayConfig and add the to DOM tree
536 """
537
538 doc = self.doc
539 modules = i3config.GetModules()
540
541 for m in modules:
542
543 modElement = doc.createElement( 'module' )
544 modElement.setAttribute('class',m.GetClass())
545 projects = ','.join( [p.GetName() for p in m.GetProjectList()] )
546 if projects:
547 modElement.setAttribute('projects',projects)
548 icetray.appendChild(modElement)
549
550 nameElement = doc.createElement( 'name' )
551 nameNode = doc.createTextNode( m.GetName() )
552 nameElement.appendChild(nameNode)
553 modElement.appendChild(nameElement)
554 if m.GetDescription():
555 modElement.appendChild(doc.createComment(m.GetDescription()))
556
557 paramsElement = doc.createElement( 'parameters' )
558 modElement.appendChild(paramsElement)
559
560 for param in m.GetParameters():
561
562 ptype = param.GetType()
563 pTypeElement = doc.createElement( param.GetType() )
564
565 pNameElement = doc.createElement( 'name' )
566 pNameNode = doc.createTextNode( param.GetName() )
567 pNameElement.appendChild(pNameNode)
568 pTypeElement.appendChild(pNameElement)
569 paramsElement.appendChild(pTypeElement)
570
571 if add_descriptions:
572 pDescriptionElement = doc.createElement( 'description' )
573 pDescriptionNode = doc.createTextNode( param.GetDescription() )
574 pDescriptionElement.appendChild(pDescriptionNode)
575 pTypeElement.appendChild(pDescriptionElement)
576
577
578 if ptype in VectorTypes:
579 for pvalue in param.GetValue():
580 if self.parser: pvalue = self.parser.parse(pvalue)
581 pValueElement = self.mkValueElement(ptype,pvalue,doc)
582 pTypeElement.appendChild(pValueElement)
583 else:
584 pValueElement = self.mkValueElement(ptype,param.GetValue(),doc)
585 pTypeElement.appendChild(pValueElement)
586
587 if param.GetDefault():
588 if ptype in VectorTypes:
589
590
591
592 pass
593 else:
594 pValueElement = self.mkValueElement(ptype,param.GetDefault(),doc,True)
595 pTypeElement.appendChild(pValueElement)
596
598 """
599 Load modules from IceTrayConfig and add the to DOM tree
600 """
601
602 doc = self.doc
603 pres = i3config.GetIceProdPres()
604
605 for m in pres:
606
607 modElement = doc.createElement( 'IceProdPre' )
608 modElement.setAttribute('class',m.GetClass())
609 modElement.setAttribute('projects','iceprod.modules')
610 icetray.appendChild(modElement)
611
612 nameElement = doc.createElement( 'name' )
613 nameNode = doc.createTextNode( m.GetName() )
614 nameElement.appendChild(nameNode)
615 modElement.appendChild(nameElement)
616 if m.GetDescription():
617 modElement.appendChild(doc.createComment(m.GetDescription()))
618
619 paramsElement = doc.createElement( 'parameters' )
620 modElement.appendChild(paramsElement)
621
622 for param in m.GetParameters():
623
624 pNameElement = doc.createElement( 'name' )
625 pNameNode = doc.createTextNode( param.GetName() )
626 pNameElement.appendChild(pNameNode)
627 pTypeElement = doc.createElement( param.GetType() )
628 pTypeElement.appendChild(pNameElement)
629 paramsElement.appendChild(pTypeElement)
630 ptype = param.GetType()
631
632 if ptype in VectorTypes:
633 for pvalue in param.GetValue():
634 if self.parser: pvalue.value = self.parser.parse(pvalue.value)
635 pValueElement = self.mkValueElement(ptype,pvalue,doc)
636 pTypeElement.appendChild(pValueElement)
637 else:
638 pvalue = param.GetValue()
639 if self.parser: pvalue.value = self.parser.parse(pvalue.value)
640 pValueElement = self.mkValueElement(ptype,pvalue,doc)
641 pTypeElement.appendChild(pValueElement)
642
643 if param.GetDefault() != None:
644 if ptype in VectorTypes:
645 for pvalue in param.GetDefault():
646 if self.parser: pvalue.value = self.parser.parse(pvalue.value)
647 pValueElement = self.mkValueElement(ptype,pvalue,doc,True)
648 pTypeElement.appendChild(pValueElement)
649 else:
650 pValueElement = self.mkValueElement(ptype,param.GetDefault(),doc,True)
651 pTypeElement.appendChild(pValueElement)
652
653
654 - def AddIceProdPosts(self,icetray,i3config):
655 """
656 Load modules from IceTrayConfig and add the to DOM tree
657 """
658
659 doc = self.doc
660 posts = i3config.GetIceProdPosts()
661
662 for m in posts:
663
664 modElement = doc.createElement( 'IceProdPost' )
665 modElement.setAttribute('class',m.GetClass())
666 modElement.setAttribute('projects','iceprod.modules')
667 icetray.appendChild(modElement)
668
669 nameElement = doc.createElement( 'name' )
670 nameNode = doc.createTextNode( m.GetName() )
671 nameElement.appendChild(nameNode)
672 modElement.appendChild(nameElement)
673 if m.GetDescription():
674 modElement.appendChild(doc.createComment(m.GetDescription()))
675
676 paramsElement = doc.createElement( 'parameters' )
677 modElement.appendChild(paramsElement)
678
679 for param in m.GetParameters():
680
681 pNameElement = doc.createElement( 'name' )
682 pNameNode = doc.createTextNode( param.GetName() )
683 pNameElement.appendChild(pNameNode)
684 pTypeElement = doc.createElement( param.GetType() )
685 pTypeElement.appendChild(pNameElement)
686 paramsElement.appendChild(pTypeElement)
687 ptype = param.GetType()
688
689 if ptype in VectorTypes:
690 for pvalue in param.GetValue():
691 if self.parser: pvalue.value = self.parser.parse(pvalue.value)
692 pValueElement = self.mkValueElement(ptype,pvalue,doc)
693 pTypeElement.appendChild(pValueElement)
694 else:
695 pvalue = param.GetValue()
696 if self.parser: pvalue.value = self.parser.parse(pvalue.value)
697 pValueElement = self.mkValueElement(ptype,pvalue,doc)
698 pTypeElement.appendChild(pValueElement)
699
700 if param.GetDefault() != None:
701 if ptype in VectorTypes:
702 for pvalue in param.GetDefault():
703 if self.parser: pvalue.value = self.parser.parse(pvalue.value)
704 pValueElement = self.mkValueElement(ptype,pvalue,doc,True)
705 pTypeElement.appendChild(pValueElement)
706 else:
707 pValueElement = self.mkValueElement(ptype,param.GetDefault(),doc,True)
708 pTypeElement.appendChild(pValueElement)
709
710
711
713 """
714 Read connections from IceTrayConfig and load them to DOM tree
715 """
716
717 doc = self.doc
718 connections = i3config.GetConnections()
719
720
721
722
723
724 for c in connections:
725
726 inbox = c.GetInbox()
727 outbox = c.GetOutbox()
728
729 connectElement = doc.createElement( 'connection' )
730 icetray.appendChild(connectElement)
731
732 outModuleElement = doc.createElement( 'module' )
733 outModuleNode = doc.createTextNode( outbox.GetModule() )
734 outModuleElement.appendChild(outModuleNode)
735
736 outboxElement = doc.createElement( 'outbox' )
737 outboxNode = doc.createTextNode( outbox.GetBoxName() )
738 outboxElement.appendChild(outboxNode)
739
740 fromElement = doc.createElement( 'from' )
741 fromElement.appendChild(outModuleElement)
742 fromElement.appendChild(outboxElement)
743 connectElement.appendChild(fromElement)
744
745 inModuleElement = doc.createElement( 'module' )
746 inModuleNode = doc.createTextNode( inbox.GetModule() )
747 inModuleElement.appendChild(inModuleNode)
748
749 inboxElement = doc.createElement( 'inbox' )
750 inboxNode = doc.createTextNode( inbox.GetBoxName() )
751 inboxElement.appendChild(inboxNode)
752
753 toElement = doc.createElement( 'to' )
754 toElement.appendChild(inModuleElement)
755 toElement.appendChild(inboxElement)
756 connectElement.appendChild(toElement)
757
759 return self.doc
760
761 - def toXML(self, fname=None):
762 return self.doc.toxml()
763
764
766 """
767 Write DOM tree as human readable xml to a file
768 """
769 if fname:
770 file_object = open(fname, "w")
771 ipxml.PrettyPrint(self.doc, file_object)
772 file_object.close()
773 else:
774 ipxml.PrettyPrint(self.doc)
775