| 1 |
""" |
| 2 |
Common code and definitions for registry support. |
| 3 |
""" |
| 4 |
|
| 5 |
#c Copyright 2008-2025, the GAVO project <[email protected]> |
| 6 |
#c |
| 7 |
#c This program is free software, covered by the GNU GPL. See the |
| 8 |
#c COPYING file in the source distribution. |
| 9 |
|
| 10 |
|
| 11 |
from gavo import base |
| 12 |
from gavo.utils import stanxml |
| 13 |
|
| 14 |
|
| 15 |
SERVICELIST_ID = "__system__/services" |
| 16 |
|
| 17 |
|
| 18 |
METADATA_PREFIXES = [ |
| 19 |
# (prefix, schema-location, namespace) |
| 20 |
("oai_dc", stanxml.schemaURL("OAI-PMH.xsd"), |
| 21 |
"http://www.openarchives.org/OAI/2.0/oai_dc/"), |
| 22 |
("ivo_vor", stanxml.schemaURL("VOResource-v1.0.xsd"), |
| 23 |
"http://www.ivoa.net/xml/RegistryInterface/v1.0"), |
| 24 |
] |
| 25 |
|
| 26 |
|
| 27 |
class OAIError(base.Error): |
| 28 |
"""is one of the standard OAI errors. |
| 29 |
""" |
| 30 |
|
| 31 |
class BadArgument(OAIError): pass |
| 32 |
class BadResumptionToken(OAIError): pass |
| 33 |
class BadVerb(OAIError): pass |
| 34 |
class CannotDisseminateFormat(OAIError): pass |
| 35 |
class IdDoesNotExist(OAIError): pass |
| 36 |
class NoMetadataFormats(OAIError): pass |
| 37 |
class NoSetHierarchy(OAIError): pass |
| 38 |
class NoRecordsMatch(OAIError): pass |
| 39 |
|
| 40 |
|
| 41 |
def getServicesRD(): |
| 42 |
return base.caches.getRD(SERVICELIST_ID) |
| 43 |
|
| 44 |
|
| 45 |
def getResType(resob): |
| 46 |
res = base.getMetaText(resob, "resType", default=None) |
| 47 |
if res is None: |
| 48 |
res = resob.resType |
| 49 |
return res |
| 50 |
|
| 51 |
|
| 52 |
def getDependencies(rdId, connection=None): |
| 53 |
"""returns a list of RD ids that are need for the generation of RRs |
| 54 |
from rdId. |
| 55 |
""" |
| 56 |
if connection is None: |
| 57 |
with base.getTableConn() as conn: |
| 58 |
return getDependencies(rdId, conn) |
| 59 |
|
| 60 |
return [r[0] for r in |
| 61 |
connection.query(getServicesRD().getById("res_dependencies") |
| 62 |
.getSimpleQuery(["prereq"], "rd=%(rd)s"), {"rd": rdId})] |
| 63 |
|
| 64 |
|
| 65 |
__all__ = ["SERVICELIST_ID", "METADATA_PREFIXES", |
| 66 |
|
| 67 |
"getResType", "getServicesRD", "getDependencies", |
| 68 |
|
| 69 |
"OAIError", "BadArgument", "BadResumptionToken", "BadVerb", |
| 70 |
"CannotDisseminateFormat", "IdDoesNotExist", |
| 71 |
"NoMetadataFormats", "NoSetHierarchy", |
| 72 |
"NoRecordsMatch", |
| 73 |
] |