def from_xml(self, xml_metainfo): if xml_metainfo.tag == 'metainfo': self.original_xml = xml_metainfo if xml_metainfo.xpath('metc/cntinfo'): self.contactinfo.from_xml(xml_metainfo.xpath('metc/cntinfo')[0]) if xml_metainfo.xpath('metstdn'): standard = xml_utils.get_text_content(xml_metainfo, 'metstdn') self.ui.fgdc_metstdn.setCurrentText(standard) # switch wizard content to reflect the standard in this record if "biological" in standard.lower() \ or 'bdp' in standard.lower(): self.root_widget.switch_schema('bdp') else: self.root_widget.switch_schema('fgdc') metstdv = xml_utils.get_text_content(xml_metainfo, 'metstdv') self.ui.fgdc_metstdv.setCurrentText(metstdv) metd = xml_utils.get_text_content(xml_metainfo, 'metd') self.metd.set_date(metd) elif xml_metainfo.tag in ['ptcontac', 'cntinfo']: if xml_metainfo.tag == 'ptcontac': xml_metainfo = xml_utils.search_xpath(xml_metainfo, 'cntinfo') self.contactinfo.from_xml(xml_metainfo)
def from_xml(self, xml_metainfo): if xml_metainfo.tag == "metainfo": self.original_xml = xml_metainfo if xml_metainfo.xpath("metc/cntinfo"): self.contactinfo.from_xml( xml_metainfo.xpath("metc/cntinfo")[0]) if xml_metainfo.xpath("metstdn"): standard = xml_utils.get_text_content(xml_metainfo, "metstdn") self.ui.fgdc_metstdn.setCurrentText(standard) # switch wizard content to reflect the standard in this record if "biological" in standard.lower() or "bdp" in standard.lower( ): self.root_widget.switch_schema("bdp") else: self.root_widget.switch_schema("fgdc") metstdv = xml_utils.get_text_content(xml_metainfo, "metstdv") self.ui.fgdc_metstdv.setCurrentText(metstdv) metd = xml_utils.get_text_content(xml_metainfo, "metd") self.metd.set_date(metd) elif xml_metainfo.tag in ["ptcontac", "cntinfo"]: if xml_metainfo.tag == "ptcontac": xml_metainfo = xml_utils.search_xpath(xml_metainfo, "cntinfo") self.contactinfo.from_xml(xml_metainfo)
def from_xml(self, keywords_xml): """ parses the xml code into the relevant procstep elements Parameters ---------- process_step - the xml element status and its contents Returns ------- None """ self.clear_widget(remove_iso=True) self.original_xml = keywords_xml if keywords_xml.tag == "keywords": for theme_xml in xml_utils.search_xpath(keywords_xml, "theme", False): themekt = xml_utils.get_text_content(theme_xml, "themekt") if themekt is not None and "iso 19115" in themekt.lower(): self.add_iso() self.iso_kws.clear_widgets(add_another=False) for themekey in xml_utils.search_xpath( theme_xml, "themekey", only_first=False ): iso = self.iso_kws.add_another() iso.ui.fgdc_themekey.setCurrentText(themekey.text) else: theme = self.add_another() theme.from_xml(theme_xml)
def to_xml(self): # add code here to translate the form into xml representation metainfo_node = xml_utils.xml_node('metainfo') metd = xml_utils.xml_node('metd', text=self.metd.get_date(), parent_node=metainfo_node) if self.original_xml is not None: metrd = xml_utils.search_xpath(self.original_xml, 'metrd') if metrd is not None: metrd.tail = None metainfo_node.append(deepcopy(metrd)) if self.original_xml is not None: metfrd = xml_utils.search_xpath(self.original_xml, 'metfrd') if metfrd is not None: metfrd.tail = None metainfo_node.append(deepcopy(metfrd)) metc = xml_utils.xml_node('metc', parent_node=metainfo_node) cntinfo = self.contactinfo.to_xml() metc.append(cntinfo) metstdn = xml_utils.xml_node('metstdn', text=self.ui.fgdc_metstdn.currentText(), parent_node=metainfo_node) metstdv = xml_utils.xml_node('metstdv', text=self.ui.fgdc_metstdv.currentText(), parent_node=metainfo_node) if self.original_xml is not None: mettc = xml_utils.search_xpath(self.original_xml, 'mettc') if mettc is not None: mettc.tail = None metainfo_node.append(deepcopy(mettc)) if self.original_xml is not None: metac = xml_utils.search_xpath(self.original_xml, 'metac') if metac is not None: metac.tail = None metainfo_node.append(deepcopy(metac)) if self.original_xml is not None: metuc = xml_utils.search_xpath(self.original_xml, 'metuc') if metuc is not None: metuc_str = xml_utils.get_text_content(self.original_xml, 'metuc') metuc = xml_utils.xml_node('metuc', text=metuc_str, parent_node=metainfo_node) if self.original_xml is not None: metsi = xml_utils.search_xpath(self.original_xml, 'metsi') if metsi is not None: metsi.tail = None metainfo_node.append(deepcopy(metsi)) metextns = xml_utils.search_xpath(self.original_xml, 'metextns') if metextns is not None: metextns.tail = None metainfo_node.append(deepcopy(metextns)) return metainfo_node
def to_xml(self): # add code here to translate the form into xml representation metainfo_node = xml_utils.xml_node('metainfo') metd = xml_utils.xml_node('metd', text=self.metd.get_date(), parent_node=metainfo_node) if self.original_xml is not None: metrd = xml_utils.search_xpath(self.original_xml, 'metrd') if metrd is not None: metrd.tail = None metainfo_node.append(deepcopy(metrd)) if self.original_xml is not None: metfrd = xml_utils.search_xpath(self.original_xml, 'metfrd') if metfrd is not None: metfrd.tail = None metainfo_node.append(deepcopy(metfrd)) metc = xml_utils.xml_node('metc', parent_node=metainfo_node) cntinfo = self.contactinfo.to_xml() metc.append(cntinfo) metstdn = xml_utils.xml_node('metstdn', text=self.ui.fgdc_metstdn.currentText(), parent_node=metainfo_node) metstdv = xml_utils.xml_node('metstdv', text=self.ui.fgdc_metstdv.currentText(), parent_node=metainfo_node) if self.original_xml is not None: mettc = xml_utils.search_xpath(self.original_xml, 'mettc') if mettc is not None: mettc.tail = None metainfo_node.append(deepcopy(mettc)) if self.original_xml is not None: metac = xml_utils.search_xpath(self.original_xml, 'metac') if metac is not None: metac.tail = None metainfo_node.append(deepcopy(metac)) metuc_str = "Record created using version {} of the USGS Metadata " \ "Wizard tool. (https://github.com/usgs/" \ "fort-pymdwizard)".format(__version__) if self.original_xml is not None: metuc = xml_utils.search_xpath(self.original_xml, 'metuc') if metuc is not None: metuc_str = xml_utils.get_text_content(self.original_xml, 'metuc') metuc = xml_utils.xml_node('metuc', text=metuc_str, parent_node=metainfo_node) if self.original_xml is not None: metextns = xml_utils.search_xpath(self.original_xml, 'metextns') if metextns is not None: metextns.tail = None metainfo_node.append(deepcopy(metextns)) return metainfo_node
def from_xml(self, spdoinfo): self.clear_widget() if spdoinfo.tag == "spdoinfo": self.original_xml = spdoinfo self.ui.rbtn_yes.setChecked(True) direct = xml_utils.get_text_content(spdoinfo, "direct") if direct is not None: if "raster" in direct.lower(): self.ui.fgdc_direct.setCurrentIndex(0) self.ui.fgdc_direct.setCurrentIndex(2) elif "point" in direct.lower(): self.ui.fgdc_direct.setCurrentIndex(2) self.ui.fgdc_direct.setCurrentIndex(0) elif "vector" in direct.lower(): self.ui.fgdc_direct.setCurrentIndex(0) self.ui.fgdc_direct.setCurrentIndex(1) rasttype = xml_utils.get_text_content(spdoinfo, "rastinfo/rastype") if rasttype is not None: self.ui.fgdc_rasttype.setCurrentText(rasttype) sdtstype = xml_utils.get_text_content( spdoinfo, "ptvctinf/sdtsterm/sdtstype") if sdtstype is not None: self.ui.fgdc_sdtstype.setCurrentText(sdtstype) ptvctcnt = xml_utils.get_text_content( spdoinfo, "ptvctinf/sdtsterm/ptvctcnt") if ptvctcnt is not None: self.ui.fgdc_ptvctcnt.setText(ptvctcnt) rasttype = xml_utils.get_text_content(spdoinfo, "rastinfo/rasttype") if rasttype is not None: self.ui.fgdc_rasttype.setCurrentText(rasttype) rowcount = xml_utils.get_text_content(spdoinfo, "rastinfo/rowcount") if rowcount is not None: self.ui.fgdc_rowcount.setText(rowcount) colcount = xml_utils.get_text_content(spdoinfo, "rastinfo/colcount") if colcount is not None: self.ui.fgdc_colcount.setText(colcount) vrtcount = xml_utils.get_text_content(spdoinfo, "rastinfo/vrtcount") if vrtcount is not None: self.ui.fgdc_vrtcount.setText(vrtcount)
def _from_xml(self, spdoinfo): self.clear_widget() if spdoinfo.tag == 'spdoinfo': self.ui.rbtn_yes.setChecked(True) direct = xml_utils.get_text_content(spdoinfo, 'direct') if direct is not None: if 'raster' in direct.lower(): self.ui.fgdc_direct.setCurrentIndex(0) self.ui.fgdc_direct.setCurrentIndex(2) elif 'point' in direct.lower(): self.ui.fgdc_direct.setCurrentIndex(2) self.ui.fgdc_direct.setCurrentIndex(0) elif 'vector' in direct.lower(): self.ui.fgdc_direct.setCurrentIndex(0) self.ui.fgdc_direct.setCurrentIndex(1) rasttype = xml_utils.get_text_content(spdoinfo, 'rastinfo/rastype') if rasttype is not None: self.ui.fgdc_rasttype.setCurrentText(rasttype) sdtstype = xml_utils.get_text_content( spdoinfo, 'ptvctinf/sdtsterm/sdtstype') if sdtstype is not None: self.ui.fgdc_sdtstype.setCurrentText(sdtstype) ptvctcnt = xml_utils.get_text_content( spdoinfo, 'ptvctinf/sdtsterm/ptvctcnt') if ptvctcnt is not None: self.ui.fgdc_ptvctcnt.setText(ptvctcnt) rasttype = xml_utils.get_text_content(spdoinfo, 'rastinfo/rasttype') if rasttype is not None: self.ui.fgdc_rasttype.setCurrentText(rasttype) rowcount = xml_utils.get_text_content(spdoinfo, 'rastinfo/rowcount') if rowcount is not None: self.ui.fgdc_rowcount.setText(rowcount) colcount = xml_utils.get_text_content(spdoinfo, 'rastinfo/colcount') if colcount is not None: self.ui.fgdc_colcount.setText(colcount) vrtcount = xml_utils.get_text_content(spdoinfo, 'rastinfo/vrtcount') if vrtcount is not None: self.ui.fgdc_vrtcount.setText(vrtcount)
def _from_xml(self, use_constraints): """ parses the xml code into the relevant useconst elements Parameters ---------- use_constraints - the xml element status and its contents Returns ------- None """ try: if use_constraints.tag == 'useconst': accost_box = self.findChild(QPlainTextEdit, "fgdc_useconst") useconst_str = xml_utils.get_text_content(use_constraints) accost_box.setPlainText(useconst_str) return True else: return False except KeyError: return False