@@ -7,6 +7,10 import sys | |||
|
7 | 7 | import ast |
|
8 | 8 | import datetime |
|
9 | 9 | import traceback |
|
10 | import math | |
|
11 | import time | |
|
12 | from multiprocessing import Process, Queue, cpu_count | |
|
13 | ||
|
10 | 14 | import schainpy |
|
11 | 15 | import schainpy.admin |
|
12 | 16 | from schainpy.utils.log import logToFile |
@@ -14,11 +18,11 from schainpy.utils.log import logToFile | |||
|
14 | 18 | from xml.etree.ElementTree import ElementTree, Element, SubElement, tostring |
|
15 | 19 | from xml.dom import minidom |
|
16 | 20 | |
|
17 | from multiprocessing import cpu_count | |
|
18 | 21 | from schainpy.model import * |
|
19 | 22 | from time import sleep |
|
20 | 23 | |
|
21 | 24 | |
|
25 | ||
|
22 | 26 | def prettify(elem): |
|
23 | 27 | """Return a pretty-printed XML string for the Element. |
|
24 | 28 | """ |
@@ -100,6 +104,9 class ParameterConf(): | |||
|
100 | 104 | |
|
101 | 105 | return self.__formated_value |
|
102 | 106 | |
|
107 | if format == 'obj': | |
|
108 | return value | |
|
109 | ||
|
103 | 110 | if format == 'str': |
|
104 | 111 | self.__formated_value = str(value) |
|
105 | 112 | return self.__formated_value |
@@ -217,9 +224,11 class ParameterConf(): | |||
|
217 | 224 | self.id = str(new_id) |
|
218 | 225 | |
|
219 | 226 | def setup(self, id, name, value, format='str'): |
|
220 | ||
|
221 | 227 | self.id = str(id) |
|
222 | 228 | self.name = name |
|
229 | if format == 'obj': | |
|
230 | self.value = value | |
|
231 | else: | |
|
223 | 232 | self.value = str(value) |
|
224 | 233 | self.format = str.lower(format) |
|
225 | 234 | |
@@ -234,7 +243,7 class ParameterConf(): | |||
|
234 | 243 | self.format = format |
|
235 | 244 | |
|
236 | 245 | def makeXml(self, opElement): |
|
237 | ||
|
246 | if self.name not in ('queue',): | |
|
238 | 247 | parmElement = SubElement(opElement, self.ELEMENTNAME) |
|
239 | 248 | parmElement.set('id', str(self.id)) |
|
240 | 249 | parmElement.set('name', self.name) |
@@ -332,6 +341,19 class OperationConf(): | |||
|
332 | 341 | |
|
333 | 342 | return value |
|
334 | 343 | |
|
344 | ||
|
345 | def getKwargs(self): | |
|
346 | ||
|
347 | kwargs = {} | |
|
348 | ||
|
349 | for parmConfObj in self.parmConfObjList: | |
|
350 | if self.name == 'run' and parmConfObj.name == 'datatype': | |
|
351 | continue | |
|
352 | ||
|
353 | kwargs[parmConfObj.name] = parmConfObj.getValue() | |
|
354 | ||
|
355 | return kwargs | |
|
356 | ||
|
335 | 357 | def setup(self, id, name, priority, type): |
|
336 | 358 | |
|
337 | 359 | self.id = str(id) |
@@ -420,6 +442,7 class OperationConf(): | |||
|
420 | 442 | |
|
421 | 443 | def createObject(self, plotter_queue=None): |
|
422 | 444 | |
|
445 | ||
|
423 | 446 | if self.type == 'self': |
|
424 | 447 | raise ValueError, "This operation type cannot be created" |
|
425 | 448 | |
@@ -431,11 +454,15 class OperationConf(): | |||
|
431 | 454 | opObj = Plotter(self.name, plotter_queue) |
|
432 | 455 | |
|
433 | 456 | if self.type == 'external' or self.type == 'other': |
|
457 | ||
|
434 | 458 | className = eval(self.name) |
|
435 | opObj = className() | |
|
459 | kwargs = self.getKwargs() | |
|
460 | ||
|
461 | opObj = className(**kwargs) | |
|
436 | 462 | |
|
437 | 463 | return opObj |
|
438 | 464 | |
|
465 | ||
|
439 | 466 | class ProcUnitConf(): |
|
440 | 467 | |
|
441 | 468 | id = None |
@@ -635,19 +662,32 class ProcUnitConf(): | |||
|
635 | 662 | for opConfObj in self.opConfObjList: |
|
636 | 663 | opConfObj.printattr() |
|
637 | 664 | |
|
665 | ||
|
666 | def getKwargs(self): | |
|
667 | ||
|
668 | opObj = self.opConfObjList[0] | |
|
669 | kwargs = opObj.getKwargs() | |
|
670 | ||
|
671 | return kwargs | |
|
672 | ||
|
638 | 673 | def createObjects(self, plotter_queue=None): |
|
639 | 674 | |
|
640 | 675 | className = eval(self.name) |
|
641 | procUnitObj = className() | |
|
676 | kwargs = self.getKwargs() | |
|
677 | procUnitObj = className(**kwargs) | |
|
642 | 678 | |
|
643 | 679 | for opConfObj in self.opConfObjList: |
|
644 | 680 | |
|
645 |
if opConfObj.type |
|
|
681 | if opConfObj.type=='self' and self.name=='run': | |
|
682 | continue | |
|
683 | elif opConfObj.type=='self': | |
|
684 | procUnitObj.addOperationKwargs(opConfObj.id, **opConfObj.getKwargs()) | |
|
646 | 685 | continue |
|
647 | 686 | |
|
648 | 687 | opObj = opConfObj.createObject(plotter_queue) |
|
649 | 688 | |
|
650 | 689 | self.opObjDict[opConfObj.id] = opObj |
|
690 | ||
|
651 | 691 | procUnitObj.addOperation(opObj, opConfObj.id) |
|
652 | 692 | |
|
653 | 693 | self.procUnitObj = procUnitObj |
@@ -733,14 +773,13 class ReadUnitConf(ProcUnitConf): | |||
|
733 | 773 | name = datatype |
|
734 | 774 | else: |
|
735 | 775 | name = '%sReader' %(datatype) |
|
736 | ||
|
737 | 776 | if datatype==None: |
|
738 | 777 | datatype = name.replace('Reader','') |
|
739 | 778 | |
|
740 | 779 | self.id = id |
|
741 | 780 | self.name = name |
|
742 | 781 | self.datatype = datatype |
|
743 | ||
|
782 | if path != '': | |
|
744 | 783 | self.path = os.path.abspath(path) |
|
745 | 784 | self.startDate = startDate |
|
746 | 785 | self.endDate = endDate |
@@ -749,7 +788,8 class ReadUnitConf(ProcUnitConf): | |||
|
749 | 788 | |
|
750 | 789 | self.inputId = '0' |
|
751 | 790 | self.parentId = parentId |
|
752 | ||
|
791 | self.queue = queue | |
|
792 | self.server = server | |
|
753 | 793 | self.addRunOperation(**kwargs) |
|
754 | 794 | |
|
755 | 795 | def update(self, datatype, path, startDate, endDate, startTime, endTime, parentId=None, name=None, **kwargs): |
@@ -791,15 +831,19 class ReadUnitConf(ProcUnitConf): | |||
|
791 | 831 | |
|
792 | 832 | opObj = self.addOperation(name = 'run', optype = 'self') |
|
793 | 833 | |
|
834 | if self.server is None: | |
|
794 | 835 | opObj.addParameter(name='datatype' , value=self.datatype, format='str') |
|
795 | 836 | opObj.addParameter(name='path' , value=self.path, format='str') |
|
796 | 837 | opObj.addParameter(name='startDate' , value=self.startDate, format='date') |
|
797 | 838 | opObj.addParameter(name='endDate' , value=self.endDate, format='date') |
|
798 | 839 | opObj.addParameter(name='startTime' , value=self.startTime, format='time') |
|
799 | 840 | opObj.addParameter(name='endTime' , value=self.endTime, format='time') |
|
800 | ||
|
841 | opObj.addParameter(name='queue' , value=self.queue, format='obj') | |
|
801 | 842 | for key, value in kwargs.items(): |
|
802 | 843 | opObj.addParameter(name=key, value=value, format=type(value).__name__) |
|
844 | else: | |
|
845 | opObj.addParameter(name='server' , value=self.server, format='str') | |
|
846 | ||
|
803 | 847 | |
|
804 | 848 | return opObj |
|
805 | 849 |
General Comments 0
You need to be logged in to leave comments.
Login now