def decode_archive(): try: print 'decoding archive...' encoded_archive_bytes = FileUtils.readFileToByteArray( File(node_archive_path)) decoded_archive_bytes = Base64.getMimeDecoder().decode( encoded_archive_bytes) FileUtils.writeByteArrayToFile(File(archive_name), decoded_archive_bytes) print 'successfully decoded archive' except: print 'Decoding application archive failed' print dumpStack() apply(traceback.print_exception, sys.exc_info()) exit(exitcode=1)
def processExperiment(self, experimentNode): """Register an IExperimentUpdatable based on the Experiment XML node. @param experimentNode An XML node corresponding to an Experiment @return IExperimentUpdatable experiment """ # Get the experiment version expVersion = experimentNode.attrib.get("version") if expVersion is None: expVersion = "0" # Get the openBIS identifier openBISIdentifier = experimentNode.attrib.get("openBISIdentifier") # Get the experiment name expName = experimentNode.attrib.get("name") # Get the experiment date and reformat it to be compatible # with postgreSQL expDate = self.formatExpDateForPostgreSQL(experimentNode.attrib.get("date")) # Get the description description = experimentNode.attrib.get("description") # Get the acquisition hardware acqHardware = experimentNode.attrib.get("acq_hardware") # Get the acquisition software acqSoftware = experimentNode.attrib.get("acq_software") # Get the owner name owner = experimentNode.attrib.get("owner_name") # Get attachments attachments = experimentNode.attrib.get("attachments") # Create the experiment (with corrected ID if needed: see above) openBISExperiment = self.createExperiment(openBISIdentifier, expName) if not openBISExperiment: msg = "Could not create experiment " + openBISIdentifier self._logger.error(msg) raise Exception(msg) # Get comma-separated tag list tagList = experimentNode.attrib.get("tags") if tagList != None and tagList != "": # Retrieve or create the tags openBISTags = self.retrieveOrCreateTags(tagList) # Set the metaprojects (tags) for openBISTag in openBISTags: openBISTag.addEntity(openBISExperiment) # Set the experiment version openBISExperiment.setPropertyValue("LSR_FORTESSA_EXPERIMENT_VERSION", expVersion) # Set the date openBISExperiment.setPropertyValue("LSR_FORTESSA_EXPERIMENT_DATE", expDate) # Set the description openBISExperiment.setPropertyValue("LSR_FORTESSA_EXPERIMENT_DESCRIPTION", description) # Set the acquisition hardware openBISExperiment.setPropertyValue("LSR_FORTESSA_EXPERIMENT_ACQ_HARDWARE", acqHardware) # Set the acquisition hardware friendly name openBISExperiment.setPropertyValue("LSR_FORTESSA_EXPERIMENT_ACQ_HARDWARE_FRIENDLY_NAME", self._machinename) # Set the acquisition software openBISExperiment.setPropertyValue("LSR_FORTESSA_EXPERIMENT_ACQ_SOFTWARE", acqSoftware) # Set the experiment owner openBISExperiment.setPropertyValue("LSR_FORTESSA_EXPERIMENT_OWNER", owner) # Add the attachments if attachments is not None: # Extract all relative file names attachmentFiles = attachments.split(";") for f in attachmentFiles: # This is an additional security step if f == '': continue # Inform msg = "Adding file attachment " + f self._logger.info(msg) # Build the full path attachmentFilePath = os.path.join(self._incoming.getAbsolutePath(), f) # Extract the file name attachmentFileName = os.path.basename(attachmentFilePath) # Read the attachment into a byte array javaFile = java.io.File(attachmentFilePath) byteArray = FileUtils.readFileToByteArray(javaFile) # Add attachment openBISExperiment.addAttachment(attachmentFilePath, attachmentFileName, "", byteArray) # Return the openBIS Experiment object return openBISExperiment
def processExperiment(self, experimentNode): """Register an IExperimentUpdatable based on the Experiment XML node. @param experimentNode An XML node corresponding to an Experiment @return IExperimentUpdatable experiment """ # Get the experiment version expVersion = experimentNode.attrib.get("version") if expVersion is None: expVersion = "0" # Get the openBIS identifier openBISIdentifier = experimentNode.attrib.get("openBISIdentifier") # Get the experiment name expName = experimentNode.attrib.get("name") # Get the experiment date and reformat it to be compatible # with postgreSQL expDate = self.formatExpDateForPostgreSQL( experimentNode.attrib.get("date")) # Get the description description = experimentNode.attrib.get("description") # Get the acquisition hardware acqHardware = experimentNode.attrib.get("acq_hardware") # Get the acquisition software acqSoftware = experimentNode.attrib.get("acq_software") # Get the owner name owner = experimentNode.attrib.get("owner_name") # Get attachments attachments = experimentNode.attrib.get("attachments") # Create the experiment (with corrected ID if needed: see above) openBISExperiment = self.createExperiment(openBISIdentifier, expName) if not openBISExperiment: msg = "Could not create experiment " + openBISIdentifier self._logger.error(msg) raise Exception(msg) # Get comma-separated tag list tagList = experimentNode.attrib.get("tags") if tagList != None and tagList != "": # Retrieve or create the tags openBISTags = self.retrieveOrCreateTags(tagList) # Set the metaprojects (tags) for openBISTag in openBISTags: openBISTag.addEntity(openBISExperiment) # Set the experiment version openBISExperiment.setPropertyValue("FACS_ARIA_EXPERIMENT_VERSION", expVersion) # Set the date openBISExperiment.setPropertyValue("FACS_ARIA_EXPERIMENT_DATE", expDate) # Set the description openBISExperiment.setPropertyValue("FACS_ARIA_EXPERIMENT_DESCRIPTION", description) # Set the acquisition hardware openBISExperiment.setPropertyValue("FACS_ARIA_EXPERIMENT_ACQ_HARDWARE", acqHardware) # Set the acquisition hardware friendly name openBISExperiment.setPropertyValue( "FACS_ARIA_EXPERIMENT_ACQ_HARDWARE_FRIENDLY_NAME", self._machinename) # Set the acquisition software openBISExperiment.setPropertyValue("FACS_ARIA_EXPERIMENT_ACQ_SOFTWARE", acqSoftware) # Set the experiment owner openBISExperiment.setPropertyValue("FACS_ARIA_EXPERIMENT_OWNER", owner) # Add the attachments if attachments is not None: # Extract all relative file names attachmentFiles = attachments.split(";") for f in attachmentFiles: # This is an additional security step if f == '': continue # Inform msg = "Adding file attachment " + f self._logger.info(msg) # Build the full path attachmentFilePath = os.path.join( self._incoming.getAbsolutePath(), f) # Extract the file name attachmentFileName = os.path.basename(attachmentFilePath) # Read the attachment into a byte array javaFile = java.io.File(attachmentFilePath) byteArray = FileUtils.readFileToByteArray(javaFile) # Add attachment openBISExperiment.addAttachment(attachmentFilePath, attachmentFileName, "", byteArray) # Return the openBIS Experiment object return openBISExperiment
def processExperiment(self, experimentNode, openBISExpType="MICROSCOPY_EXPERIMENT"): """Register an IExperiment based on the Experiment XML node. @param experimentNode An XML node corresponding to an Experiment @param openBISExpType The experiment type @return IExperiment experiment """ # Get the experiment version expVersion = experimentNode.attrib.get("version") if expVersion is None: expVersion = "0" # Get the openBIS identifier openBISIdentifier = experimentNode.attrib.get("openBISIdentifier") # Get the experiment name expName = experimentNode.attrib.get("name") # Get the experiment date and reformat it to be compatible # with postgreSQL # TODO: Add this # expDate = self.formatExpDateForPostgreSQL(experimentNode.attrib.get("date")) # Get the description description = experimentNode.attrib.get("description") # Get the acquisition hardware # TODO: Add this # acqHardware = experimentNode.attrib.get("acq_hardware") # Get the acquisition software # TODO: Add this # acqSoftware = experimentNode.attrib.get("acq_software") # Get the owner name # TODO: Add this # owner = experimentNode.attrib.get("owner_name") # Get attachments attachments = experimentNode.attrib.get("attachments") # Make sure to keep the code length within the limits imposed by # openBIS for codes if len(openBISIdentifier) > 41: openBISIdentifier = openBISIdentifier[0:41] # Create univocal ID openBISIdentifier = openBISIdentifier + "_" + self.getCustomTimeStamp() # Make sure to create a new Experiment openBISExperiment = self._transaction.createNewExperiment(openBISIdentifier, openBISExpType) print(type(openBISExperiment)) if not openBISExperiment: msg = "PROCESSOR::processExperiment(): " + \ "Could not create experiment " + openBISIdentifier self._logger.error(msg) raise Exception(msg) # Get comma-separated tag list tagList = experimentNode.attrib.get("tags") if tagList != None and tagList != "": # Retrieve or create the tags openBISTags = self.retrieveOrCreateTags(tagList) # Set the metaprojects (tags) for openBISTag in openBISTags: openBISTag.addEntity(openBISExperiment) # Set the date # TODO: Add this # openBISExperiment.setPropertyValue("MICROSCOPY_EXPERIMENT_DATE", # expDate) # Store the name openBISExperiment.setPropertyValue("MICROSCOPY_EXPERIMENT_NAME", expName) # Set the experiment version openBISExperiment.setPropertyValue("MICROSCOPY_EXPERIMENT_VERSION", expVersion) # Set the description -- but only if is not empty. # This makes sure that the description of an already existing experiment # is not overridden by an empty string. if description != "": openBISExperiment.setPropertyValue("MICROSCOPY_EXPERIMENT_DESCRIPTION", description) else: currentDescription = openBISExperiment.getPropertyValue("MICROSCOPY_EXPERIMENT_DESCRIPTION") if (currentDescription is None or currentDescription == ""): openBISExperiment.setPropertyValue("MICROSCOPY_EXPERIMENT_DESCRIPTION", "") # TODO: Add this # openBISExperiment.setPropertyValue("MICROSCOPY_EXPERIMENT_ACQ_HARDWARE", # acqHardware) # Set the acquisition hardware friendly name openBISExperiment.setPropertyValue("MICROSCOPY_EXPERIMENT_ACQ_HARDWARE_FRIENDLY_NAME", self._machinename) # Set the acquisition software # TODO: Add this # openBISExperiment.setPropertyValue("MICROSCOPY_EXPERIMENT_ACQ_SOFTWARE", # acqSoftware) # Set the experiment owner # TODO: Add this # openBISExperiment.setPropertyValue("MICROSCOPY_EXPERIMENT_OWNER", # owner) # Add the attachments if attachments is not None: # Extract all relative file names attachmentFiles = attachments.split(";") for f in attachmentFiles: # This is an additional security step if f == '': continue # Inform msg = "Adding file attachment " + f self._logger.info(msg) # Build the full path attachmentFilePath = os.path.join(self._incoming.getAbsolutePath(), f) # Extract the file name attachmentFileName = os.path.basename(attachmentFilePath) # Read the attachment into a byte array javaFile = java.io.File(attachmentFilePath) byteArray = FileUtils.readFileToByteArray(javaFile) # Add attachment openBISExperiment.addAttachment(attachmentFilePath, attachmentFileName, "", byteArray) # Return the openBIS Experiment object return openBISExperiment