@@ -5,6 +5,7 Created on September , 2012 | |||||
5 |
|
5 | |||
6 | import sys |
|
6 | import sys | |
7 | import ast |
|
7 | import ast | |
|
8 | import datetime | |||
8 | import traceback |
|
9 | import traceback | |
9 | import schainpy |
|
10 | import schainpy | |
10 | import schainpy.admin |
|
11 | import schainpy.admin | |
@@ -685,7 +686,7 class ReadUnitConf(ProcUnitConf): | |||||
685 | self.name = name |
|
686 | self.name = name | |
686 | self.datatype = datatype |
|
687 | self.datatype = datatype | |
687 |
|
688 | |||
688 | self.path = path |
|
689 | self.path = os.path.abspath(path) | |
689 | self.startDate = startDate |
|
690 | self.startDate = startDate | |
690 | self.endDate = endDate |
|
691 | self.endDate = endDate | |
691 | self.startTime = startTime |
|
692 | self.startTime = startTime | |
@@ -723,6 +724,13 class ReadUnitConf(ProcUnitConf): | |||||
723 | self.parentId = parentId |
|
724 | self.parentId = parentId | |
724 |
|
725 | |||
725 | self.updateRunOperation(**kwargs) |
|
726 | self.updateRunOperation(**kwargs) | |
|
727 | ||||
|
728 | def removeOperations(self): | |||
|
729 | ||||
|
730 | for obj in self.opConfObjList: | |||
|
731 | del obj | |||
|
732 | ||||
|
733 | self.opConfObjList = [] | |||
726 |
|
734 | |||
727 | def addRunOperation(self, **kwargs): |
|
735 | def addRunOperation(self, **kwargs): | |
728 |
|
736 | |||
@@ -862,9 +870,12 class Project(): | |||||
862 | self.name = name |
|
870 | self.name = name | |
863 | self.description = description |
|
871 | self.description = description | |
864 |
|
872 | |||
865 | def addReadUnit(self, datatype=None, name=None, **kwargs): |
|
873 | def addReadUnit(self, id=None, datatype=None, name=None, **kwargs): | |
866 |
|
874 | |||
867 | idReadUnit = self.__getNewId() |
|
875 | if id is None: | |
|
876 | idReadUnit = self.__getNewId() | |||
|
877 | else: | |||
|
878 | idReadUnit = str(id) | |||
868 |
|
879 | |||
869 | readUnitConfObj = ReadUnitConf() |
|
880 | readUnitConfObj = ReadUnitConf() | |
870 | readUnitConfObj.setup(idReadUnit, name, datatype, parentId=self.id, **kwargs) |
|
881 | readUnitConfObj.setup(idReadUnit, name, datatype, parentId=self.id, **kwargs) | |
@@ -939,30 +950,36 class Project(): | |||||
939 |
|
950 | |||
940 | def writeXml(self, filename): |
|
951 | def writeXml(self, filename): | |
941 |
|
952 | |||
942 | if not os.access(os.path.dirname(filename), os.W_OK): |
|
953 | abs_file = os.path.abspath(filename) | |
|
954 | ||||
|
955 | if not os.access(os.path.dirname(abs_file), os.W_OK): | |||
|
956 | print "No write permission on %s" %os.path.dirname(abs_file) | |||
943 | return 0 |
|
957 | return 0 | |
944 |
|
958 | |||
945 |
if os.path.isfile(file |
|
959 | if os.path.isfile(abs_file) and not(os.access(abs_file, os.W_OK)): | |
|
960 | print "File %s already exists and it could not be overwriten" %abs_file | |||
946 | return 0 |
|
961 | return 0 | |
947 |
|
962 | |||
948 | self.makeXml() |
|
963 | self.makeXml() | |
949 |
|
964 | |||
950 |
ElementTree(self.projectElement).write(file |
|
965 | ElementTree(self.projectElement).write(abs_file, method='xml') | |
951 |
|
966 | |||
952 |
self.filename = file |
|
967 | self.filename = abs_file | |
953 |
|
968 | |||
954 | return 1 |
|
969 | return 1 | |
955 |
|
970 | |||
956 | def readXml(self, filename): |
|
971 | def readXml(self, filename): | |
957 |
|
972 | |||
958 |
|
|
973 | abs_file = os.path.abspath(filename) | |
959 | print "%s does not exist" %filename |
|
974 | ||
|
975 | if not os.path.isfile(abs_file): | |||
|
976 | print "%s does not exist" %abs_file | |||
960 | return 0 |
|
977 | return 0 | |
961 |
|
978 | |||
962 | self.projectElement = None |
|
979 | self.projectElement = None | |
963 | self.procUnitConfObjDict = {} |
|
980 | self.procUnitConfObjDict = {} | |
964 |
|
981 | |||
965 |
self.projectElement = ElementTree().parse(file |
|
982 | self.projectElement = ElementTree().parse(abs_file) | |
966 |
|
983 | |||
967 | self.project = self.projectElement.tag |
|
984 | self.project = self.projectElement.tag | |
968 |
|
985 | |||
@@ -1030,6 +1047,42 class Project(): | |||||
1030 |
|
1047 | |||
1031 | self.__connect(puObjIN, thisPUObj) |
|
1048 | self.__connect(puObjIN, thisPUObj) | |
1032 |
|
1049 | |||
|
1050 | def __handleError(self, procUnitConfObj): | |||
|
1051 | ||||
|
1052 | import socket | |||
|
1053 | ||||
|
1054 | err = traceback.format_exception(sys.exc_info()[0], | |||
|
1055 | sys.exc_info()[1], | |||
|
1056 | sys.exc_info()[2]) | |||
|
1057 | ||||
|
1058 | subject = "SChain v%s: Error running %s\n" %(schainpy.__version__, procUnitConfObj.name) | |||
|
1059 | ||||
|
1060 | subtitle = "%s: %s\n" %(procUnitConfObj.getElementName() ,procUnitConfObj.name) | |||
|
1061 | subtitle += "Hostname: %s\n" %socket.gethostbyname(socket.gethostname()) | |||
|
1062 | subtitle += "Working directory: %s\n" %os.path.abspath("./") | |||
|
1063 | subtitle += "Configuration file: %s\n" %self.filename | |||
|
1064 | subtitle += "Time: %s\n" %str(datetime.datetime.now()) | |||
|
1065 | ||||
|
1066 | readUnitConfObj = self.getReadUnitObj() | |||
|
1067 | if readUnitConfObj: | |||
|
1068 | subtitle += "\nInput parameters:\n" | |||
|
1069 | subtitle += "[Data path = %s]\n" %readUnitConfObj.path | |||
|
1070 | subtitle += "[Data type = %s]\n" %readUnitConfObj.datatype | |||
|
1071 | subtitle += "[Start date = %s]\n" %readUnitConfObj.startDate | |||
|
1072 | subtitle += "[End date = %s]\n" %readUnitConfObj.endDate | |||
|
1073 | subtitle += "[Start time = %s]\n" %readUnitConfObj.startTime | |||
|
1074 | subtitle += "[End time = %s]\n" %readUnitConfObj.endTime | |||
|
1075 | ||||
|
1076 | message = "".join(err) | |||
|
1077 | ||||
|
1078 | sys.stderr.write(message) | |||
|
1079 | ||||
|
1080 | adminObj = schainpy.admin.SchainNotify() | |||
|
1081 | adminObj.sendAlert(message=message, | |||
|
1082 | subject=subject, | |||
|
1083 | subtitle=subtitle, | |||
|
1084 | filename=self.filename) | |||
|
1085 | ||||
1033 | def isPaused(self): |
|
1086 | def isPaused(self): | |
1034 | return 0 |
|
1087 | return 0 | |
1035 |
|
1088 | |||
@@ -1084,45 +1137,17 class Project(): | |||||
1084 | try: |
|
1137 | try: | |
1085 | sts = procUnitConfObj.run() |
|
1138 | sts = procUnitConfObj.run() | |
1086 | is_ok = is_ok or sts |
|
1139 | is_ok = is_ok or sts | |
|
1140 | except ValueError, e: | |||
|
1141 | print "***** Error occurred in %s *****" %(procUnitConfObj.name) | |||
|
1142 | sleep(0.5) | |||
|
1143 | print e | |||
|
1144 | is_ok = False | |||
|
1145 | break | |||
1087 | except: |
|
1146 | except: | |
1088 | print "***** Error occurred in %s *****" %(procUnitConfObj.name) |
|
1147 | print "***** Error occurred in %s *****" %(procUnitConfObj.name) | |
1089 |
|
||||
1090 | sleep(0.5) |
|
1148 | sleep(0.5) | |
1091 |
|
1149 | self.__handleError(procUnitConfObj) | ||
1092 | err = traceback.format_exception(sys.exc_info()[0], |
|
|||
1093 | sys.exc_info()[1], |
|
|||
1094 | sys.exc_info()[2]) |
|
|||
1095 |
|
||||
1096 | import socket |
|
|||
1097 |
|
||||
1098 | subject = "SChain v%s: Error running %s\n" %(schainpy.__version__, procUnitConfObj.name) |
|
|||
1099 |
|
||||
1100 | subtitle = "%s: %s\n" %(procUnitConfObj.getElementName() ,procUnitConfObj.name) |
|
|||
1101 | subtitle += "Hostname: %s\n" %socket.gethostbyname(socket.gethostname()) |
|
|||
1102 | subtitle += "Working directory: %s\n" %os.path.abspath("./") |
|
|||
1103 | subtitle += "Configuration file: %s\n" %self.filename |
|
|||
1104 |
|
||||
1105 | readUnitConfObj = self.getReadUnitObj() |
|
|||
1106 | if readUnitConfObj: |
|
|||
1107 | subtitle += "Data path: %s\n" %readUnitConfObj.path |
|
|||
1108 | subtitle += "Data type: %s\n" %readUnitConfObj.datatype |
|
|||
1109 | subtitle += "Start date: %s\n" %readUnitConfObj.startDate |
|
|||
1110 | subtitle += "End date: %s\n" %readUnitConfObj.endDate |
|
|||
1111 | subtitle += "Start time: %s\n" %readUnitConfObj.startTime |
|
|||
1112 | subtitle += "End time: %s\n" %readUnitConfObj.endTime |
|
|||
1113 |
|
||||
1114 | message = "".join(err) |
|
|||
1115 |
|
||||
1116 | sys.stderr.write(message) |
|
|||
1117 |
|
||||
1118 | adminObj = schainpy.admin.SchainNotify() |
|
|||
1119 | adminObj.sendAlert(message=message, |
|
|||
1120 | subject=subject, |
|
|||
1121 | subtitle=subtitle, |
|
|||
1122 | filename=self.filename) |
|
|||
1123 |
|
||||
1124 | is_ok = False |
|
1150 | is_ok = False | |
1125 |
|
||||
1126 | break |
|
1151 | break | |
1127 |
|
1152 | |||
1128 | #If every process unit finished so end process |
|
1153 | #If every process unit finished so end process | |
@@ -1142,8 +1167,11 class Project(): | |||||
1142 |
|
1167 | |||
1143 | def start(self, filename): |
|
1168 | def start(self, filename): | |
1144 |
|
1169 | |||
1145 | self.writeXml(filename) |
|
1170 | if not self.writeXml(filename): | |
1146 | self.readXml(filename) |
|
1171 | return | |
|
1172 | ||||
|
1173 | if not self.readXml(filename): | |||
|
1174 | return | |||
1147 |
|
1175 | |||
1148 | self.createObjects() |
|
1176 | self.createObjects() | |
1149 | self.connectObjects() |
|
1177 | self.connectObjects() |
@@ -4130,9 +4130,7 class BasicWindow(QMainWindow, Ui_BasicWindow): | |||||
4130 |
|
4130 | |||
4131 | return projectObjView |
|
4131 | return projectObjView | |
4132 |
|
4132 | |||
4133 | def createReadUnitView(self, projectObjView): |
|
4133 | def createReadUnitView(self, projectObjView, idReadUnit=None): | |
4134 |
|
||||
4135 | # project_name, description, datatype, data_path, startDate, endDate, startTime, endTime, online, delay, walk, set = self.getParmsFromProjectWindow() |
|
|||
4136 |
|
4134 | |||
4137 | projectParms = self.__getParmsFromProjectWindow() |
|
4135 | projectParms = self.__getParmsFromProjectWindow() | |
4138 |
|
4136 | |||
@@ -4140,7 +4138,8 class BasicWindow(QMainWindow, Ui_BasicWindow): | |||||
4140 | return None |
|
4138 | return None | |
4141 |
|
4139 | |||
4142 | if projectParms.datatype in ("Voltage", "Spectra", "Fits"): |
|
4140 | if projectParms.datatype in ("Voltage", "Spectra", "Fits"): | |
4143 |
readUnitConfObj = projectObjView.addReadUnit(d |
|
4141 | readUnitConfObj = projectObjView.addReadUnit(id=idReadUnit, | |
|
4142 | datatype=projectParms.datatype, | |||
4144 | path=projectParms.dpath, |
|
4143 | path=projectParms.dpath, | |
4145 | startDate=projectParms.startDate, |
|
4144 | startDate=projectParms.startDate, | |
4146 | endDate=projectParms.endDate, |
|
4145 | endDate=projectParms.endDate, | |
@@ -4162,7 +4161,8 class BasicWindow(QMainWindow, Ui_BasicWindow): | |||||
4162 | readUnitConfObj.addOperation(name="printInfo") |
|
4161 | readUnitConfObj.addOperation(name="printInfo") | |
4163 |
|
4162 | |||
4164 | if projectParms.datatype == "USRP": |
|
4163 | if projectParms.datatype == "USRP": | |
4165 |
readUnitConfObj = projectObjView.addReadUnit(d |
|
4164 | readUnitConfObj = projectObjView.addReadUnit(id=idReadUnit, | |
|
4165 | datatype=projectParms.datatype, | |||
4166 | path=projectParms.dpath, |
|
4166 | path=projectParms.dpath, | |
4167 | startDate=projectParms.startDate, |
|
4167 | startDate=projectParms.startDate, | |
4168 | endDate=projectParms.endDate, |
|
4168 | endDate=projectParms.endDate, | |
@@ -4179,50 +4179,10 class BasicWindow(QMainWindow, Ui_BasicWindow): | |||||
4179 |
|
4179 | |||
4180 | def updateReadUnitView(self, projectObjView, idReadUnit): |
|
4180 | def updateReadUnitView(self, projectObjView, idReadUnit): | |
4181 |
|
4181 | |||
4182 | # project_name, description, datatype, data_path, startDate, endDate, startTime, endTime, online, delay, walk , set = self.getParmsFromProjectWindow() |
|
4182 | projectObjView.removeProcUnit(idReadUnit) | |
4183 |
|
||||
4184 | readUnitConfObj = projectObjView.getProcUnitObj(idReadUnit) |
|
|||
4185 |
|
||||
4186 | projectParms = self.__getParmsFromProjectWindow() |
|
|||
4187 |
|
4183 | |||
4188 | if not projectParms.isValid(): |
|
4184 | readUnitConfObj = self.createReadUnitView(projectObjView, idReadUnit) | |
4189 | return None |
|
|||
4190 |
|
4185 | |||
4191 | if projectParms.datatype in ["Voltage", "Spectra", "Fits"]: |
|
|||
4192 | readUnitConfObj.update(datatype=projectParms.datatype, |
|
|||
4193 | path=projectParms.dpath, |
|
|||
4194 | startDate=projectParms.startDate, |
|
|||
4195 | endDate=projectParms.endDate, |
|
|||
4196 | startTime=projectParms.startTime, |
|
|||
4197 | endTime=projectParms.endTime, |
|
|||
4198 | online=projectParms.online, |
|
|||
4199 | walk=projectParms.walk |
|
|||
4200 | ) |
|
|||
4201 | if projectParms.set: |
|
|||
4202 | readUnitConfObj.addParameter(name="set", value=projectParms.set, format="int") |
|
|||
4203 |
|
||||
4204 | if projectParms.delay: |
|
|||
4205 | readUnitConfObj.addParameter(name="delay", value=projectParms.delay, format="int") |
|
|||
4206 |
|
||||
4207 | if projectParms.expLabel: |
|
|||
4208 | readUnitConfObj.addParameter(name="expLabel", value=projectParms.expLabel) |
|
|||
4209 |
|
||||
4210 | readUnitConfObj.addOperation(name="printInfo") |
|
|||
4211 |
|
||||
4212 | if projectParms.datatype == "USRP": |
|
|||
4213 | readUnitConfObj.update(datatype=projectParms.datatype, |
|
|||
4214 | path=projectParms.dpath, |
|
|||
4215 | startDate=projectParms.startDate, |
|
|||
4216 | endDate=projectParms.endDate, |
|
|||
4217 | startTime=projectParms.startTime, |
|
|||
4218 | endTime=projectParms.endTime, |
|
|||
4219 | online=projectParms.online, |
|
|||
4220 | ippKm=projectParms.ippKm |
|
|||
4221 | ) |
|
|||
4222 |
|
||||
4223 | if projectParms.delay: |
|
|||
4224 | readUnitConfObj.addParameter(name="delay", value=projectParms.delay, format="int") |
|
|||
4225 |
|
||||
4226 | return readUnitConfObj |
|
4186 | return readUnitConfObj | |
4227 |
|
4187 | |||
4228 | def createProcUnitView(self, projectObjView, datatype, inputId): |
|
4188 | def createProcUnitView(self, projectObjView, datatype, inputId): |
General Comments 0
You need to be logged in to leave comments.
Login now