2013-07-26T10:00:00
The datalink response structure, and
the management table for async datalink jobs. For the STREAMs
that have been here in previous DaCHS versions, see //soda.
virtual-observatories
Data links for data sets.
for linkDef in self.sourceToken:
yield linkDef.asDict()
A descriptor generator simply pulling a row from a database
table. This row is made available as the ``.metadata`` attribute.
You also must give a field that the generator will pull a URL
from; the generator arranges things so that the default dlget will
simply redirect there.
Note that the #this and #preview links DaCHS normally makes
for descriptors from products are not added automatically here. Try
to at least provide #this.
See also `Non-Product descriptor Generators`_.
Since DaCHS 2.13, you can define a function ``addExtras(descriptor)`` in
a setup element and add attributes as necessary.
*Since version 2.4.*
base.NotGiven
class FromrowDescriptor(datalink.DatalinkDescriptorMixin):
"""a datalink descriptor just encapsulating a row from
an arbitrary table.
These have, as usual, pubDID and data, where data by default
is just something redirecting to dataURL (or does a 404 if
dataURL is NotGiven).
The row matched is available in the metadata attribute.
You'll usually construct these through its fromDB class
method.
"""
suppressAutoLinks = True
data = None
forSemantics = soda.DEFAULT_SEMANTICS
def __init__(self, pubDID, metadataRow):
self.pubDID, self.metadata = pubDID, metadataRow
@classmethod
def fromDB(cls, did, tableName, idColumn):
if not re.match(r"[\\w_.]+$", tableName):
raise base.StructError(f"Invalid table name {tableName}")
if not re.match(r"[\\w_.]+$", idColumn):
raise base.StructError(f"Invalid column name {idColumn}")
with base.getTableConn() as conn:
rows = list(conn.queryToDicts(
f"select * from {tableName} where {idColumn}=%(did)s",
locals()))
if not rows:
raise svcs.UnknownURI(f"No dataset with id {did} known here")
if len(rows)>1:
raise base.ReportableError(
f"Multiple datasets matched for {did}. Bailing out.",
hint="This is always an operator error – whatever is"
" used as an ID in datalink must be a primary key"
" in the managing table.")
return cls(did, rows[0])
if didPrefix:
if not "://" in pubDID:
pubDID = didPrefix+pubDID
desc = FromrowDescriptor.fromDB(pubDID, tableName, idColumn)
if "addExtras" in globals():
addExtras(desc)
return desc
A table managing datalink jobs submitted
asynchronously (the dlasync renderer)