def step(self): ''' This class checks the output from a LIMB process to see if it matches certain criteria Require params process_title from command line Other values taken from config.ini In the case of errors a message will be returned and sent to the previous step. ''' error = None try: self.getVariables() # Check files on goobi-server, if they already have been moved if (not self.ignore_goobi_folder and limb_tools.alreadyMoved(self.goobi_toc,self.goobi_pdf, self.input_files_dir,self.goobi_altos, self.valid_exts)): return error tools.ensureDirsExist(self.limb_dir, self.alto_dir, self.toc_dir, self.pdf_input_dir, self.input_files_dir) limb_tools.performValidations(self.toc_dir,self.pdf_input_dir, self.input_files_dir,self.alto_dir, self.valid_exts) return None except IOError as e: return "IOError - {0}".format(e.strerror) except DataError as e: return "Validation error - {0}.".format(e.strerror)
def step(self): """ legr: copy TIFF's from Goobi to Limb legr: if "overwrite_destination_files=True" is added to the command line, we send TIFF's to Limb legr: even if we already has recieved ALTO's, PDF and TOC from a previous LIMB processing. """ error = None self.getVariables() msg = ('Copying files from {0} to {1} via transit {2}.') msg = msg.format(self.source_folder, self.hotfolder_dir, self.transit_dir) self.debug_message(msg) try: if not self.overwrite_destination_files: if limb_tools.alreadyMoved(self.goobi_toc,self.goobi_pdf, self.input_files,self.goobi_altos, self.valid_exts): return error if (tools.folderExist(self.hotfolder_dir) and fs.compareDirectories(self.source_folder, self.hotfolder_dir)): return error tools.copy_files(source = self.source_folder, dest = self.hotfolder_dir, transit = self.transit_dir, delete_original = False, wait_interval = self.sleep_interval, max_retries = self.retries, logger = self.glogger) except errors.TransferError as e: error = e.strerror except errors.TransferTimedOut as e: error = e.strerror except Exception as e: error = str(e) return error
def step(self): ''' Move altos, toc, pdf from limb to goobi ''' error = None try: self.getVariables() # check if files already have been copied: if (not self.ignore_goobi_folder and limb_tools.alreadyMoved(self.goobi_toc,self.goobi_pdf, self.input_files,self.goobi_altos, self.valid_exts)): return error tools.ensureDirsExist(self.limb_altos, self.limb_toc, self.limb_pdf) self.moveFiles(self.limb_altos, self.goobi_altos) self.moveFiles(self.limb_toc, self.goobi_toc) self.moveFiles(self.limb_pdf, self.goobi_pdf) # Delete the empty process folder in LIMBs output folder try: os.rmdir(self.limb_process_root) except OSError: msg = 'Process folder "{0}" on LIMB could not be deleted.' msg = msg.format(self.limb_process_root) self.info_message(msg) except ValueError as e: return e.strerror #return "Could not convert string to int - check config file." except (TransferError, TransferTimedOut, IOError) as e: return e.strerror return None
def step(self): """ This script's role is to wait until LIMB processing is complete before finishing. In the event of a timeout, it reports back to previous step before exiting. """ error = None retry_counter = 0 try: self.getVariables() # First check if files already have been copied to goobi if not self.ignore_goobi_folder and limb_tools.alreadyMoved( self.goobi_toc, self.goobi_pdf, self.input_files, self.goobi_altos, self.valid_exts ): return error # keep on retrying for the given number of attempts while retry_counter < self.retry_num: if self.limbIsReady(): msg = "LIMB output is ready - exiting." self.debug_message(msg) return None # this is the only successful exit possible else: # if they haven't arrived, sit and wait for a while msg = "LIMB output not ready - sleeping for {0} seconds..." msg = msg.format(self.retry_wait) self.debug_message(msg) retry_counter += 1 time.sleep(self.retry_wait) except IOError as e: # if we get an IO error we need to crash error = "Error reading from directory {0}" error = error.format(e.strerror) return error except ValueError as e: # caused by conversion of non-numeric strings in config to nums error = "Invalid config data supplied, error: {0}" error = error.format(e.strerror) return error # if we've gotten this far, we've timed out and need to go back to the previous step return "Timed out waiting for LIMB output."