def sendEmail(self, _strSubject, _strMessage): """Sends an email to the EDNA contact person (if configured).""" EDVerbose.DEBUG("EDPluginControlInterfaceToMXCuBEv1_2.sendEmail: Subject = %s" % _strSubject) EDVerbose.DEBUG("EDPluginControlInterfaceToMXCuBEv1_2.sendEmail: Message:") EDVerbose.DEBUG(_strMessage) if self.__strEDNAContactEmail == None: EDVerbose.DEBUG("EDPluginControlInterfaceToMXCuBEv1_2.sendEmail: No email address configured!") elif not EDUtilsPath.getEdnaSite().startswith("ESRF"): EDVerbose.DEBUG("EDPluginControlInterfaceToMXCuBEv1_2.sendEmail: Not executed at the ESRF! EDNA_SITE=%s" % EDUtilsPath.getEdnaSite()) else: try: EDVerbose.DEBUG("Sending message to %s." % self.__strEDNAContactEmail) EDVerbose.DEBUG("Message: %s" % _strMessage) strMessage = """ EDNA_HOME = %s EDNA_SITE = %s PLUGIN_NAME = %s working_dir = %s %s """ % (EDUtilsPath.getEdnaHome(), EDUtilsPath.getEdnaSite(), self.getPluginName(), self.getWorkingDirectory(), _strMessage) strEmailMsg = ("From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n%s" % (self.__strEDNAEmailSender, \ self.__strEDNAContactEmail, \ _strSubject, strMessage)) server = smtplib.SMTP("localhost") server.sendmail(self.__strEDNAEmailSender, self.__strEDNAContactEmail, strEmailMsg) server.quit() except: EDVerbose.DEBUG("Error when sending email message!") EDVerbose.writeErrorTrace()
def sendEmail(self, _strSubject, _strMessage): """Sends an email to the EDNA contact person (if configured).""" self.DEBUG("EDPluginControlInterfaceToMXCuBEv1_3.sendEmail: Subject = %s" % _strSubject) self.DEBUG("EDPluginControlInterfaceToMXCuBEv1_3.sendEmail: Message:") self.DEBUG(_strMessage) if self.strEDNAContactEmail == None: self.DEBUG("EDPluginControlInterfaceToMXCuBEv1_3.sendEmail: No email address configured!") elif not EDUtilsPath.getEdnaSite().startswith("ESRF"): self.DEBUG("EDPluginControlInterfaceToMXCuBEv1_3.sendEmail: Not executed at the ESRF! EDNA_SITE=%s" % EDUtilsPath.getEdnaSite()) else: try: self.DEBUG("Sending message to %s." % self.strEDNAContactEmail) self.DEBUG("Message: %s" % _strMessage) strMessage = """ EDNA_HOME = %s EDNA_SITE = %s PLUGIN_NAME = %s working_dir = %s %s """ % (EDUtilsPath.getEdnaHome(), EDUtilsPath.getEdnaSite(), self.getPluginName(), self.getWorkingDirectory(), _strMessage) strEmailMsg = ("From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n%s" % (self.strEDNAEmailSender, \ self.strEDNAContactEmail, \ _strSubject, strMessage)) server = smtplib.SMTP("localhost") server.sendmail(self.strEDNAEmailSender, self.strEDNAContactEmail, strEmailMsg) server.quit() except: self.ERROR("Error when sending email message!") self.writeErrorTrace()
def sendEmail(self, _strSubject, _strMessage): """Sends an email to the EDNA contact person (if configured).""" strTime = "%.1f s" % (self.tStop - self.tStart) if EDUtilsPath.isESRF(): strPathImage = None for dataSet in self.dataInput.dataSet: for imageFile in dataSet.imageFile: strPathImage = imageFile.path.value break if strPathImage is not None: (strBeamline, strProposal, strPrefix) = self.getBeamlineProposalFromPath(strPathImage) else: strBeamline = "Unknown" strProposal = "Unknown" strPrefix = "Unknown" strHost = socket.gethostname() strSubject = "EDNA ch %s %s %s %s %s (%s)" % (_strSubject, strBeamline, strProposal, strPrefix, strHost, strTime) else: strSubject = "EDNA %s : %s (%s)" % (_strSubject, EDUtilsPath.getEdnaSite(), strTime) self.DEBUG("EDPluginControlInterfaceToMXCuBEv1_4.sendEmail: Subject = %s" % strSubject) self.DEBUG("EDPluginControlInterfaceToMXCuBEv1_4.sendEmail: Message:") self.DEBUG(_strMessage) if self.strEDNAContactEmail == None: self.DEBUG("EDPluginControlInterfaceToMXCuBEv1_4.sendEmail: No email address configured!") elif not EDUtilsPath.getEdnaSite().startswith("ESRF"): self.DEBUG("EDPluginControlInterfaceToMXCuBEv1_4.sendEmail: Not executed at the ESRF! EDNA_SITE=%s" % EDUtilsPath.getEdnaSite()) else: try: self.DEBUG("Sending message to %s." % self.strEDNAContactEmail) self.DEBUG("Message: %s" % _strMessage) strMessage = "EDNA_HOME = %s\n" % EDUtilsPath.getEdnaHome() strMessage += "EDNA_SITE = %s\n" % EDUtilsPath.getEdnaSite() strMessage += "PLUGIN_NAME = %s\n" % self.getPluginName() strMessage += "working_dir = %s\n\n" % self.getWorkingDirectory() strMessage += "Reference images:\n" xsDataInputMXCuBE = self.getDataInput() for xsDataSetMXCuBE in xsDataInputMXCuBE.getDataSet(): for xsDataFile in xsDataSetMXCuBE.getImageFile(): strMessage += "%s\n" % xsDataFile.getPath().getValue() strMessage += "\n" strMessage += _strMessage strEmailMsg = ("From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n%s" % (self.strEDNAEmailSender, \ self.strEDNAContactEmail, \ strSubject, strMessage)) server = smtplib.SMTP("localhost") server.sendmail(self.strEDNAEmailSender, self.strEDNAContactEmail, strEmailMsg) server.quit() except: self.ERROR("Error when sending email message!") self.writeErrorTrace()
def getPathToProjectConfigurationFile(self, _strModuleName): """ This method returns the path to the Project configuration file. @param _strModuleName: Name of the module @type _strModuleName: python string @return: The path to the project configuration file @type: python string """ strPathToProjectConfigurationFile = None strCurrentDirectory = self.getModuleLocation(_strModuleName) bConfFileFound = False with self.locked(): while not bConfFileFound: strPreviousDirectory = strCurrentDirectory strCurrentDirectory = os.path.dirname(strCurrentDirectory) strPathToConfigurationDirectory = os.path.abspath(os.path.join(strCurrentDirectory, "conf")) strConfigurationFileName = "XSConfiguration_%s.xml" % EDUtilsPath.getEdnaSite() strPathToProjectConfigurationFile = os.path.abspath(os.path.join(strPathToConfigurationDirectory, \ strConfigurationFileName)) self.DEBUG("Looking for configuration file for %s in %s" % (_strModuleName, strPathToProjectConfigurationFile)) bConfFileFound = os.path.isfile(strPathToProjectConfigurationFile) if strCurrentDirectory in (EDUtilsPath.EDNA_HOME, strPreviousDirectory): strPathToProjectConfigurationFile = None break return strPathToProjectConfigurationFile
def createApplicationWorkingDirectory(self): """ Created the working directory of the application (<date>-<application name>) First tries to retrieve the base dir from --basedir option or related parameter from constructor Otherwise tries to retrieve it from EDNA_BASE_DIRECTORY environment variable Otherwise put the base dir as the current directory """ EDVerbose.DEBUG("EDApplication.createApplicationWorkingDirectory") strBaseDirectory = self.getBaseDir() strDateTime = time.strftime("%Y%m%d-%H%M%S", time.localtime(time.time())) self._strFullApplicationWorkingDirectory = os.path.join(strBaseDirectory, self._strWorkingDir) # Check that a folder / file with the same name already exists if(os.path.exists(self._strFullApplicationWorkingDirectory) or \ os.path.exists(self._strFullApplicationWorkingDirectory)): # It does exist so we have to modify the name of the working directory iIndex = 1 bContinueFlag = True while (bContinueFlag): self._strFullApplicationWorkingDirectory = os.path.join(strBaseDirectory, "%s_%d" % \ (strDateTime, \ iIndex)) if(os.path.isdir(self._strFullApplicationWorkingDirectory) or \ os.path.exists(self._strFullApplicationWorkingDirectory)): iIndex += 1 else: bContinueFlag = False # Add _nobackup suffix if run at the ESRF strEdnSite = EDUtilsPath.getEdnaSite() if EDUtilsPath.isESRF(): self._strFullApplicationWorkingDirectory += "_nobackup" # Make the directory os.mkdir(self._strFullApplicationWorkingDirectory) # Change it to be the current working directory os.chdir(self._strFullApplicationWorkingDirectory)
def preparePythonWrapperScript(self): listScript = ["#!%s" % sys.executable, ""] listScript += ["import os, sys, xmlrpclib"] listScript += [ """pyXmlrcplibProxy = xmlrpclib.ServerProxy('http://%s:%d')""" % (self.__edServerXMLRCP.getHost(), self.__edServerXMLRCP.getPort()) ] listScript += ["""os.chdir("%s")""" % self.getWorkingDirectory()] listScript += ["""os.environ['EDNA_HOME']="%s" """ % EDUtilsPath.getEdnaHome()] listScript += ["""os.environ['EDNA_SITE']="%s" """ % EDUtilsPath.getEdnaSite()] listScript += ["""sys.path.append(os.path.join(os.environ["EDNA_HOME"], "kernel", "src"))"""] listScript += ["""from EDFactoryPluginStatic import EDFactoryPluginStatic"""] listScript += ["""from EDUtilsFile import EDUtilsFile"""] listScript += ["""edPlugin = EDFactoryPluginStatic.loadPlugin("%s")""" % self.__strNameOfPlugin] for strValue in self.__dictXMLDataInput: if strValue == self.getDefaultInputDataKey(): listScript += ['edPlugin.setDataInput("""%s""")' "" % self.__dictXMLDataInput[strValue]] else: listScript += ['edPlugin.setDataInput("""%s""", "%s")' % (self.__dictXMLDataInput[strValue], strValue)] listScript += ["""def actionSuccessFile(_edPlugin=None):"""] listScript += [""" strSuccessMessage = "" """] listScript += [""" for strKey in _edPlugin.getListOfDataOutputKeys():"""] listScript += [""" if strKey == _edPlugin.getDefaultOutputDataKey():"""] listScript += [""" strXMLOutput = _edPlugin.getDataOutput().marshal()"""] listScript += [""" strSuccessMessage += strKey + "\\n" """] listScript += [ """ EDUtilsFile.writeFile(os.path.join("%s", "XSDataResult_"+strKey+".xml"), strXMLOutput)""" % self.getWorkingDirectory() ] listScript += [""" else:"""] listScript += [""" iIndex = 1"""] listScript += [""" for xsDataResult in _edPlugin.getDataOutput(strKey):"""] listScript += [""" strXMLOutput = xsDataResult.marshal()"""] listScript += [""" strSuccessMessage += "%s_%d\\n" % (strKey, iIndex) """] listScript += [ """ EDUtilsFile.writeFile(os.path.join("%s", "XSDataResult_"+strKey+"_%%d.xml") %% iIndex, strXMLOutput)""" % self.getWorkingDirectory() ] listScript += [""" """] listScript += [ """ EDUtilsFile.writeFile(os.path.join("%s", "SUCCESS.txt"), strSuccessMessage)""" % self.getWorkingDirectory() ] listScript += ["""def actionSuccessXMLRCP(_edPlugin=None):"""] listScript += [""" pyXmlrcplibProxy.callbackSUCCESS("%d", [])""" % self.getId()] listScript += [""" for strKey in _edPlugin.getListOfDataOutputKeys():"""] listScript += [""" strXMLOutput = _edPlugin.getDataOutput().marshal()"""] listScript += [""" pyXmlrcplibProxy.setDataOutput("%d", strXMLOutput)""" % self.getId()] listScript += ["""def actionFailure(_edObject=None):"""] listScript += [""" pyXmlrcplibProxy.callbackFAILURE("%d", [])""" % self.getId()] listScript += ["""#edPlugin.connectSUCCESS(actionSuccessFile)"""] listScript += ["""edPlugin.connectSUCCESS(actionSuccessXMLRCP)"""] listScript += ["""edPlugin.connectFAILURE(actionFailure)"""] listScript += ["""edPlugin.executeSynchronous()"""] listScript += [""] listScript += [""] strPythonWrapper = "" for strLine in listScript: strPythonWrapper = strPythonWrapper + strLine + "\n" return strPythonWrapper
def doFailureActionISPyB(self, _edPlugin=None): self.DEBUG("EDPluginControlInterfaceToMXCuBEv1_3.doFailureActionISpyB...") self.retrieveFailureMessages(self.edPluginControlISPyB, "EDPluginControlInterfaceToMXCuBEv1_3.doFailureActionISpyB") # Send failure email message (MXSUP-183): strSubject = "%s : FAILURE!" % EDUtilsPath.getEdnaSite() strMessage = "ISPyB FAILURE!" self.sendEmail(strSubject, strMessage)
def doFailureActionInterface(self, _edPlugin=None): self.DEBUG( "EDPluginControlInterfaceToMXCuBEv1_3.doFailureActionInterface...") # Send failure email message (MXSUP-183): strSubject = "%s : FAILURE!" % EDUtilsPath.getEdnaSite() strMessage = "Characterisation FAILURE!" self.storeResultsInISPyB(strSubject, strMessage)
def doSuccessActionInterface(self, _edPlugin=None): self.DEBUG("EDPluginControlInterfaceToMXCuBEv1_3.doSuccessActionInterface...") self.retrieveSuccessMessages(self.edPluginControlInterface, "EDPluginControlInterfaceToMXCuBEv1_3.doSuccessActionInterface") # Send success email message (MXSUP-183): self.tStop = time.time() strSubject = "%s : SUCCESS! (%.1f s)" % (EDUtilsPath.getEdnaSite(), self.tStop - self.tStart) strMessage = "Characterisation success!" self.storeResultsInISPyB(strSubject, strMessage)
def doSuccessActionInterface(self, _edPlugin=None): self.DEBUG("EDPluginControlInterfaceToMXCuBEv1_3.doSuccessActionInterface...") self.retrieveSuccessMessages(self.edPluginControlInterface, "EDPluginControlInterfaceToMXCuBEv1_3.doSuccessActionInterface") xsDataResultCharacterisation = self.edPluginControlInterface.getDataOutput().getResultCharacterisation() self.xsDataResultMXCuBE.setCharacterisationResult(xsDataResultCharacterisation) xsDataResultControlISPyB = self.edPluginControlInterface.getDataOutput().getResultControlISPyB() if xsDataResultControlISPyB != None: self.xsDataResultMXCuBE.setScreeningId(xsDataResultControlISPyB.getScreeningId()) if xsDataResultCharacterisation != None: strPathCharacterisationResult = os.path.join(self.getWorkingDirectory(), "CharacterisationResult.xml") xsDataResultCharacterisation.exportToFile(strPathCharacterisationResult) self.xsDataResultMXCuBE.setListOfOutputFiles(XSDataString(strPathCharacterisationResult)) # For the moment, create "DNA" style output directory strPathToDNAFileDirectory = self.createDNAFileDirectoryPath(xsDataResultCharacterisation) xsDataDictionaryLogFile = None if (self.createDNAFileDirectory(strPathToDNAFileDirectory)): xsDataDictionaryLogFile = self.createOutputFileDictionary(xsDataResultCharacterisation, strPathToDNAFileDirectory) strPyArchPathToDNAFileDirectory = self.createPyArchDNAFilePath(strPathToDNAFileDirectory) if (self.createDNAFileDirectory(strPyArchPathToDNAFileDirectory)): xsDataDictionaryLogFile = self.createOutputFileDictionary(xsDataResultCharacterisation, strPyArchPathToDNAFileDirectory) self.xsDataResultMXCuBE.setOutputFileDictionary(xsDataDictionaryLogFile) # Send success email message (MXSUP-183): self.tStop = time.time() strSubject = "%s : SUCCESS! (%.1f s)" % (EDUtilsPath.getEdnaSite(), self.tStop-self.tStart) strMessage = "Characterisation success!" if xsDataResultCharacterisation.getStatusMessage(): strMessage += "\n\n" strMessage += xsDataResultCharacterisation.getStatusMessage().getValue() if xsDataResultCharacterisation.getShortSummary(): strMessage += "\n\n" strMessage += xsDataResultCharacterisation.getShortSummary().getValue() self.sendEmail(strSubject, strMessage) # Fix for bug EDNA-55 : If burning strategy EDNA2html shouldn't be run bRunExecOutputHTML = False xsDataInputMXCuBE = self.getDataInput() xsDataDiffractionPlan = xsDataInputMXCuBE.getDiffractionPlan() if xsDataDiffractionPlan.getStrategyOption() is not None: strStrategyOption = xsDataDiffractionPlan.getStrategyOption().getValue() if strStrategyOption.find("-DamPar") != -1: bRunExecOutputHTML = False if (self.edPluginExecOutputHTML is not None) and bRunExecOutputHTML: self.edPluginExecOutputHTML.setDataInput(XSDataFile(XSDataString(strPathToDNAFileDirectory)), "dnaFileDirectory") self.edPluginExecOutputHTML.execute() # Fix for bug MXSUP-251: Put the BEST .par file in the EDNA characterisation root directory xsDataIntegrationResult = xsDataResultCharacterisation.getIntegrationResult() if xsDataIntegrationResult: listXSDataIntegrationSubWedgeResult = xsDataIntegrationResult.getIntegrationSubWedgeResult() if listXSDataIntegrationSubWedgeResult: if listXSDataIntegrationSubWedgeResult != []: strBestfilePar = listXSDataIntegrationSubWedgeResult[0].getBestfilePar().getValue() # Put the file one directory above the mxCuBE v1.3 plugin working directory: strDir = os.path.dirname(self.getWorkingDirectory()) strPath = os.path.join(strDir, "bestfile.par") EDUtilsFile.writeFile(strPath, strBestfilePar) # Execute plugin which creates a simple HTML page self.executeSimpleHTML(xsDataResultCharacterisation)
def doFailureActionCCP4i(self, _edPlugin=None): EDVerbose.DEBUG("EDPluginControlInterfaceToMXCuBEv1_2.doFailureActionCCP4i...") self.setFailure() xsDataResultMXCuBE = XSDataResultMXCuBE() self.setDataOutput(xsDataResultMXCuBE) self.writeDataOutput() # Send failure email message (MXSUP-183): strSubject = "%s : FAILURE!" % EDUtilsPath.getEdnaSite() strMessage = "CCP4I FAILURE!" self.sendEmail(strSubject, strMessage)
def doFailureActionCharacterisation(self, _edPlugin=None): """ retrieve the potential warning messages retrieve the potential error messages """ EDVerbose.DEBUG("EDPluginControlInterfaceToMXCuBEv1_2.doFailureActionCharacterisation") # Send failure email message (MXSUP-183): strSubject = "%s : FAILURE!" % EDUtilsPath.getEdnaSite() strMessage = "Characterisation FAILURE!" self.sendEmail(strSubject, strMessage)
def doSuccessActionCCP4i(self, _edPlugin=None): EDVerbose.DEBUG("EDPluginControlInterfaceToMXCuBEv1_2.doSuccessActionCCP4i...") self.retrieveSuccessMessages(self.__edPluginControlCCP4i, "EDPluginControlInterfaceToMXCuBEv1_2.doSuccessActionCCP4i") # Retrieve the results from the CCP4 plugin execution xsDataResultCCP4i = self.__edPluginControlCCP4i.getDataOutput() self.__xsDataResultMXCuBE = XSDataResultMXCuBE() xsDataStringListOfOutputFiles = xsDataResultCCP4i.getListOfOutputFiles() self.__xsDataResultMXCuBE.setListOfOutputFiles(xsDataStringListOfOutputFiles) # Retrieve the characterisation output object xsDataResultCharacterisation = self.getXSDataResultCharacterisation(xsDataStringListOfOutputFiles.getValue()) # For the moment, create "DNA" style output directory strPathToDNAFileDirectory = self.createDNAFileDirectoryPath(xsDataResultCharacterisation) xsDataDictionaryLogFile = None if (self.createDNAFileDirectory(strPathToDNAFileDirectory)): xsDataDictionaryLogFile = self.createOutputFileDictionary(xsDataStringListOfOutputFiles, xsDataResultCharacterisation, strPathToDNAFileDirectory) strPyArchPathToDNAFileDirectory = self.createPyArchDNAFilePath(strPathToDNAFileDirectory) if (self.createDNAFileDirectory(strPyArchPathToDNAFileDirectory)): xsDataDictionaryLogFile = self.createOutputFileDictionary(xsDataStringListOfOutputFiles, xsDataResultCharacterisation, strPyArchPathToDNAFileDirectory) self.__xsDataResultMXCuBE.setOutputFileDictionary(xsDataDictionaryLogFile) # Send success email message (MXSUP-183): strSubject = "%s : SUCCESS!" % EDUtilsPath.getEdnaSite() strMessage = "Success!" if xsDataDictionaryLogFile != None: for xsDataKeyValuePair in xsDataDictionaryLogFile.getKeyValuePair(): strKey = xsDataKeyValuePair.getKey().getValue() if strKey == "executiveSummary": strPathToExecutiveSummary = xsDataKeyValuePair.getValue().getValue() strMessage = EDUtilsFile.readFile(strPathToExecutiveSummary) self.sendEmail(strSubject, strMessage) # Fix for bug EDNA-55 : If burning strategy EDNA2html shouldn't be run bRunExecOutputHTML = True xsDataInputMXCuBE = self.getDataInput() xsDataDiffractionPlan = xsDataInputMXCuBE.getDiffractionPlan() if xsDataDiffractionPlan.getStrategyOption() is not None: strStrategyOption = xsDataDiffractionPlan.getStrategyOption().getValue() if strStrategyOption.find("-DamPar") != -1: bRunExecOutputHTML = False if (self.__edPluginExecOutputHTML is not None) and bRunExecOutputHTML: self.__edPluginExecOutputHTML.executeSynchronous() if not self.__edPluginExecOutputHTML.isFailure() and self.__edPluginExecOutputHTML.hasDataOutput("htmlFile"): strPathToHTMLFile = self.__edPluginExecOutputHTML.getDataOutput("htmlFile")[0].getPath().getValue() strPathToHTMLDir = self.__edPluginExecOutputHTML.getDataOutput("htmlDir")[0].getPath().getValue() strPathToDNAIndexDirectory = os.path.join(strPathToDNAFileDirectory, "index") if os.path.exists(strPathToHTMLFile): try: os.mkdir(strPathToDNAIndexDirectory) shutil.copy(strPathToHTMLFile, os.path.join(strPathToDNAIndexDirectory, "index.html")) shutil.copytree(strPathToHTMLDir, os.path.join(strPathToDNAIndexDirectory, os.path.basename(strPathToHTMLDir))) if strPyArchPathToDNAFileDirectory is not None: strPathToPyArchIndexDirectory = os.path.join(strPyArchPathToDNAFileDirectory, "index") os.mkdir(strPathToPyArchIndexDirectory) shutil.copy(strPathToHTMLFile, os.path.join(strPathToPyArchIndexDirectory, "index.html")) shutil.copytree(strPathToHTMLDir, os.path.join(strPathToPyArchIndexDirectory, os.path.basename(strPathToHTMLDir))) except Exception, e: EDVerbose.DEBUG("Exception caught: %r" % e)
def doSuccessActionInterface(self, _edPlugin=None): self.DEBUG( "EDPluginControlInterfaceToMXCuBEv1_3.doSuccessActionInterface...") self.retrieveSuccessMessages( self.edPluginControlInterface, "EDPluginControlInterfaceToMXCuBEv1_3.doSuccessActionInterface") # Send success email message (MXSUP-183): self.tStop = time.time() strSubject = "%s : SUCCESS! (%.1f s)" % (EDUtilsPath.getEdnaSite(), self.tStop - self.tStart) strMessage = "Characterisation success!" self.storeResultsInISPyB(strSubject, strMessage)
def process(self, _edObject=None): EDPluginControl.process(self) self.DEBUG("EDPluginControlMXCuBEWrapperv1_3.process") # Check that if image path contains RAW_DATA the current working directory should be PROCESSED_DATA strTimeString = time.strftime( "%Y%m%d-%H%M%S", time.localtime( time.time())) + "-%06d" % random.randint(0, 1000000) strWorkingDir = self.getWorkingDirectory() strProcessedDataDir = strWorkingDir strFirstImagePath = None for dataSet in self.dataInput.dataSet: for imageFile in dataSet.imageFile: strFirstImagePath = imageFile.path.value break if strFirstImagePath.find("RAW_DATA") != -1: strCurrentWorkingDirectory = os.getcwd() strCurrentProcessedDataDir = os.path.dirname( strCurrentWorkingDirectory) strProcessedDataDir = os.path.dirname( string.replace(strFirstImagePath, "RAW_DATA", "PROCESSED_DATA")) if strCurrentProcessedDataDir != strProcessedDataDir: strEDAppliDir = "EDApplication_" + strTimeString strNewLogFileName = os.path.join(strProcessedDataDir, strEDAppliDir + ".log") strWorkingDir = os.path.join(strProcessedDataDir, strEDAppliDir, self.getBaseName()) if not os.path.exists(strWorkingDir): os.makedirs(strWorkingDir, 0o755) # Write out input XML file strPathToInputFile = os.path.join(strProcessedDataDir, "EDNA_Input_%s.xml" % strTimeString) strPathToOutputFile = os.path.join( strProcessedDataDir, "EDNA_Output_%s.xml" % strTimeString) EDUtilsFile.writeFile(strPathToInputFile, self.getDataInput().marshal()) strScript = "export EDNA_SITE=%s\n" % EDUtilsPath.getEdnaSite() strScript += "/opt/pxsoft/bin/edna-plugin-launcher" strScript += " --execute %s" % self.strMXCuBEPlugin strScript += " --inputFile %s" % strPathToInputFile strScript += " --outputFile %s" % strPathToOutputFile strScript += " --basedir %s" % strProcessedDataDir strScript += " 2>&1\n" strScriptFileName = "edna_start_%s.sh" % strTimeString strScriptPath = os.path.join(strProcessedDataDir, strScriptFileName) EDUtilsFile.writeFile(strScriptPath, strScript) # TODO: Make the script executable os.system("bash %s" % strScriptPath) xsDataResultMXCuBE = XSDataResultMXCuBE() if os.path.exists(strPathToOutputFile): strOutput = EDUtilsFile.readFile(strPathToOutputFile) xsDataResultMXCuBE = XSDataResultMXCuBE.parseString(strOutput) self.setDataOutput(xsDataResultMXCuBE)
def __init__(self, _edStringTestName=None): EDTestCasePluginExecute.__init__(self, "EDPluginControlInterfacev1_3") self.setRequiredPluginConfiguration("EDPluginMOSFLMIndexingv10") self.setRequiredPluginConfiguration("EDPluginMOSFLMIntegrationv10") self.setRequiredPluginConfiguration("EDPluginMOSFLMGeneratePredictionv10") self.setRequiredPluginConfiguration("EDPluginBestv1_2") self.setRequiredPluginConfiguration("EDPluginRaddosev10") self.setConfigurationFile(self.getRefConfigFile()) if EDUtilsPath.getEdnaSite().startswith("ESRF"): self.setDataInputFile(os.path.join(self.getPluginTestsDataHome(), "XSDataInputInterface_ESRF.xml")) else: self.setDataInputFile(os.path.join(self.getPluginTestsDataHome(), "XSDataInputInterface_reference.xml"))
def preProcess(self): EDTestCasePluginExecute.preProcess(self) strImageName1 = "ref-testscale_1_001.img" strImageName2 = "ref-testscale_1_002.img" self.loadTestImage([ strImageName1, strImageName2 ]) edPlugin = self.getPlugin() edPlugin.setDataInput(XSDataString(os.path.join(self.getTestsDataImagesHome(), strImageName1)), "imagePaths") edPlugin.setDataInput(XSDataString(os.path.join(self.getTestsDataImagesHome(), strImageName2)), "imagePaths") if EDUtilsPath.getEdnaSite().startswith("ESRF"): edPlugin.setDataInput(XSDataInteger(772751), "dataCollectionId") else: edPlugin.setDataInput(XSDataInteger(1), "dataCollectionId") edPlugin.setDataInput(XSDataString("EDNA test characterisation"), "comments") edPlugin.setDataInput(XSDataString("Test"), "shortComments")
def preProcess(self): EDTestCasePluginExecute.preProcess(self) strImageName1 = "ref-testscale_1_001.img" strImageName2 = "ref-testscale_1_002.img" self.loadTestImage([strImageName1, strImageName2]) edPlugin = self.getPlugin() edPlugin.setDataInput(XSDataString(os.path.join(self.getTestsDataImagesHome(), strImageName1)), "imagePaths") edPlugin.setDataInput(XSDataString(os.path.join(self.getTestsDataImagesHome(), strImageName2)), "imagePaths") if EDUtilsPath.getEdnaSite().startswith("ESRF"): edPlugin.setDataInput(XSDataInteger(772751), "dataCollectionId") else: edPlugin.setDataInput(XSDataInteger(1), "dataCollectionId") edPlugin.setDataInput(XSDataString("EDNA test characterisation"), "comments") edPlugin.setDataInput(XSDataString("Test"), "shortComments")
def process(self, _edObject=None): EDPluginControl.process(self) self.DEBUG("EDPluginControlMXCuBEWrapperv1_3.process") # Check that if image path contains RAW_DATA the current working directory should be PROCESSED_DATA strTimeString = time.strftime("%Y%m%d-%H%M%S", time.localtime(time.time())) + "-%06d" % random.randint( 0, 1000000 ) strWorkingDir = self.getWorkingDirectory() strProcessedDataDir = strWorkingDir strFirstImagePath = None for dataSet in self.dataInput.dataSet: for imageFile in dataSet.imageFile: strFirstImagePath = imageFile.path.value break if strFirstImagePath.find("RAW_DATA") != -1: strCurrentWorkingDirectory = os.getcwd() strCurrentProcessedDataDir = os.path.dirname(strCurrentWorkingDirectory) strProcessedDataDir = os.path.dirname(string.replace(strFirstImagePath, "RAW_DATA", "PROCESSED_DATA")) if strCurrentProcessedDataDir != strProcessedDataDir: strEDAppliDir = "EDApplication_" + strTimeString strNewLogFileName = os.path.join(strProcessedDataDir, strEDAppliDir + ".log") strWorkingDir = os.path.join(strProcessedDataDir, strEDAppliDir, self.getBaseName()) if not os.path.exists(strWorkingDir): os.makedirs(strWorkingDir, 0755) # Write out input XML file strPathToInputFile = os.path.join(strProcessedDataDir, "EDNA_Input_%s.xml" % strTimeString) strPathToOutputFile = os.path.join(strProcessedDataDir, "EDNA_Output_%s.xml" % strTimeString) EDUtilsFile.writeFile(strPathToInputFile, self.getDataInput().marshal()) strScript = "export EDNA_SITE=%s\n" % EDUtilsPath.getEdnaSite() strScript += "/opt/pxsoft/bin/edna-plugin-launcher" strScript += " --execute %s" % self.strMXCuBEPlugin strScript += " --inputFile %s" % strPathToInputFile strScript += " --outputFile %s" % strPathToOutputFile strScript += " --basedir %s" % strProcessedDataDir strScript += " 2>&1\n" strScriptFileName = "edna_start_%s.sh" % strTimeString strScriptPath = os.path.join(strProcessedDataDir, strScriptFileName) EDUtilsFile.writeFile(strScriptPath, strScript) # TODO: Make the script executable os.system("bash %s" % strScriptPath) xsDataResultMXCuBE = XSDataResultMXCuBE() if os.path.exists(strPathToOutputFile): strOutput = EDUtilsFile.readFile(strPathToOutputFile) xsDataResultMXCuBE = XSDataResultMXCuBE.parseString(strOutput) self.setDataOutput(xsDataResultMXCuBE)
def doFailureActionInterface(self, _edPlugin=None): self.DEBUG("EDPluginControlInterfaceToMXCuBEv1_3.doFailureActionInterface...") self.setFailure() xsDataResultCharacterisation = None if self.edPluginControlInterface.hasDataOutput("characterisation"): xsDataResultCharacterisation = self.edPluginControlInterface.getDataOutput("characterisation")[0] # Execute plugin which creates a simple HTML page self.executeSimpleHTML(xsDataResultCharacterisation) # Send failure email message (MXSUP-183): strSubject = "%s : FAILURE!" % EDUtilsPath.getEdnaSite() strMessage = "Interface FAILURE!" if self.edPluginControlInterface.hasDataOutput("characterisation"): xsDataResultCharacterisation = self.edPluginControlInterface.getDataOutput("characterisation")[0] if xsDataResultCharacterisation.getStatusMessage(): strMessage += "\n\n" strMessage += xsDataResultCharacterisation.getStatusMessage().getValue() if xsDataResultCharacterisation.getShortSummary(): strMessage += "\n\n" strMessage += xsDataResultCharacterisation.getShortSummary().getValue() self.sendEmail(strSubject, strMessage)
def __init__(self, _strPluginName, _strPluginDir=None, _strTestName=None): """ Initialise the Plugin Execution test - Edna site - Configuration files - Data input file - Plugin launcher """ EDTestCasePlugin.__init__(self, _strPluginName, _strPluginDir, _strTestName) self.__edPlugin = None self.__strEdnaSite = EDUtilsPath.getEdnaSite() self.__strRefConfigFile = None self.__dictStrDataInputFiles = {} self.__strDefaultInputDataKey = "defaultInputData" self.__dictStrReferenceDataOutputFiles = {} self.__strDefaultOutputDataKey = "defaultOutputData" self.__iNoExpectedErrorMessages = 0 self.__iNoExpectedWarningMessages = 0 self.__bAcceptPluginFailure = False # Deprecated! self.m_edObtainedOutputDataFile = None EDUtilsParallel.uninitializeNbThread()
def doFailureActionInterface(self, _edPlugin=None): self.DEBUG("EDPluginControlInterfaceToMXCuBEv1_3.doFailureActionInterface...") # Send failure email message (MXSUP-183): strSubject = "%s : FAILURE!" % EDUtilsPath.getEdnaSite() strMessage = "Characterisation FAILURE!" self.storeResultsInISPyB(strSubject, strMessage)
def __init__(self, _strTestName=None): EDTestCase.__init__(self, "EDTestCaseEDConfiguration") strKernelDataHome = EDUtilsTest.getPluginTestDataDirectory(self.getClassName()) strDataDir = "EDConfiguration" self.strDataPath = EDUtilsPath.mergePath(strKernelDataHome, strDataDir) self.strEdnaSiteOrig = EDUtilsPath.getEdnaSite()
def doSuccessActionInterface(self, _edPlugin=None): self.DEBUG("EDPluginControlInterfaceToMXCuBEv1_3.doSuccessActionInterface...") self.retrieveSuccessMessages(self.edPluginControlInterface, "EDPluginControlInterfaceToMXCuBEv1_3.doSuccessActionInterface") if self.edPluginControlInterface.hasDataOutput("characterisation"): xsDataResultCharacterisation = self.edPluginControlInterface.getDataOutput("characterisation")[0] self.xsDataResultMXCuBE.setCharacterisationResult(xsDataResultCharacterisation) strPathCharacterisationResult = os.path.join(self.getWorkingDirectory(), "CharacterisationResult.xml") xsDataResultCharacterisation.outputFile(strPathCharacterisationResult) self.xsDataResultMXCuBE.setListOfOutputFiles(XSDataString(strPathCharacterisationResult)) # For the moment, create "DNA" style output directory strPathToDNAFileDirectory = self.createDNAFileDirectoryPath(xsDataResultCharacterisation) xsDataDictionaryLogFile = None if (self.createDNAFileDirectory(strPathToDNAFileDirectory)): xsDataDictionaryLogFile = self.createOutputFileDictionary(xsDataResultCharacterisation, strPathToDNAFileDirectory) strPyArchPathToDNAFileDirectory = self.createPyArchDNAFilePath(strPathToDNAFileDirectory) if (self.createDNAFileDirectory(strPyArchPathToDNAFileDirectory)): xsDataDictionaryLogFile = self.createOutputFileDictionary(xsDataResultCharacterisation, strPyArchPathToDNAFileDirectory) self.xsDataResultMXCuBE.setOutputFileDictionary(xsDataDictionaryLogFile) # Send success email message (MXSUP-183): self.tStop = time.time() strSubject = "%s : SUCCESS! (%.1f s)" % (EDUtilsPath.getEdnaSite(), self.tStop-self.tStart) strMessage = "Characterisation success!" if xsDataResultCharacterisation.getStatusMessage(): strMessage += "\n\n" strMessage += xsDataResultCharacterisation.getStatusMessage().getValue() if xsDataResultCharacterisation.getShortSummary(): strMessage += "\n\n" strMessage += xsDataResultCharacterisation.getShortSummary().getValue() self.sendEmail(strSubject, strMessage) # Fix for bug EDNA-55 : If burning strategy EDNA2html shouldn't be run bRunExecOutputHTML = True xsDataInputMXCuBE = self.getDataInput() xsDataDiffractionPlan = xsDataInputMXCuBE.getDiffractionPlan() if xsDataDiffractionPlan.getStrategyOption() is not None: strStrategyOption = xsDataDiffractionPlan.getStrategyOption().getValue() if strStrategyOption.find("-DamPar") != -1: bRunExecOutputHTML = False if (self.edPluginExecOutputHTML is not None) and bRunExecOutputHTML: self.edPluginExecOutputHTML.executeSynchronous() if not self.edPluginExecOutputHTML.isFailure() and self.edPluginExecOutputHTML.hasDataOutput("htmlFile"): strPathToHTMLFile = self.edPluginExecOutputHTML.getDataOutput("htmlFile")[0].getPath().getValue() strPathToHTMLDir = self.edPluginExecOutputHTML.getDataOutput("htmlDir")[0].getPath().getValue() strPathToDNAIndexDirectory = os.path.join(strPathToDNAFileDirectory, "index") if os.path.exists(strPathToHTMLFile): try: os.mkdir(strPathToDNAIndexDirectory) shutil.copy(strPathToHTMLFile, os.path.join(strPathToDNAIndexDirectory, "index.html")) shutil.copytree(strPathToHTMLDir, os.path.join(strPathToDNAIndexDirectory, os.path.basename(strPathToHTMLDir))) if strPyArchPathToDNAFileDirectory is not None: strPathToPyArchIndexDirectory = os.path.join(strPyArchPathToDNAFileDirectory, "index") os.mkdir(strPathToPyArchIndexDirectory) shutil.copy(strPathToHTMLFile, os.path.join(strPathToPyArchIndexDirectory, "index.html")) shutil.copytree(strPathToHTMLDir, os.path.join(strPathToPyArchIndexDirectory, os.path.basename(strPathToHTMLDir))) except Exception, e: self.DEBUG("Exception caught: %r" % e) # Fix for bug MXSUP-251: Put the BEST .par file in the EDNA characterisation root directory xsDataIntegrationResult = xsDataResultCharacterisation.getIntegrationResult() if xsDataIntegrationResult: listXSDataIntegrationSubWedgeResult = xsDataIntegrationResult.getIntegrationSubWedgeResult() if listXSDataIntegrationSubWedgeResult: if listXSDataIntegrationSubWedgeResult != []: strBestfilePar = listXSDataIntegrationSubWedgeResult[0].getBestfilePar().getValue() # Put the file one directory above the mxCuBE v1.3 plugin working directory: strDir = os.path.dirname(self.getWorkingDirectory()) strPath = os.path.join(strDir, "bestfile.par") EDUtilsFile.writeFile(strPath, strBestfilePar) # Execute plugin which creates a simple HTML page self.executeSimpleHTML(xsDataResultCharacterisation)
def preProcess(self): """ Creates the application working directory (log dir) Initializes the configuration retrieves the plugin xml data to be passed to the plugin """ EDVerbose.DEBUG("EDApplication.preProcess") self.processCommandline() if (not self.__bIsFailure): # Check that the plugin can be located strPluginLocation = EDFactoryPluginStatic.getFactoryPlugin().getModuleLocation(self.__strPluginName) if (strPluginLocation is None): EDVerbose.error("Plugin %s cannot be loaded!" % self.__strPluginName) self.__bIsFailure = True # Check that the input file can be read if (self.getDataInputFilePath() is not None) and (not os.path.exists(self.__strDataInputFilePath)): EDVerbose.error("Input XML file not found : %s" % self.__strDataInputFilePath) self.__bIsFailure = True # Check that the output file can be created if (self.__strDataOutputFilePath is not None): strOutputDirectory = os.path.dirname(self.__strDataOutputFilePath) if (strOutputDirectory is None or strOutputDirectory == ""): strOutputDirectory = os.getcwd() self.__strDataOutputFilePath = os.path.join(strOutputDirectory, self.__strDataOutputFilePath) if (not os.access(strOutputDirectory, os.W_OK)): EDVerbose.error("Output directory not writable: %s" % strOutputDirectory) self.__bIsFailure = True elif (os.path.exists(self.__strDataOutputFilePath)): if (not os.access(self.__strDataOutputFilePath, os.W_OK)): EDVerbose.error("Output file not writable: %s" % self.__strDataOutputFilePath) self.__bIsFailure = True if (not self.__bIsFailure): EDVerbose.DEBUG("EDApplication.PLUGIN_PARAM_LABEL: " + EDApplication.PLUGIN_PARAM_LABEL) # Load the configuration file if(self.__strConfigurationFileName is None): self.__strConfigurationHome = EDApplication.getConfigurationHome(self.__strPluginName) self.__strConfigurationFileName = os.path.abspath(os.path.join(self.__strConfigurationHome, "XSConfiguration_%s.xml" % EDUtilsPath.getEdnaSite())) if (os.path.exists(self.__strConfigurationFileName)): EDVerbose.screen("Loading Configuration file: %s" % self.__strConfigurationFileName) edConfiguration = EDConfiguration(self.__strConfigurationFileName) self.setConfiguration(edConfiguration) self.loadConfiguration() EDVerbose.DEBUG("EDApplication.preProcess: Checking... Number of plugins...: %d" % EDApplication.__edConfiguration.getPluginListSize()) pyDictionary = {} pyDictionary[ "${EDNA_HOME}" ] = EDUtilsPath.getEdnaHome() if self.getDataInputFilePath() is not None: self.__strXMLData = EDUtilsFile.readFileAndParseVariables(self.getDataInputFilePath(), pyDictionary) else: EDVerbose.warning("Cannot find configuration file: %s" % self.__strConfigurationFileName) # Create the application working directory if(self.__strWorkingDir is None): self.__strWorkingDir = self.__strApplicationInstanceName self.createApplicationWorkingDirectory()