def __init__(self, element): Contributor.__init__(self, element) self.type = 'organization' organization = XmlUtils.getChild('organization', element) if not organization: raise Exception, 'organization not found in %s' % self.element.toxml( ) self.instName = XmlUtils.getChildText(organization, 'instName') self.instDept = XmlUtils.getChildText(organization, 'instDept') self.instEmail = XmlUtils.getChildText(organization, 'instEmail')
def __init__(self, element): Contributor.__init__(self, element) self.type = 'person' person = XmlUtils.getChild('person', element) if not person: raise Exception, 'person not found in %s' % self.element.toxml() self.nameFirst = XmlUtils.getChildText(person, 'nameFirst') self.nameLast = XmlUtils.getChildText(person, 'nameLast') self.instName = XmlUtils.getChildText(person, 'instName') self.instDept = XmlUtils.getChildText(person, 'instDept') self.emailPrimary = XmlUtils.getChildText(person, 'emailPrimary')
def __init__(self, element): self.lastName = XmlUtils.getChildText(element, "lastName") self.firstName = XmlUtils.getChildText(element, "firstName") try: self.order = int(element.getAttribute("order")) except: self.order = 1000 self.role = element.getAttribute("role") self.upid = element.getAttribute("UCARid") self.affiliations = map( Affiliation, XmlUtils.getChildElements(element, 'affiliation'))
def __init__(self, element): # print element.toxml() self.element = element self.id = element.getAttribute("xml:id") self.asnUri = self.getChildByTypeAttr('DocumentID', 'asnUri') self.asnPurl = self.getChildByTypeAttr('DocumentID', 'asnPurl') self.title = XmlUtils.getChildText(self.element, 'DocumentTitle') self.uid = os.path.basename(self.asnUri) self.author = XmlUtils.getChildText(self.element, 'DocumentJurisdiction') self.topic = XmlUtils.getChildText(self.element, 'DocumentSubject') self.created = XmlUtils.getChildText(self.element, 'LocalAdoptionDate') self.status = XmlUtils.getChildText(self.element, 'PublicationStatus')
def downloadtester(): # path ="H:/python-lib/ncar_lib/WebCatMetadata/Monographs/MONOGRAPH-000-000-000-280.xml" collection = "NCAR Technical Notes" mdFileName = "TECH-NOTE-000-000-000-233.xml" mdPath = os.path.join(collectionsDir, collection, mdFileName) rec = WebCatRecord(mdPath) anum = XmlUtils.getChildText(rec.doc, "accessionNum") url = XmlUtils.getChildText(rec.doc, "url") print "Accession #: " + anum print "url: " + url print "path: " + rec.path dest = os.path.join("pdf", rec.accessionNum + ".pdf") rec.download(dest)
def getResponse (self, preprocessor=None): """ simply return response from server as an XmlRecord instance """ response = ServiceClient.getResponse (self, preprocessor) if not response.hasError(): # now test for CAT error error = response.doc.selectSingleNode (response.doc.dom, 'CATWebService:Error') if error: statusMessage = XmlUtils.getChildText (error, "StatusMessage") returnCode = XmlUtils.getChildText (error, "ReturnCode") response.error = CatResponseError ([statusMessage, returnCode]) #self.result = response.doc return response
def showRec(rec): print "\n", rec.getId() print "- ", rec.get('title') authors = rec.getAuthors() if authors: authors.sort(lambda a, b: cmp(XmlUtils.getChildText(a, "lastName"), XmlUtils.getChildText(b, "lastName"))) # print "- authors" authorList = [] for author in authors: authorList.append("%s, %s" % (XmlUtils.getChildText(author, "lastName"), XmlUtils.getChildText(author, "firstName"))) print "- " + ", ".join(authorList) # for author in authors: # print " - %s, %s" % (XmlUtils.getChildText (author, "lastName"), # XmlUtils.getChildText (author, "firstName")) print "- " + rec.get('pubName')
def __init__ (self, element): Contributor.__init__ (self, element) for attr in self.simple_child_tags: setattr (self, attr, XmlUtils.getChildText (element, attr)) try: self.order = int(element.getAttribute ("order")) except: self.order = "" self.upid = element.getAttribute ("UCARid")
def __init__(self, element, unit): self.unit = unit self.name = urllib.unquote(XmlUtils.getChildText( element, 'Name')) # take the %20s out source = XmlUtils.getChild('WorksheetSource', element) self.href = urllib.unquote( source.getAttribute('HRef')) # take the %20s out self.data_path = os.path.join(utils.ingest_data_dir, self.unit, self.href)
def _get_phy_extent(self): if not self.did.physdescElements: return self.extent # default if len(self.did.physdescElements) > 1: raise Exception, "item %d has %d physdescElements" % ( self.id, len(self.did.physdescElements)) physdesc = self.did.physdescElements[0] extent = XmlUtils.getChildText(physdesc, "extent") if extent: return extent.strip()
def __init__ (self, element): self.element = element self.lastName = XmlUtils.getChildText (element, "lastName") self.firstName = XmlUtils.getChildText (element, "firstName") try: self.order = int(element.getAttribute ("order")) except: self.order = 1000 self.role = element.getAttribute ("role") self.upid = element.getAttribute ("UCARid") for baseField in self.affiliationFields: for suffix in self.affiliationLevels: field = baseField + suffix if baseField == 'instDivision': val = map (XmlUtils.getText, XmlUtils.getChildElements(element, field)) else: val = XmlUtils.getChildText (element, field) or "" setattr (self, field, val) if 0 and val: print "%s: %s" % (field, val)
def _get_field(self, qName): try: return XmlUtils.getChildText(self.doc, qName) except: msg = "_get_field error: %s" % sys.exc_info()[1] raise Exception, msg
def getId (self): """ this method cannot be called until after finalizeXml has executed """ return XmlUtils.getChildText (self.doc, "recordID")
def getAccessionNum (self): """ this method cannot be called until the record has been populated (AccessionNum is a derived element name) """ return XmlUtils.getChildText (self.doc, "accessionNum")
def getInstName (self): return XmlUtils.getChildText(self.element, 'instName')
def __init__(self, element): self.instName = XmlUtils.getChildText(element, "instName") self.instDivisions = self.get_inst_divs(element) self.instProject = XmlUtils.getChildText(element, "instProject")
def __init__(self, element): self.path = element.getAttribute("path") for attr in self.attrs: val = XmlUtils.getChildText(element, attr).strip() setattr(self, attr, val)
def getNameLast(self): return XmlUtils.getChildText(self.element, 'nameLast')
def getAccessionNum(self, rec): return XmlUtils.getChildText(rec.doc, "AccessionNum") self.recordCount = self.recordCount + 1
def __init__(self, element): self.id = element.getAttribute("id") self.name = XmlUtils.getChildText(element, "name") self.homeurl = XmlUtils.getChildText(element, "homeurl")
def get(self, tag): return XmlUtils.getChildText(self.element, tag)