def step(self): error = None try: self.getVariables() # Get the number of valid images image_count = tools.getFileCountWithExtension(self.image_path, self.valid_exts) self.debug_message("Der blev optalt {} billeder".format(image_count)) # write the number of images to a Goobi property. It sometimes fail, hence the retry stuff max_retry = 10 retry = 0 ok = False while not ok: ok = self.goobi_com.addProperty(name=self.property_name, value=image_count, overwrite=True) retry += 1 if not ok: self.debug_message("Billedantallet kunne ikke gemmes! Proever igen... (retry={})".format(retry)) time.sleep(5) if retry > max_retry: error = "Fejl, Kunne ikke gemme billedantallet i Goobi's database!" self.debug_message(error) # return error # Return None for now, we don't want a wep api lockup to stop the workflow # Until a "sudo service tomcat restart", imagecount will be 0. # todo: solve problem with web api lockup return None self.debug_message("Billedantallet ({}) blev gemt korrekt i forsoeg nr {}".format(image_count, retry)) # not sure which exceptions to expect... except ValueError as e: error = str(e.with_traceback) return error
def altoFileCountMatches(alto_dir, input_files_dir,valid_exts): ''' Ensure number of alto files is the same as the number of input files. Return boolean ''' numAlto = len(os.listdir(alto_dir)) numInputFiles = tools.getFileCountWithExtension(input_files_dir,valid_exts) return numAlto == numInputFiles
def pageCountMatches(pdf_input_dir,input_files_dir,valid_exts): ''' Compare num pages in pdfinfo with pages in input picture directory. return boolean ''' pdf = tools.getFirstFileWithExtension(pdf_input_dir, '.pdf') pdfInfo = tools.pdfinfo(os.path.join(pdf_input_dir, pdf)) numPages = int(pdfInfo['Pages']) numInputFiles = tools.getFileCountWithExtension(input_files_dir,valid_exts) return numPages == numInputFiles