lc_resource
LcResource
Bases: object
This is a record that links a semantic reference to a physical data source, and specifies the capabilities (and someday, access limitations) of the data source.
The LcResource serializes to a json file with the following format: { ref: [ { "dataSource": source, "dataSourceType": ds_type, .... }, ... ] } where ref is the semantic reference.
__init__(origin, source, ds_type, interfaces=None, privacy=0, priority=50, static=False, preload_archive=None, config=None, **kwargs)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
origin |
semantic reference to data origin |
required | |
source |
physical data source; 'None' allowed if 'downloadLink' argument provided |
required | |
ds_type |
data source type |
required | |
interfaces |
list which can include 'entity', 'foreground', or 'background'. Default 'foreground' |
None
|
|
privacy |
Ignored / No longer used. |
0
|
|
priority |
[50] priority level.. numeric (nominally 0-100), lowest priority resource is loaded first |
50
|
|
static |
[False] if True, load_all() after initializing |
False
|
|
preload_archive |
[None] use to assign an existing archive |
None
|
|
config |
ConfigureInterface specifications |
None
|
|
kwargs |
additional keyword arguments to constructor. Some interesting ones: download: a dict containing 'url' and optional 'md5sum' fields prefix: often used when accessing zipped archives token: a jwt used for authenticating to xdb 'options': popped with values used as kwargs (per ResourceSpec) |
{}
|
from_dict(ref, d)
classmethod
Returns a single LcResource loaded from a dict. only required field is 'dataSourceType'. other fields are passed to the constructor and either interpreted directly or added as supplemental args
If 'dataSource' is not present, one had better hope that url is present in the dict to download the source
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ref |
|
required | |
d |
|
required |
Returns:
Type | Description |
---|---|
|
from_file(file)
classmethod
generates LcResources contained in the named file, sorted by increasing priority. The filename and the reference must be the same.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file |
|
required |
Returns:
Type | Description |
---|---|
an ordered list of resources |
matches(k)
Pretty cheesy. When we serialize a set of resources, we need to make sure not to include self twice. To make the comparison concrete, use a serialized resource as input.
We were using dataSource as a unique identifier for resource entries; but the introduction of download links breaks that because a downloadable resource has no source until it's been downloaded. The solution is to fallback to download.url ONLY IF the resource has no source specified.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
k |
a serialized LcResource |
required |
Returns:
Type | Description |
---|---|
|
write_to_file(path, assign_ref=None, apply_config=None)
Adds the resource to a file whose name is the resource's semantic reference. If the same datasource is already present in the file, replace it with the current resource. otherwise append.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
directory to store the resource file. |
required | |
assign_ref |
assign this ref instead of the resource's current ref |
None
|
|
apply_config |
overwrites configuration with supplied dict |
None
|
Returns:
Type | Description |
---|---|
|
ResourceInvalid
Bases: Exception
resource points to an invalid filename