def add_pub_date_to_xml(self, doi_id, root): # Get the date for the first version date_struct = None date_str = self.get_pub_date_str_from_lax(doi_id) if date_str is not None: date_struct = time.strptime(date_str, "%Y%m%d000000") else: # Use current date date_struct = time.gmtime() # Create the pub-date XML tag pub_date_tag = self.pub_date_xml_element(date_struct) # Add the tag to the XML for tag in root.findall('./front/article-meta'): parent_tag_index = xmlio.get_first_element_index(tag, 'elocation-id') if not parent_tag_index: if(self.logger): self.logger.info('no elocation-id tag and no pub-date added: ' + str(doi_id)) else: tag.insert( parent_tag_index - 1, pub_date_tag) # Should only do it once but ensure it is only done once break return root
def add_tag_to_xml_before_elocation_id(self, add_tag, root, doi_id=""): # Add the tag to the XML for tag in root.findall('./front/article-meta'): parent_tag_index = xmlio.get_first_element_index(tag, 'elocation-id') if not parent_tag_index: if self.logger: self.logger.info('no elocation-id tag and no ' + str(add_tag.tag) + ' added: ' + str(doi_id)) else: tag.insert(parent_tag_index - 1, add_tag) # Should only do it once but ensure it is only done once break return root
def add_tag_to_xml_before_elocation_id(self, add_tag, root, doi_id=""): # Add the tag to the XML for tag in root.findall('./front/article-meta'): parent_tag_index = xmlio.get_first_element_index( tag, 'elocation-id') if not parent_tag_index: if self.logger: self.logger.info('no elocation-id tag and no ' + str(add_tag.tag) + ' added: ' + str(doi_id)) else: tag.insert(parent_tag_index - 1, add_tag) # Should only do it once but ensure it is only done once break return root
def add_self_uri_to_xml(self, doi_id, file_name, root): """ Add the self-uri tag to the XML for the PDF file """ # Create the XML tag self_uri_tag = self.self_uri_xml_element(file_name, doi_id) # Add the tag to the XML for tag in root.findall('./front/article-meta'): parent_tag_index = xmlio.get_first_element_index(tag, 'permissions') if not parent_tag_index: if self.logger: self.logger.info('no permissions tag and no self-uri tag added: ' + str(doi_id)) else: tag.insert(parent_tag_index, self_uri_tag) return root
def add_poa_ds_zip_to_xml(self, doi_id, file_name, root): """ Add the ext-link tag to the XML for the PoA ds.zip file """ # Create the XML tag supp_tag = self.ds_zip_xml_element(file_name, doi_id) # Add the tag to the XML for tag in root.findall('./front/article-meta'): parent_tag_index = xmlio.get_first_element_index(tag, 'history') if not parent_tag_index: if(self.logger): self.logger.info('no history tag and no ds_zip tag added: ' + str(doi_id)) else: tag.insert( parent_tag_index - 1, supp_tag) return root
def add_self_uri_to_xml(self, doi_id, file_name, root): """ Add the self-uri tag to the XML for the PDF file """ # Create the XML tag self_uri_tag = self.self_uri_xml_element(file_name, doi_id) # Add the tag to the XML for tag in root.findall('./front/article-meta'): parent_tag_index = xmlio.get_first_element_index( tag, 'permissions') if not parent_tag_index: if self.logger: self.logger.info( 'no permissions tag and no self-uri tag added: ' + str(doi_id)) else: tag.insert(parent_tag_index, self_uri_tag) return root
def test_get_first_element_index(self, filename, tag_name, index): root = xmlio.parse(sample_xml(filename)) self.assertEqual(xmlio.get_first_element_index(root, tag_name), index)