def createFolders(self,root,folderStructure): ''' root is where the folder structure shall be created folderStructure is a list of tuples of names and relative paths, e.g. [("doc_pdf_path","documents/pdf/"), ("doc_invalid_path","documents/invalid/")] The relative paths will be created in root and the names will be printed as debug info with logger ''' for name,rel_path in folderStructure: path = os.path.join(root,rel_path) if not os.path.exists(path): tools.find_or_create_dir(path) self.debug_message('Created {0}'.format(path)) else: self.debug_message('{0} already exists as {1}.'.format(name,path))
def getVariables(self): ''' Get all required vars from command line + config and confirm their existence. ''' process_path = self.command_line.process_path self.break_level = self.getBreakLevel() v_exts = self.getConfigItem('valid_file_exts', section = self.valid_file_exts_section) self.valid_exts = v_exts.split(';') # TODO: Generalize this to take input from its own config section inv_path = self.getConfigItem('img_invalid_path', section = self.folder_structure_section) self.invalid_path = os.path.join(process_path,inv_path) tools.find_or_create_dir(self.invalid_path) img_path = self.getConfigItem('img_master_path', section= self.folder_structure_section) self.image_path = os.path.join(process_path,img_path) # Set list for storing paths for invalid files to move self.invalid_files = []
def getVariables(self): ''' Get all required vars from command line + config and confirm their existence. ''' process_root = self.command_line.process_path # Set path to input folder master_img_rel = self.getConfigItem('img_master_path', section = self.folder_structure_section) self.input_folder = os.path.join(process_root, master_img_rel) # Set path to output folder master_jpeg_rel = self.getConfigItem('img_master_jpeg_path', section = self.folder_structure_section) self.output_folder = os.path.join(process_root, master_jpeg_rel) tools.find_or_create_dir(self.output_folder) # Get quality and resize options for image conversion self.quality = self.getConfigItem('quality') self.resize_type = self.getConfigItem('resize_type') self.resize = self.getConfigItem('resize') exts = self.getConfigItem('valid_file_exts',section = self.valid_file_exts_section) self.valid_exts = exts.split(';')
def getVariables(self): ''' This script pulls in all the variables from the command line and the config file that are necessary for its running. Errors in variables will lead to an Exception being thrown. We need the path to the OJS mount, the current process dir, the pdf dir, and the ojs xml dir. ''' # Temporary, new processes should always have issn, so check should be in essential section # Initially assume we have an ISSN on the command line issn_missing = False try: self.issn = self.command_line.issn except AttributeError as e: self.debug_message("Warning, missing attribute. Details: {0}".format(e)) # We dont have an ISSN on the commandline, so use old code issn_missing = True process_path = self.command_line.process_path # Temporary, until all new processes uses issn if issn_missing: mets_file_name = self.getConfigItem('metadata_goobi_file', None, 'process_files') mets_file = os.path.join(process_path, mets_file_name) ojs_mount = self.getConfigItem('ojs_mount') ojs_metadata_dir = self.getConfigItem('metadata_ojs_path', section= self.folder_structure_section) self.ojs_metadata_dir = os.path.join(process_path, ojs_metadata_dir) pdf_path = self.getConfigItem('doc_pdf_path', section= self.folder_structure_section) self.pdf_input_dir = os.path.join(process_path, pdf_path) # Temporary condition, until all new processes uses issn if issn_missing: issue_data = mets_tools.getIssueData(mets_file) # Get path to generate ojs_dir -> system means "define it from system variables" self.ojs_journal_path = self.getSetting('ojs_journal_path', default='system') if self.ojs_journal_path == 'system': volume_title = tools.parseTitle(issue_data['TitleDocMain']) # TODO: write this one back as a property? # self.goobi_com.addProperty(self.process_id, 'ojs_journal_path', volume_title, overwrite=True) else: volume_title = self.ojs_journal_path # volume_title = tools.parseTitle(issue_data['TitleDocMain']) else: # We have a process with issn, so: issn = self.command_line.issn ojs_journal_path = ojs.getJournalPath(self.ojs_server, issn) ojs_journal_folder = os.path.join(ojs_mount, ojs_journal_path) # Temporary condition, until all new processes uses issn if issn_missing: ojs_journal_folder = os.path.join(ojs_mount, volume_title) # Create folder and set owner to gid 1000 => ojs-group tools.find_or_create_dir(ojs_journal_folder,change_owner=1000) self.ojs_dest_dir = os.path.join(ojs_journal_folder, self.command_line.process_title) # Create folder and set owner to gid 1000 => ojs-group tools.find_or_create_dir(self.ojs_dest_dir,change_owner=1000) tools.ensureDirsExist(self.ojs_metadata_dir, self.pdf_input_dir, self.ojs_dest_dir) # Temporary condition, in the future, issn is always available if not issn_missing: self.debug_message("metadata_dir is %s" % self.ojs_metadata_dir) self.debug_message("pdf_input_dir is %s" % self.pdf_input_dir) self.debug_message("dest_dir is %s" % self.ojs_dest_dir)