utils¶
Utility functions for OTEAPI DLite plugin.
RemoveItem
¶
Singleton class used by update_dict() to indicate items that should be removed in the source dictionary.
Source code in oteapi_dlite/utils/utils.py
282 283 284 |
|
TypeMismatchError
¶
Bases: TypeError
Raised by update_dict() if there is a mismatch in value types
between the dct
and update
dictionaries.
Source code in oteapi_dlite/utils/utils.py
276 277 278 279 |
|
add_settings(session, label, settings)
¶
Store settings to the session.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session
|
Union[dict[str, Any], None]
|
An OTEAPI session object. |
required |
label
|
str
|
Label of settings to add. |
required |
settings
|
Union[dict, list, str, int, float, bool, NoneType]
|
A JSON-serialisable Python object with the settings to store. |
required |
Returns:
Type | Description |
---|---|
SessionUpdate
|
A SessionUpdate instance with the added settings. |
Source code in oteapi_dlite/utils/utils.py
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 |
|
get_collection(session=None, collection_id=None)
¶
Retrieve a DLite Collection.
Looks for a Collection UUID in the session. If none exists, a new, empty Collection is created and stored in the session.
If collection_id
is provided, that id is used. If there already is a
collection_id
in the session, that is left untouched. Otherwise
collection_id
is added to the session.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session
|
Optional[dict[str, Any]]
|
An OTEAPI session object. |
None
|
collection_id
|
Optional[str]
|
A specific collection ID to retrieve. |
None
|
Return
A DLite Collection to be used throughout the OTEAPI session.
Source code in oteapi_dlite/utils/utils.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
|
get_driver(mediaType=None, accessService=None)
¶
Return name of DLite driver for the given media type/access service.
Source code in oteapi_dlite/utils/utils.py
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
|
get_instance(meta, session=None, collection=None, routedict=None, instance_id=None, allow_incomplete=False, **kwargs)
¶
Instantiates and returns an instance of meta
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
meta
|
Union[str, Metadata]
|
Metadata to instantiate. Typically its URI. |
required |
session
|
Optional[dict[str, Any]]
|
An OTEAPI session object. |
None
|
collection
|
Optional[Collection]
|
The collection with instances and mappings.
The default is to get the collection from |
None
|
Some less used optional arguments
routedict: Dict mapping property names to route number to select for the given property. The default is to select the route with lowest cost. instance_id: URI of instance to create. allow_incomplete: Whether to allow not populating all properties of the returned instance. kwargs: Additional arguments passed to dlite.mappings.instantiate().
Source code in oteapi_dlite/utils/utils.py
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
|
get_meta(uri)
¶
Returns metadata corresponding to given uri.
This function may in the future be connected to a database.
Source code in oteapi_dlite/utils/utils.py
119 120 121 122 123 124 125 126 127 |
|
get_settings(session, label)
¶
Retrieve settings from the session.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session
|
Union[dict[str, Any], None]
|
An OTEAPI session object. |
required |
label
|
str
|
Label of settings to retrieve. |
required |
Returns:
Type | Description |
---|---|
Any
|
Python object with the settings or None if no settings exists |
Any
|
with this label. |
Source code in oteapi_dlite/utils/utils.py
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 |
|
get_triplestore(session)
¶
Return a tripper.Triplestore instance for the current session.
If a 'tripper.triplestore' setting has been added with the SettingsStrategy, it will be used to configure the returned triplestore instance. Otherwise the session collection will be used.
Source code in oteapi_dlite/utils/utils.py
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 |
|
update_collection(collection)
¶
Update collection in DataCache.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection
|
Collection
|
The DLite Collection to be updated. |
required |
Source code in oteapi_dlite/utils/utils.py
109 110 111 112 113 114 115 116 |
|
update_dict(dct, update)
¶
Update dictionary dct
using dictionary update
.
This function differ from dict.update()
in that it updates
sub-directories recursively, instead of replacing them with the
content of update
.
If update
has RemoveItem
as a value, the corresponding item
in dct
will be removed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dct
|
dict
|
Dict to update. |
required |
update
|
Optional[dict]
|
Dict used to update |
required |
Returns:
Type | Description |
---|---|
dict
|
The updated dict |
Raises:
Type | Description |
---|---|
TypeMismatchError
|
If there is a mismatch in value types
between the |
Source code in oteapi_dlite/utils/utils.py
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 |
|