本文整理汇总了Python中oaipmh.metadata.MetadataRegistry.registerWriter方法的典型用法代码示例。如果您正苦于以下问题:Python MetadataRegistry.registerWriter方法的具体用法?Python MetadataRegistry.registerWriter怎么用?Python MetadataRegistry.registerWriter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oaipmh.metadata.MetadataRegistry
的用法示例。
在下文中一共展示了MetadataRegistry.registerWriter方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
# 需要导入模块: from oaipmh.metadata import MetadataRegistry [as 别名]
# 或者: from oaipmh.metadata.MetadataRegistry import registerWriter [as 别名]
def setUp(self):
super(BookMetadataTest, self).setUp()
xml = path.join(path.dirname(__file__), 'files/lubie-kiedy-kobieta.xml')
self.book = models.Book.from_xml_file(xml)
xml = path.join(path.dirname(__file__), 'files/antygona.xml')
self.book2 = models.Book.from_xml_file(xml)
mr = MetadataRegistry()
self.catalogue = Catalogue(mr)
mr.registerWriter('oai_dc', oai_dc_writer)
nsmap = {'oai_dc': NS_OAIDC, 'dc': NS_DC, 'xsi': NS_XSI}
self.xml = XMLTreeServer(self.catalogue, mr, nsmap)
示例2: Cheshire3OaiServer
# 需要导入模块: from oaipmh.metadata import MetadataRegistry [as 别名]
# 或者: from oaipmh.metadata.MetadataRegistry import registerWriter [as 别名]
class Cheshire3OaiServer(object):
"""A server object complying with the oaipmh module's API."""
protocolMap = None
db = None
def __init__(self, session, configs, dbs, dbName):
self.session = session
self.protocolMap = configs[dbName]
self.db = dbs[dbName]
session.database = self.db.id
# Get some generally useful stuff now
self.baseURL = self.protocolMap.baseURL
# Get earliest datestamp in database - UTC of the epoch as query term
q = cqlparse('rec.lastModificationDate > "%s"'
'' % (str(datetime.datetime.utcfromtimestamp(0))))
try:
tl = self.db.scan(session, q, 1)
except SRWDiagnostics.Diagnostic16:
raise ConfigFileException('Index map for '
'rec.lastModificationDate required '
'in protocolMap: %s'
'' % self.db.get_path(session,
'protocolMap').id
)
else:
try:
datestamp = tl[0][0]
except IndexError:
# Something went wrong :( - use the epoch
self.earliestDatestamp = datetime.datetime.utcfromtimestamp(0)
else:
try:
self.earliestDatestamp = datetime.datetime.strptime(
datestamp,
'%Y-%m-%dT%H:%M:%S'
)
except ValueError:
self.earliestDatestamp = datetime.datetime.strptime(
datestamp,
'%Y-%m-%d %H:%M:%S'
)
self.repositoryName = self.protocolMap.title
self.protocolVersion = self.protocolMap.version
self.adminEmails = self.protocolMap.contacts
# Check for deletion support
recordStore = self.db.get_path(session, 'recordStore')
deletions = recordStore.get_setting(session, 'storeDeletions')
# Cheshire3 cannot guarantee that deletions will persist
self.deletedRecord = "transient" if deletions else "no"
# Finest level of granularity
self.granularity = "YYYY-MM-DDThh:mm:ssZ"
# Cheshire3 does not support compressions at this time
self.compression = []
self.metadataRegistry = OaiMetadataRegistry()
def getRecord(self, metadataPrefix, identifier):
"""Return a (header, metadata, about) tuple for the the record.
metadataPrefix - identifies metadata set to retrieve the record in
identifier - repository-unique identifier of record
Should raise error.CannotDisseminateFormatError if metadataPrefix
is unknown or not supported by identifier.
Should raise error.IdDoesNotExistError if identifier is unknown or
illegal.
"""
session = self.session
if (
metadataPrefix and not
(metadataPrefix in self.protocolMap.recordNamespaces)
):
raise CannotDisseminateFormatError()
if not self.metadataRegistry.hasWriter(metadataPrefix):
# Need to create a 'MetadataWriter' for this schema for oaipmh to
# use, and put in self.metadataRegister
schemaId = self.protocolMap.recordNamespaces[metadataPrefix]
txr = self.protocolMap.transformerHash.get(schemaId, None)
mdw = Cheshire3OaiMetadataWriter(txr)
self.metadataRegistry.registerWriter(metadataPrefix, mdw)
q = cqlparse('rec.identifier exact "%s"' % (identifier))
try:
rs = self.db.search(session, q)
except SRWDiagnostics.Diagnostic16:
raise ConfigFileException('Index map for rec.identifier required '
'in protocolMap: %s'
'' % self.db.get_path(session,
'protocolMap').id
)
if not len(rs) or len(rs) > 1:
raise IdDoesNotExistError('%s records exist for this identifier'
'' % (len(rs)))
r = rs[0]
# Handle non-ascii characters in identifier
#.........这里部分代码省略.........
示例3: SubElement
# 需要导入模块: from oaipmh.metadata import MetadataRegistry [as 别名]
# 或者: from oaipmh.metadata.MetadataRegistry import registerWriter [as 别名]
nsmap={'oai_dc': NS_OAIDC, 'dc': NS_DC, 'xsi': NS_XSI, 'dcterms': NS_DCTERMS}
map = metadata.getMap()
for name in [
'title', 'creator', 'subject', 'description', 'publisher',
'contributor', 'date', 'type', 'format', 'identifier',
'source', 'language', 'relation', 'coverage', 'rights',
]:
for value in map.get(name, []):
e = SubElement(element, nsdc(name), nsmap=nsmap)
e.text = value
for name in ['hasPart', 'isPartOf']:
for value in map.get(name, []):
e = SubElement(element, nsdcterms(name), nsmap=nsmap)
e.text = value
metadata_registry = MetadataRegistry()
metadata_registry.registerWriter('oai_dc', fbc_oai_dc_writer)
metadata_registry.registerWriter('qdc', qdc_writer)
server = ServerBase(Catalogue(metadata_registry), metadata_registry,
{'topxsi': NS_XSI})
def oaipmh(request):
resp = server.handleRequest(request.GET)
return HttpResponse(resp, content_type='application/xml')
示例4: showSets
# 需要导入模块: from oaipmh.metadata import MetadataRegistry [as 别名]
# 或者: from oaipmh.metadata.MetadataRegistry import registerWriter [as 别名]
def showSets(self, provider):
iterator = provider.listSets()
print "Provider Name: %s \n" % provider._name
for header, metadata, about in iterator:
print "setSpec: {:<30} \t setName: {}".format(header, metadata)
if __name__ == '__main__' :
registry = MetadataRegistry()
registry.registerReader('oai_dc', oai_dc_reader)
registry.registerReader('qdc', qdc_reader)
registry.registerWriter('oai_dc', oai_dc_writer)
date_patern = compile(REGEX_DATE)
if not exists(BASE_PATH):
makedirs(BASE_PATH)
parser = argparse.ArgumentParser(
description='Make harvest from any repositories and save the metadata in file system')
group = parser.add_mutually_exclusive_group(required=True)
group.add_argument(
'-u', '--url', type=str, default=None, metavar='OAI provider URL',
help='an alternative URL for harvesting. Ignore settings file')