def test_get_usgs_contact_info(): assert 'fgdc_cntperp' in utils.get_usgs_contact_info('talbertc') bad = utils.get_usgs_contact_info('bad') assert bad['fgdc_cntperp']['fgdc_cntper'].strip() == '' cnt_info = utils.get_usgs_contact_info('talbertc', as_dictionary=False) assert cnt_info.getchildren()[0].getchildren()[0].text == 'Colin Talbert'
def test_get_usgs_contact_info(): fgdc_cntinfo = utils.get_usgs_contact_info("talbertc") if not "fgdc_error" in fgdc_cntinfo: assert "fgdc_cntperp" in utils.get_usgs_contact_info("talbertc") bad = utils.get_usgs_contact_info("bad") assert bad["fgdc_cntperp"]["fgdc_cntper"].strip() == "" cnt_info = utils.get_usgs_contact_info("talbertc", as_dictionary=False) assert cnt_info.getchildren()[0].getchildren( )[0].text == "Colin Talbert"
def add_contact(self): username = self.usgs_contact_ui.le_usgs_ad_name.text() # strip off the @usgs.gov if they entered one username = username.split("@")[0] if not username: return try: cntperp = utils.get_usgs_contact_info(username, as_dictionary=False) if cntperp.getchildren()[0].getchildren()[0].text.strip(): self.from_xml(cntperp) self.usgs_contact.deleteLater() else: msg = QMessageBox(self) utils.set_window_icon(msg) msg.setIcon(QMessageBox.Information) msg.setText("'{}' Not Found".format(username)) msg.setInformativeText("The Metadata Wizard was unable to locate the provided user name in the USGS directory") msg.setWindowTitle("Name Not Found") msg.setStandardButtons(QMessageBox.Ok) msg.exec_() except: msg_text = "Make sure there is a working Internet connection or try again latter." msg = QMessageBox(self) utils.set_window_icon(msg) msg.setIcon(QMessageBox.Information) msg.setText("Issue encountered while searching contact information.") msg.setInformativeText(msg_text) msg.setWindowTitle("Problem encountered") msg.setStandardButtons(QMessageBox.Ok) msg.exec_()
def __init__( self, username=None, password=None, hash="593af2e0e4b0764e6c602207", parent=None, mainform=None, ): self.mainform = mainform if username is None: try: username = getpass.getuser() contact = utils.get_usgs_contact_info(username, True) self.username = contact["fgdc_cntemail"] except: self.username = "" else: self.username = username QWidget.__init__(self, parent=parent) self.ui = UI_sb_locator.Ui_Form() # .Ui_USGSContactInfoWidgetMain() self.ui.setupUi(self) self.password = password self.hash = hash self.ui.username.setText(self.username) self.ui.password.setText(password) self.ui.hash.setText(hash) self.setWindowTitle("ScienceBase Item/User Identifier") self.connect_events()
def pull_datasetcontact(self): try: sb_info = utils.get_usgs_contact_info("sciencebase", as_dictionary=False) self.contactinfo.from_xml(sb_info) except: msg = "Having trouble getting sciencebase contact info now.\n" msg += "Check internet connection or try again latter." QMessageBox.warning(self, "Problem encountered", msg)
def add_contact(self): username = self.usgs_contact_ui.le_usgs_ad_name.text() # strip off the @usgs.gov if they entered one username = username.split("@")[0] cntperp = utils.get_usgs_contact_info(username, as_dictionary=False) if cntperp.getchildren()[0].getchildren()[0].text.strip(): self._from_xml(cntperp) self.usgs_contact.deleteLater() else: msg = QMessageBox(self) msg.setIcon(QMessageBox.Information) msg.setText("'{}' Not Found".format(username)) msg.setInformativeText( "The Metadata Wizard was unable to locate the provided user name in the USGS directory" ) msg.setWindowTitle("Name Not Found") msg.setStandardButtons(QMessageBox.Ok) msg.exec_()
def generate_review_report(xml_document, docx_fname, which="bdp"): document = Document() DOCX = "{http://schemas.openxmlformats.org/wordprocessingml/2006/main}" element = document.settings.element.find(DOCX + "proofState") element.attrib[DOCX + "grammar"] = "dirty" element.attrib[DOCX + "spelling"] = "dirty" _load_styles(document) title_str = "Metadata Review for:\n\t{}" try: title_str = xml_document.metadata.idinfo.citation.citeinfo.title.text except: title_str = ( "No FGDC Title found in record at metadta/idinfo/citation/citeinfo/title" ) title = document.add_heading("Metadata Review for:", level=2) title.style = document.styles["fgdc heading 2"] title.paragraph_format.line_spacing = 1 title2 = document.add_paragraph("\t" + title_str + "\n", style="fgdc tag content") bar = title2.add_run("_" * 72) document.add_paragraph("") reviewinfoline = document.add_heading("Review Info:", level=3) reviewinfoline.style = document.styles["review content heading"] fname = os.path.split(xml_document.fname)[-1] _add_tag(document, "Metadata file being reviewed", fname, tag_style="fgdc bold") try: username = getpass.getuser() contact = utils.get_usgs_contact_info(username, True) reviewer_str = "{} ({})".format(contact["fgdc_cntperp"]["fgdc_cntper"], contact["fgdc_cntemail"]) except: # something when wrong getting the contact info # (no internet, non USGS, etc), just insert placeholcers reviewer_str = "<<insert reviewer name>> (<<insert reviewer email>>)" _add_tag(document, "Reviewer", reviewer_str, tag_style="fgdc bold") _add_tag(document, "Review Date", time.strftime("%m/%d/%Y"), tag_style="fgdc bold") document.add_paragraph("") summaryline = document.add_heading("Summary:", level=3) summaryline.style = document.styles["review content heading"] document.add_paragraph("<<insert general review comments here>>", style="fgdc tag content") document.add_paragraph("", style="fgdc tag content") document.add_paragraph("", style="fgdc tag content") errorline = document.add_heading("FGDC Schema Errors:", level=3) errorline.style = document.styles["review content heading"] errors = format_errors(xml_document, which) if errors: document.add_paragraph("Error (XML Path to error)", style="fgdc tag") for error in errors: e = document.add_paragraph("\t{}\n\t({})".format( error[1], error[0]), style="fgdc tag content") else: document.add_paragraph("\tNo Schema Errors found", style="fgdc tag") document.add_paragraph("") mdcontentline = document.add_heading("Metadata Content:", level=3) mdcontentline.style = document.styles["review content heading"] bar = document.add_paragraph("_" * 72, style="fgdc bar") title2 = document.add_heading("Metadata:", level=3) title2.style = document.styles["fgdc heading 3"] for child in xml_document.metadata.children: long_name = _get_longname(child.tag) link = document.add_paragraph(text=long_name, style="fgdc link") link.paragraph_format.left_indent = Inches(0.5) link.paragraph_format.line_spacing = 1 for child in xml_document.metadata.children: long_name = _get_longname(child.tag) bar = document.add_paragraph("_" * 72, style="fgdc bar") section_title = document.add_heading(long_name + ":", level=3) section_title.style = document.styles["fgdc heading 3"] section_title.paragraph_format.space_after = Inches(0.15) _add_child_content(document, child) document.save(docx_fname)
def generate_review_report(xml_document, docx_fname, which='bdp'): document = Document() DOCX = '{http://schemas.openxmlformats.org/wordprocessingml/2006/main}' element = document.settings.element.find(DOCX + 'proofState') element.attrib[DOCX + 'grammar'] = 'dirty' element.attrib[DOCX + 'spelling'] = 'dirty' _load_styles(document) title_str = "Metadata Review for:\n\t{}" try: title_str = xml_document.metadata.idinfo.citation.citeinfo.title.text except: title_str = "No FGDC Title found in record at metadta/idinfo/citation/citeinfo/title" title = document.add_heading("Metadata Review for:", level=2) title.style = document.styles['fgdc heading 2'] title.paragraph_format.line_spacing = 1 title2 = document.add_paragraph("\t"+title_str+'\n', style='fgdc tag content') bar = title2.add_run('_'*72) document.add_paragraph('') reviewinfoline = document.add_heading('Review Info:', level=3) reviewinfoline.style = document.styles['review content heading'] fname = os.path.split(xml_document.fname)[-1] _add_tag(document, "Metadata file being reviewed", fname, tag_style='fgdc bold') try: username = getpass.getuser() contact = utils.get_usgs_contact_info(username, True) reviewer_str = "{} ({})".format(contact['fgdc_cntperp']['fgdc_cntper'], contact['fgdc_cntemail']) except: # something when wrong getting the contact info # (no internet, non USGS, etc), just insert placeholcers reviewer_str ="<<insert reviewer name>> (<<insert reviewer email>>)" _add_tag(document, "Reviewer", reviewer_str, tag_style='fgdc bold') _add_tag(document, "Review Date", time.strftime("%m/%d/%Y"), tag_style='fgdc bold') document.add_paragraph('') summaryline = document.add_heading('Summary:', level=3) summaryline.style = document.styles['review content heading'] document.add_paragraph('<<insert general review comments here>>', style='fgdc tag content') document.add_paragraph('', style='fgdc tag content') document.add_paragraph('', style='fgdc tag content') errorline = document.add_heading('FGDC Schema Errors:', level=3) errorline.style = document.styles['review content heading'] errors = format_errors(xml_document, which) if errors: document.add_paragraph('Error (XML Path to error)', style='fgdc tag') for error in errors: e = document.add_paragraph('\t{}\n\t({})'.format(error[1], error[0]), style='fgdc tag content') else: document.add_paragraph('\tNo Schema Errors found', style='fgdc tag') document.add_paragraph('') mdcontentline = document.add_heading('Metadata Content:', level=3) mdcontentline.style = document.styles['review content heading'] bar = document.add_paragraph('_'*72, style='fgdc bar') title2 = document.add_heading('Metadata:', level=3) title2.style = document.styles['fgdc heading 3'] for child in xml_document.metadata.children: long_name = _get_longname(child.tag) link = document.add_paragraph(text=long_name, style='fgdc link') link.paragraph_format.left_indent = Inches(0.5) link.paragraph_format.line_spacing=1 for child in xml_document.metadata.children: long_name = _get_longname(child.tag) bar = document.add_paragraph('_'*72, style='fgdc bar') section_title = document.add_heading(long_name+ ':', level=3) section_title.style = document.styles['fgdc heading 3'] section_title.paragraph_format.space_after = Inches(.15) _add_child_content(document, child) document.save(docx_fname)