def to_xml(self): spdom = xml_node('spdom') if self.schema == 'bdp': descgeog = xml_node('descgeog', text=self.ui.fgdc_descgeog.text(), parent_node=spdom) bounding = xml_node('bounding', parent_node=spdom) westbc = xml_node('westbc', text=self.ui.fgdc_westbc.text(), parent_node=bounding) eastbc = xml_node('eastbc', text=self.ui.fgdc_eastbc.text(), parent_node=bounding) northbc = xml_node('northbc', text=self.ui.fgdc_northbc.text(), parent_node=bounding) southbc = xml_node('southbc', text=self.ui.fgdc_southbc.text(), parent_node=bounding) if self.original_xml is not None: boundalt = xml_utils.search_xpath(self.original_xml, 'bounding/boundalt') if boundalt is not None: spdom.append(deepcopy(boundalt)) dsgpoly_list = xml_utils.search_xpath(self.original_xml, 'dsgpoly', only_first=False) for dsgpoly in dsgpoly_list: spdom.append(deepcopy(dsgpoly)) return spdom
def from_xml(self, xml_idinfo): """ parses the xml code into the relevant accconst elements Parameters ---------- access_constraints - the xml element status and its contents Returns ------- None """ try: if xml_idinfo.tag == 'idinfo': self.crossrefs.clear_widgets(add_another=False) crossrefs = xml_utils.search_xpath(xml_idinfo, 'crossref', only_first=False) if crossrefs: self.ui.radio_crossrefyes.setChecked(True) else: self.crossrefs.add_another() self.ui.radio_crossrefno.setChecked(True) for crossref in crossrefs: crossref_widget = self.crossrefs.add_another() crossref_widget.from_xml(xml_utils.search_xpath(crossref, 'citeinfo')) except KeyError: self.ui.radio_crossrefno.setChecked(True)
def to_xml(self): spdom = xml_node("spdom") if self.schema == "bdp": descgeog = xml_node("descgeog", text=self.ui.fgdc_descgeog.text(), parent_node=spdom) bounding = xml_node("bounding", parent_node=spdom) westbc = xml_node("westbc", text=self.ui.fgdc_westbc.text(), parent_node=bounding) eastbc = xml_node("eastbc", text=self.ui.fgdc_eastbc.text(), parent_node=bounding) northbc = xml_node("northbc", text=self.ui.fgdc_northbc.text(), parent_node=bounding) southbc = xml_node("southbc", text=self.ui.fgdc_southbc.text(), parent_node=bounding) if self.original_xml is not None: boundalt = xml_utils.search_xpath(self.original_xml, "bounding/boundalt") if boundalt is not None: spdom.append(deepcopy(boundalt)) dsgpoly_list = xml_utils.search_xpath(self.original_xml, "dsgpoly", only_first=False) for dsgpoly in dsgpoly_list: spdom.append(deepcopy(dsgpoly)) return spdom
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): distinfo_node = xml_utils.xml_node('distinfo') dist = xml_utils.xml_node('distrib', parent_node=distinfo_node) cntinfo = self.contactinfo.to_xml() dist.append(cntinfo) if self.original_xml is not None: resdesc = xml_utils.search_xpath(self.original_xml, 'resdesc') if resdesc is not None: resdesc.tail = None distinfo_node.append(deepcopy(resdesc)) if self.ui.radio_online.isChecked(): liab = xml_utils.xml_node('distliab', text=self.ui.fgdc_distliab.toPlainText(), parent_node=distinfo_node) stdorder = xml_utils.xml_node('stdorder', parent_node=distinfo_node) digform = xml_utils.xml_node('digform', parent_node=stdorder) digtinfo = xml_utils.xml_node('digtinfo', parent_node=digform) formname = xml_utils.xml_node('formname', parent_node=digtinfo, text='Digital Data') digtopt = xml_utils.xml_node('digtopt', parent_node=digform) onlinopt = xml_utils.xml_node('onlinopt', parent_node=digtopt) computer = xml_utils.xml_node('computer', parent_node=onlinopt) networka = xml_utils.xml_node('networka', parent_node=computer) networkr = xml_utils.xml_node('networkr', text=self.ui.fgdc_networkr.text(), parent_node=networka) fees = xml_utils.xml_node('fees', text=self.ui.fgdc_fees.toPlainText(), parent_node=stdorder) if self.ui.radio_otherdist.isChecked(): liab = xml_utils.xml_node('distliab', text=self.ui.fgdc_distliab.toPlainText(), parent_node=distinfo_node) other = xml_utils.xml_node('custom', text=self.ui.fgdc_custom.toPlainText(), parent_node=distinfo_node) if self.ui.radio_dist.isChecked(): liab = xml_utils.xml_node('distliab', text=self.ui.fgdc_distliab.toPlainText(), parent_node=distinfo_node) if self.original_xml is not None: techpreq = xml_utils.search_xpath(self.original_xml, 'techpreq') if techpreq is not None: techpreq.tail = None distinfo_node.append(deepcopy(techpreq)) return distinfo_node
def to_xml(self): if self.ui.rbtn_yes.isChecked(): spdoinfo = xml_utils.xml_node("spdoinfo") if self.original_xml is not None: indspref = xml_utils.search_xpath(self.original_xml, "indspref") if indspref is not None: indspref.tail = None spdoinfo.append(deepcopy(indspref)) direct = xml_utils.xml_node("direct", text=self.ui.fgdc_direct.currentText(), parent_node=spdoinfo) if self.ui.fgdc_direct.currentText() == "Raster": rasttype = self.ui.fgdc_rasttype.currentText() if rasttype: rastinfo = xml_utils.xml_node("rastinfo", parent_node=spdoinfo) rasttype = xml_utils.xml_node("rasttype", text=rasttype, parent_node=rastinfo) rowcount_str = self.ui.fgdc_rowcount.text() colcount_str = self.ui.fgdc_colcount.text() vrtcount_str = self.ui.fgdc_vrtcount.text() if rowcount_str or colcount_str: rowcount = xml_utils.xml_node("rowcount", text=rowcount_str, parent_node=rastinfo) colcount = xml_utils.xml_node("colcount", text=colcount_str, parent_node=rastinfo) if vrtcount_str: vrtcount = xml_utils.xml_node("vrtcount", text=vrtcount_str, parent_node=rastinfo) else: sdtstype = self.ui.fgdc_sdtstype.currentText() ptvctcnt = self.ui.fgdc_ptvctcnt.text() if sdtstype or ptvctcnt: ptvctinf = xml_utils.xml_node("ptvctinf", parent_node=spdoinfo) sdtsterm = xml_utils.xml_node("sdtsterm", parent_node=ptvctinf) sdtstype = xml_utils.xml_node("sdtstype", text=sdtstype, parent_node=sdtsterm) ptvctcnt_str = self.ui.fgdc_ptvctcnt.text() if ptvctcnt_str: sdtsterm = xml_utils.xml_node("ptvctcnt", text=ptvctcnt_str, parent_node=sdtsterm) else: spdoinfo = None return spdoinfo
def from_xml(self, taxoncl): """ parses the xml code into the relevant timeperd elements Parameters ---------- metadata_date - the xml element timeperd and its contents Returns ------- None """ try: if taxoncl.tag == "taxoncl": self.ui.fgdc_taxonrn.setText(taxoncl.xpath("taxonrn")[0].text) self.ui.fgdc_taxonrv.setText(taxoncl.xpath("taxonrv")[0].text) commons = xml_utils.search_xpath(taxoncl, "common", only_first=False) if commons: self.commons.clear_widgets(add_another=False) for common in commons: this_common = self.commons.add_another() this_common.setText(common.text) children_taxoncl = taxoncl.xpath("taxoncl") for child_taxoncl in children_taxoncl: child_widget = Taxoncl() child_widget.from_xml(child_taxoncl) self.ui.child_taxoncl.layout().addWidget(child_widget) self.child_taxoncl.append(child_widget) else: print("The tag is not a detailed") except KeyError: pass
def populate_section(self, metadata_element, section_name, widget): """ Since the content of top level sections might contain items that need to go to separate top level items, this function handles the divvying up of sub-content. Parameters ---------- metadata_element : XML Element section_name : Section tag to populate widget : The section widget Returns ------- """ just_this_one = type(metadata_element) == etree._Element if just_this_one and metadata_element.tag == section_name: section = metadata_element elif just_this_one: return True else: section = xml_utils.search_xpath(metadata_element, section_name) if section is not None: widget.from_xml(section) elif not just_this_one: widget.clear_widget()
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 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): taxonomy = xml_utils.xml_node('taxonomy') taxonomy.append(self.keywtax.to_xml()) if self.original_xml is not None: taxonsys = xml_utils.search_xpath(self.original_xml, 'taxonsys') if taxonsys is not None: taxonsys.tail = None taxonomy.append(deepcopy(taxonsys)) taxongen = xml_utils.search_xpath(self.original_xml, 'taxongen') if taxongen is not None: taxongen.tail = None taxonomy.append(deepcopy(taxongen)) taxonomy.append(self.taxoncl.to_xml()) return taxonomy
def to_xml(self): # add code here to translate the form into xml representation dataqual_node = xml_utils.xml_node(tag='dataqual') attraccr_node = self.attraccr.to_xml() dataqual_node.append(attraccr_node) logic_node = self.logic.to_xml() dataqual_node.append(logic_node) complete_node = self.complete.to_xml() dataqual_node.append(complete_node) if self.posacc.has_content(): posacc_node = self.posacc.to_xml() dataqual_node.append(posacc_node) if self.sourceinput.has_content(): srcinfo_node = self.sourceinput.to_xml() procstep_node = self.procstep.to_xml() procstep_children = procstep_node.getchildren() for i in procstep_children: srcinfo_node.append(i) if self.original_xml is not None: methods = xml_utils.search_xpath(self.original_xml, 'lineage/method', only_first=False) for i, method in enumerate(methods): method.tail = None srcinfo_node.insert(i, deepcopy(method)) dataqual_node.append(srcinfo_node) if self.original_xml is not None: cloud = xml_utils.search_xpath(self.original_xml, 'cloud') if cloud is not None: cloud.tail = None dataqual_node.append(deepcopy(cloud)) return dataqual_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 to_xml(self): keywords = self.theme_list.to_xml() place_keywords = self.place_list.to_xml() for child_node in place_keywords.xpath("place"): keywords.append(child_node) if self.original_xml is not None: stratums = xml_utils.search_xpath(self.original_xml, "stratum", only_first=False) for stratum in stratums: stratum.tail = None keywords.append(deepcopy(stratum)) temporals = xml_utils.search_xpath(self.original_xml, "temporal", only_first=False) for temporal in temporals: temporal.tail = None keywords.append(deepcopy(temporal)) return keywords
def populate_section(self, metadata_element, section_name, widget): just_this_one = type(metadata_element) == etree._Element if just_this_one and metadata_element.tag == section_name: section = metadata_element elif just_this_one: return True else: section = xml_utils.search_xpath(metadata_element, section_name) if section is not None: widget._from_xml(section) elif not just_this_one: widget.clear_widget()
def to_xml(self): """ encapsulates the QPlainTextEdit text in an element tag Returns ------- attraccr element tag in xml tree """ attracc = xml_utils.xml_node(tag="attracc") attraccr_str = self.findChild(QPlainTextEdit, "fgdc_attraccr").toPlainText() attraccr = xml_utils.xml_node(tag="attraccr", text=attraccr_str, parent_node=attracc) if self.original_xml is not None: qattracc = xml_utils.search_xpath(self.original_xml, "qattracc") if qattracc is not None: qattracc.tail = None attracc.append(deepcopy(qattracc)) return attracc
def from_xml(self, spref_node): self.clear_widget() if spref_node.tag == 'spref': self.original_xml = spref_node self.ui.rbtn_yes.setChecked(True) geograph = xml_utils.search_xpath(spref_node, 'horizsys/geograph') if geograph is not None: self.ui.btn_planar.setChecked(True) self.ui.btn_geographic.setChecked(True) utils.populate_widget_element(self.ui.fgdc_latres, geograph, 'latres') utils.populate_widget_element(self.ui.fgdc_longres, geograph, 'longres') utils.populate_widget_element(self.ui.fgdc_geogunit, geograph, 'geogunit') local = xml_utils.search_xpath(spref_node, 'horizsys/local') if local is not None: self.ui.btn_planar.setChecked(True) self.ui.btn_local.setChecked(True) utils.populate_widget_element(self.ui.fgdc_localdes, local, 'localdes') utils.populate_widget_element(self.ui.fgdc_localgeo, local, 'localgeo') planar = xml_utils.search_xpath(spref_node, 'horizsys/planar') if planar is not None: self.ui.btn_grid.setChecked(True) self.ui.btn_planar.setChecked(True) mapproj = xml_utils.search_xpath(planar, 'mapproj') if mapproj is not None: self.ui.btn_projection.setChecked(True) utils.populate_widget_element(self.ui.fgdc_mapprojn, mapproj, 'mapprojn') mapproj_children = mapproj.getchildren() if len(mapproj_children) > 1: self.mapproj.from_xml(mapproj_children[1]) gridsys = xml_utils.search_xpath(planar, 'gridsys') if gridsys is not None: self.ui.btn_grid.setChecked(True) xml_utils.search_xpath(gridsys, 'gridsysn') utils.populate_widget_element(self.ui.fgdc_gridsysn, gridsys, 'gridsysn') gridsys_children = gridsys.getchildren() if len(gridsys_children) > 1: gridsys_contents = gridsys.getchildren()[1] else: gridsys_contents = [] for item in gridsys_contents.getchildren(): tag = item.tag if spatial_utils.lookup_shortname(tag) is not None: self.grid_mapproj.from_xml(item) elif tag == 'mapproj': mapprojn = xml_utils.search_xpath(item, 'mapprojn') if mapprojn.text in \ spatial_utils.PROJECTION_LOOKUP: self.grid_mapproj.from_xml(item.getchildren()[1]) else: item_widget = self.findChild(QLineEdit, "fgdc_"+tag) utils.set_text(item_widget, item.text) grid_proj = gridsys.xpath('proj') localp = xml_utils.search_xpath(planar, 'localp') if localp: self.ui.btn_localp.setChecked(True) utils.populate_widget_element(self.ui.fgdc_localpd, localp, 'localpd') utils.populate_widget_element(self.ui.fgdc_localpgi, localp, 'localpgi') utils.populate_widget_element(self.ui.fgdc_plance, planar, 'planci/plance') utils.populate_widget_element(self.ui.fgdc_plandu, planar, 'planci/plandu') utils.populate_widget_element(self.ui.fgdc_absres, planar, 'planci/coordrep/absres') utils.populate_widget_element(self.ui.fgdc_ordres, planar, 'planci/coordrep/ordres') self.planar_changed() geodetic = xml_utils.search_xpath(spref_node, 'horizsys/geodetic') if geodetic is not None: utils.populate_widget_element(self.ui.fgdc_horizdn, geodetic, 'horizdn') utils.populate_widget_element(self.ui.fgdc_ellips, geodetic, 'ellips') utils.populate_widget_element(self.ui.fgdc_semiaxis, geodetic, 'semiaxis') utils.populate_widget_element(self.ui.fgdc_denflat, geodetic, 'denflat') vertdef = xml_utils.search_xpath(spref_node, 'vertdef') if vertdef is not None: self.vertdef.from_xml(vertdef)
def _to_xml(self): # add code here to translate the form into xml representation idinfo_node = xml_utils.xml_node('idinfo') citation_node = xml_utils.xml_node('citation', parent_node=idinfo_node) citeinfo_node = self.citation._to_xml() citation_node.append(citeinfo_node) idinfo_node.append(citation_node) descript_node = xml_utils.xml_node('descript', parent_node=idinfo_node) abstract_node = self.descript._to_xml() descript_node.append(abstract_node) purpose_node = self.purpose._to_xml() descript_node.append(purpose_node) supplinf_node = self.supplinf._to_xml() if supplinf_node.text is not None: descript_node.append(supplinf_node) idinfo_node.append(descript_node) timeperd_node = self.timeperd._to_xml() idinfo_node.append(timeperd_node) status_node = self.status._to_xml() idinfo_node.append(status_node) spdom_node = self.root_widget.spatial_tab.spdom._to_xml() idinfo_node.append(spdom_node) keywords = self.keywords._to_xml() idinfo_node.append(keywords) if self.schema == 'bdp' and self.taxonomy.has_content(): taxonomy = self.taxonomy._to_xml() idinfo_node.append(taxonomy) accconst_node = self.accconst._to_xml() idinfo_node.append(accconst_node) useconst_node = self.useconst._to_xml() idinfo_node.append(useconst_node) if self.ptcontac.has_content(): ptcontac = self.ptcontac._to_xml() idinfo_node.append(ptcontac) datacredit_node = self.datacredit._to_xml() if datacredit_node.text: idinfo_node.append(datacredit_node) if self.original_xml is not None: secinfo = xml_utils.search_xpath(self.original_xml, 'secinfo') if secinfo is not None: idinfo_node.append(deepcopy(secinfo)) native = xml_utils.search_xpath(self.original_xml, 'native') if native is not None: idinfo_node.append(deepcopy(native)) crossref_list = xml_utils.search_xpath(self.original_xml, 'crossref', only_first=False) for crossref in crossref_list: idinfo_node.append(deepcopy(crossref)) tool = xml_utils.search_xpath(self.original_xml, 'tool') if tool is not None: idinfo_node.append(deepcopy(tool)) return idinfo_node
def to_xml(self): distinfo_node = xml_utils.xml_node("distinfo") dist = xml_utils.xml_node("distrib", parent_node=distinfo_node) cntinfo = self.contactinfo.to_xml() dist.append(cntinfo) if self.original_xml is not None: resdesc = xml_utils.search_xpath(self.original_xml, "resdesc") if resdesc is not None: resdesc.tail = None distinfo_node.append(deepcopy(resdesc)) if self.ui.radio_online.isChecked(): liab = xml_utils.xml_node( "distliab", text=self.ui.fgdc_distliab.toPlainText(), parent_node=distinfo_node, ) stdorder = xml_utils.xml_node("stdorder", parent_node=distinfo_node) digform = xml_utils.xml_node("digform", parent_node=stdorder) if self.original_xml is not None and self.original_xml.xpath( "stdorder/digform/digtinfo/formname"): digtinfo = self.original_xml.xpath("stdorder/digform/digtinfo") digform.append(deepcopy(digtinfo[0])) else: digtinfo = xml_utils.xml_node("digtinfo", parent_node=digform) formname = xml_utils.xml_node("formname", parent_node=digtinfo, text="Digital Data") digtopt = xml_utils.xml_node("digtopt", parent_node=digform) onlinopt = xml_utils.xml_node("onlinopt", parent_node=digtopt) computer = xml_utils.xml_node("computer", parent_node=onlinopt) networka = xml_utils.xml_node("networka", parent_node=computer) networkr = xml_utils.xml_node("networkr", text=self.ui.fgdc_networkr.text(), parent_node=networka) fees = xml_utils.xml_node("fees", text=self.ui.fgdc_fees.toPlainText(), parent_node=stdorder) if self.ui.radio_otherdist.isChecked(): liab = xml_utils.xml_node( "distliab", text=self.ui.fgdc_distliab.toPlainText(), parent_node=distinfo_node, ) other = xml_utils.xml_node( "custom", text=self.ui.fgdc_custom.toPlainText(), parent_node=distinfo_node, ) if self.ui.radio_dist.isChecked(): liab = xml_utils.xml_node( "distliab", text=self.ui.fgdc_distliab.toPlainText(), parent_node=distinfo_node, ) if self.original_xml is not None: techpreq = xml_utils.search_xpath(self.original_xml, "techpreq") if techpreq is not None: techpreq.tail = None distinfo_node.append(deepcopy(techpreq)) return distinfo_node
def from_xml(self, spref_node): self.clear_widget() if spref_node.tag == "spref": self.original_xml = spref_node self.ui.rbtn_yes.setChecked(True) geograph = xml_utils.search_xpath(spref_node, "horizsys/geograph") if geograph is not None: self.ui.btn_planar.setChecked(True) self.ui.btn_geographic.setChecked(True) utils.populate_widget_element(self.ui.fgdc_latres, geograph, "latres") utils.populate_widget_element(self.ui.fgdc_longres, geograph, "longres") utils.populate_widget_element(self.ui.fgdc_geogunit, geograph, "geogunit") local = xml_utils.search_xpath(spref_node, "horizsys/local") if local is not None: self.ui.btn_planar.setChecked(True) self.ui.btn_local.setChecked(True) utils.populate_widget_element(self.ui.fgdc_localdes, local, "localdes") utils.populate_widget_element(self.ui.fgdc_localgeo, local, "localgeo") planar = xml_utils.search_xpath(spref_node, "horizsys/planar") if planar is not None: self.ui.btn_grid.setChecked(True) self.ui.btn_planar.setChecked(True) mapproj = xml_utils.search_xpath(planar, "mapproj") if mapproj is not None: self.ui.btn_projection.setChecked(True) utils.populate_widget_element(self.ui.fgdc_mapprojn, mapproj, "mapprojn") mapproj_children = mapproj.getchildren() if len(mapproj_children) > 1: self.mapproj.from_xml(mapproj_children[1]) gridsys = xml_utils.search_xpath(planar, "gridsys") if gridsys is not None: self.ui.btn_grid.setChecked(True) xml_utils.search_xpath(gridsys, "gridsysn") utils.populate_widget_element(self.ui.fgdc_gridsysn, gridsys, "gridsysn") gridsys_children = gridsys.getchildren() if len(gridsys_children) > 1: gridsys_contents = gridsys.getchildren()[1] else: gridsys_contents = [] for item in gridsys_contents.getchildren(): tag = item.tag if spatial_utils.lookup_shortname(tag) is not None: self.grid_mapproj.from_xml(item) elif tag == "mapproj": mapprojn = xml_utils.search_xpath(item, "mapprojn") if mapprojn.text in spatial_utils.PROJECTION_LOOKUP: self.grid_mapproj.from_xml( item.getchildren()[1]) else: item_widget = self.findChild( QLineEdit, "fgdc_" + tag) utils.set_text(item_widget, item.text) grid_proj = gridsys.xpath("proj") localp = xml_utils.search_xpath(planar, "localp") if localp: self.ui.btn_localp.setChecked(True) utils.populate_widget_element(self.ui.fgdc_localpd, localp, "localpd") utils.populate_widget_element(self.ui.fgdc_localpgi, localp, "localpgi") utils.populate_widget_element(self.ui.fgdc_plance, planar, "planci/plance") utils.populate_widget_element(self.ui.fgdc_plandu, planar, "planci/plandu") utils.populate_widget_element(self.ui.fgdc_absres, planar, "planci/coordrep/absres") utils.populate_widget_element(self.ui.fgdc_ordres, planar, "planci/coordrep/ordres") self.planar_changed() geodetic = xml_utils.search_xpath(spref_node, "horizsys/geodetic") if geodetic is not None: utils.populate_widget_element(self.ui.fgdc_horizdn, geodetic, "horizdn") utils.populate_widget_element(self.ui.fgdc_ellips, geodetic, "ellips") utils.populate_widget_element(self.ui.fgdc_semiaxis, geodetic, "semiaxis") utils.populate_widget_element(self.ui.fgdc_denflat, geodetic, "denflat") vertdef = xml_utils.search_xpath(spref_node, "vertdef") if vertdef is not None: self.vertdef.from_xml(vertdef)
def to_xml(self): # add code here to translate the form into xml representation metainfo_node = xml_utils.xml_node("metainfo") metc = xml_utils.xml_node('metc', parent_node=metainfo_node) if self.metd.has_content(): metd = self.metd.to_xml() metainfo_node.append(metd) if self.contactinfo.has_content(): cntinfo = self.contactinfo.to_xml() metc.append(cntinfo) metainfo_node.append(metc) if self.original_xml is not None: metstdn = xml_utils.search_xpath(self.original_xml, "metstdn") metstdv = xml_utils.search_xpath(self.original_xml, "metstdv") if metstdn is not None: metstdn.tail = None metainfo_node.append(deepcopy(metstdn)) metstdv.tail = None metainfo_node.append(deepcopy(metstdv)) else: 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: # metd = xml_utils.xml_node("metd", parent_node=metainfo_node, # text=self.metd.get_date()) # if metd is not None: # metainfo_node.append(deepcopy(metd)) # metrd = xml_utils.search_xpath(self.original_xml, "metrd") # if metrd is not None: # metrd.tail = None # metainfo_node.append(deepcopy(metrd)) # metfrd = xml_utils.search_xpath(self.original_xml, "metfrd") # if metfrd is not None: # metfrd.tail = None # metainfo_node.append(deepcopy(metfrd)) # mettc = xml_utils.search_xpath(self.original_xml, "mettc") # if mettc is not None: # mettc.tail = None # metainfo_node.append(deepcopy(mettc)) # metac = xml_utils.search_xpath(self.original_xml, "metac") # if metac is not None: # metac.tail = None # metainfo_node.append(deepcopy(metac)) # 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 # ) # 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)) # else: # 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) return metainfo_node
def from_xml(self, xml_idinfo): self.original_xml = xml_idinfo citation = xml_utils.search_xpath(xml_idinfo, "citation") if citation is not None: self.citation.from_xml(citation) abstract = xml_utils.search_xpath(xml_idinfo, "descript/abstract") if abstract is not None: self.descript.from_xml(abstract) purpose = xml_utils.search_xpath(xml_idinfo, "descript/purpose") if purpose is not None: self.purpose.from_xml(purpose) supplinf = xml_utils.search_xpath(xml_idinfo, "descript/supplinf") if supplinf is not None: self.supplinf.from_xml(supplinf) timeperd = xml_utils.search_xpath(xml_idinfo, "timeperd") if timeperd is not None: self.timeperd.from_xml(timeperd) status = xml_utils.search_xpath(xml_idinfo, "status") if status is not None: self.status.from_xml(status) spdom = xml_utils.search_xpath(xml_idinfo, "spdom") if spdom is not None: self.root_widget.spatial_tab.spdom.from_xml(spdom) keywords = xml_utils.search_xpath(xml_idinfo, "keywords") if keywords is not None: self.keywords.from_xml(keywords) taxonomy = xml_utils.search_xpath(xml_idinfo, "taxonomy") if taxonomy is not None: self.taxonomy.from_xml(taxonomy) accconst = xml_utils.search_xpath(xml_idinfo, "accconst") if accconst is not None: self.accconst.from_xml(accconst) useconst = xml_utils.search_xpath(xml_idinfo, "useconst") if useconst is not None: self.useconst.from_xml(useconst) ptcontac = xml_utils.search_xpath(xml_idinfo, "ptcontac") if ptcontac is not None: self.ptcontac.from_xml(ptcontac) datacred = xml_utils.search_xpath(xml_idinfo, "datacred") if datacred is not None: self.datacredit.from_xml(datacred) native = xml_utils.search_xpath(xml_idinfo, "native") if native is not None: self.native.from_xml(native) crossref = xml_utils.search_xpath(xml_idinfo, "crossref") if crossref is not None: self.crossref_list.from_xml(xml_idinfo)
def to_xml(self): # add code here to translate the form into xml representation idinfo_node = xml_utils.xml_node('idinfo') citation_node = xml_utils.xml_node('citation', parent_node=idinfo_node) citeinfo_node = self.citation.to_xml() citation_node.append(citeinfo_node) idinfo_node.append(citation_node) descript_node = xml_utils.xml_node('descript', parent_node=idinfo_node) abstract_node = self.descript.to_xml() descript_node.append(abstract_node) purpose_node = self.purpose.to_xml() descript_node.append(purpose_node) supplinf_node = self.supplinf.to_xml() if supplinf_node.text is not None: descript_node.append(supplinf_node) idinfo_node.append(descript_node) timeperd_node = self.timeperd.to_xml() idinfo_node.append(timeperd_node) status_node = self.status.to_xml() idinfo_node.append(status_node) if self.root_widget.use_spatial: spdom_node = self.root_widget.spatial_tab.spdom.to_xml() idinfo_node.append(spdom_node) keywords = self.keywords.to_xml() idinfo_node.append(keywords) if self.schema == 'bdp' and self.taxonomy.has_content(): taxonomy = self.taxonomy.to_xml() idinfo_node.append(taxonomy) accconst_node = self.accconst.to_xml() idinfo_node.append(accconst_node) useconst_node = self.useconst.to_xml() idinfo_node.append(useconst_node) if self.ptcontac.has_content(): ptcontac = self.ptcontac.to_xml() idinfo_node.append(ptcontac) if self.original_xml is not None: browse = xml_utils.search_xpath(self.original_xml, 'browse') if browse is not None: browse.tail = None idinfo_node.append(deepcopy(browse)) datacredit_node = self.datacredit.to_xml() if datacredit_node.text: idinfo_node.append(datacredit_node) if self.original_xml is not None: secinfo = xml_utils.search_xpath(self.original_xml, 'secinfo') if secinfo is not None: secinfo.tail = None idinfo_node.append(deepcopy(secinfo)) if self.native.has_content(): idinfo_node.append(self.native.to_xml()) if self.crossref_list.has_content(): for crossref in self.crossref_list.get_children(): idinfo_node.append(crossref.to_xml()) if self.original_xml is not None: tools = xml_utils.search_xpath(self.original_xml, 'tool', only_first=False) for tool in tools: tool.tail = None idinfo_node.append(deepcopy(tool)) return idinfo_node
def _from_xml(self, xml_idinfo): self.original_xml = (xml_idinfo) citation = xml_utils.search_xpath(xml_idinfo, 'citation') if citation is not None: self.citation._from_xml(citation) abstract = xml_utils.search_xpath(xml_idinfo, 'descript/abstract') if abstract is not None: self.descript._from_xml(abstract) purpose = xml_utils.search_xpath(xml_idinfo, 'descript/purpose') if purpose is not None: self.purpose._from_xml(purpose) supplinf = xml_utils.search_xpath(xml_idinfo, 'descript/supplinf') if supplinf is not None: self.supplinf._from_xml(supplinf) timeperd = xml_utils.search_xpath(xml_idinfo, 'timeperd') if timeperd is not None: self.timeperd._from_xml(timeperd) status = xml_utils.search_xpath(xml_idinfo, 'status') if status is not None: self.status._from_xml(status) spdom = xml_utils.search_xpath(xml_idinfo, 'spdom') if spdom is not None: self.root_widget.spatial_tab.spdom._from_xml(spdom) keywords = xml_utils.search_xpath(xml_idinfo, 'keywords') if keywords is not None: self.keywords._from_xml(keywords) taxonomy = xml_utils.search_xpath(xml_idinfo, 'taxonomy') if taxonomy is not None: self.taxonomy._from_xml(taxonomy) accconst = xml_utils.search_xpath(xml_idinfo, 'accconst') if accconst is not None: self.accconst._from_xml(accconst) useconst = xml_utils.search_xpath(xml_idinfo, 'useconst') if useconst is not None: self.useconst._from_xml(useconst) ptcontac = xml_utils.search_xpath(xml_idinfo, 'ptcontac') if ptcontac is not None: self.ptcontac._from_xml(ptcontac) datacred = xml_utils.search_xpath(xml_idinfo, 'datacred') if datacred is not None: self.datacredit._from_xml(datacred)
def to_xml(self): spref_node = xml_node('spref') horizsys = xml_node('horizsys', parent_node=spref_node) if self.ui.btn_geographic.isChecked(): geograph = xml_node('geograph', parent_node=horizsys) latres_str = self.findChild(QLineEdit, "fgdc_latres").text() xml_node('latres', latres_str, geograph) longres_str = self.findChild(QLineEdit, "fgdc_longres").text() xml_node('longres', longres_str, geograph) geogunit_str = self.findChild(QComboBox, "fgdc_geogunit").currentText() xml_node('geogunit', geogunit_str, geograph) elif self.ui.btn_planar.isChecked(): planar = xml_node('planar', parent_node=horizsys) if self.ui.btn_projection.isChecked(): mapproj = xml_node('mapproj', parent_node=planar) projection_name = self.ui.fgdc_mapprojn.currentText() xml_node('mapprojn', text=projection_name, parent_node=mapproj) proj = self.mapproj.to_xml() mapproj.append(proj) elif self.ui.btn_grid.isChecked(): gridsys = xml_node('gridsys', parent_node=planar) gridsys_name = self.ui.fgdc_gridsysn.currentText() gridsys_info = spatial_utils.GRIDSYS_LOOKUP[gridsys_name] xml_node('gridsysn', text=gridsys_name, parent_node=gridsys) root_node = xml_node(gridsys_info['shortname'], parent_node=gridsys) for item in gridsys_info['elements']: widget = self.findChild(QLineEdit, "fgdc_"+item).text() xml_node(item, text=widget, parent_node=root_node) proj = self.grid_mapproj.to_xml() root_node.append(proj) else: localp = xml_node('localp', parent_node=planar) localpd_str = self.ui.fgdc_localpd.text() xml_node('localpd', localpd_str, parent_node=localp) localpgi_str = self.ui.fgdc_localpgi.text() xml_node('localpgi', localpgi_str, parent_node=localp) planci = xml_node('planci', parent_node=planar) xml_node('plance', text=self.ui.fgdc_plance.currentText(), parent_node=planci) coordrep = xml_node('coordrep', parent_node=planci) xml_node('absres', text=self.ui.fgdc_absres.text(), parent_node=coordrep) xml_node('ordres', text=self.ui.fgdc_ordres.text(), parent_node=coordrep) xml_node('plandu', text=self.ui.fgdc_plandu.currentText(), parent_node=planci) else: local = xml_node('local', parent_node=horizsys) xml_node('localdes', text=self.ui.fgdc_localdes.text(), parent_node=local) xml_node('localgeo', text=self.ui.fgdc_localgeo.text(), parent_node=local) if self.findChild(QComboBox, "fgdc_horizdn").currentText(): geodetic = xml_node('geodetic', parent_node=horizsys) horizdn_str = self.findChild(QComboBox, "fgdc_horizdn").currentText() xml_node('horizdn', horizdn_str, geodetic) ellips_str = self.findChild(QComboBox, "fgdc_ellips").currentText() xml_node('ellips', ellips_str, geodetic) semiaxis_str = self.findChild(QLineEdit, "fgdc_semiaxis").text() xml_node('semiaxis', semiaxis_str, geodetic) denflat_str = self.findChild(QLineEdit, "fgdc_denflat").text() xml_node('denflat', denflat_str, geodetic) if self.original_xml is not None: vertdef = xml_utils.search_xpath(self.original_xml, 'vertdef') if vertdef is not None: vertdef.tail = None spref_node.append(deepcopy(vertdef)) return spref_node