obsinfo.misc package
obsinfo.misc.configuration
obsinfo.misc.const
Exit values as constants as per UNIX BSD standard
obsinfo.misc.datapath
- class obsinfo.misc.datapath.Datapath(datapath=None)
Bases:
objectClass to discover where information files are stored.
- datapath_list
directories where information files will be searched, in sequence
- Type:
list of str
- infofiles_path
same as datapath_list, used by validate, kept for compatibility
- Type:
list of str
- validate_path
one unique path to validation schemas
- Type:
str
- static add_frag(path, frag)
Add the path and the frag to restore a partial or complete uri
- Parameters:
path (str) – path portion of uri, possibly with other elements but without frag
frag (str) – fragment portion of uri
- Returns:
- (str) path with frag. If there is no frag and path ends with
.{something}.{suffix} , returns path + “#” + {something}
- build_datapath(file)
Create list of directories which may have data or schemas
If the file path is absolute, return the file itself.
If path starts by ./ or ../ complete to an absolute path using working directory
If the file has no prefix discover whether file exists in the datapath list. Use the first found file.
- Parameters:
file (str or path) – filename of file to be found
- Returns:
found file as string
- Raises:
FileNotFoundError –
obsinfo.misc.jsonref
This is the online jsonref library, v0.2
- WCC had to change one line in order to subclass it:
callback() had an absolute reference that had to be changed to relative (marked “# WCC”)
- class obsinfo.misc.jsonref.JsonLoader(store=(), cache_results=True)
Bases:
objectProvides a callable which takes a URI, and returns the loaded JSON referred to by that URI. Uses
requestsif available for HTTP URIs, and falls back tourllib. By default it keeps a cache of previously loaded documents.- Parameters:
store – A pre-populated dictionary matching URIs to loaded JSON documents
cache_results – If this is set to false, the internal cache of loaded JSON documents is not used
- get_remote_json(uri, **kwargs)
- class obsinfo.misc.jsonref.JsonRef(refobj, base_uri='', loader=None, jsonschema=False, load_on_repr=True, _path=(), _store=None)
Bases:
LazyProxyA lazy loading proxy to the dereferenced data pointed to by a JSON Reference object.
- callback()
- property full_uri
- classmethod replace_refs(obj, _recursive=False, **kwargs)
Returns a deep copy of obj with all contained JSON reference objects replaced with
JsonRefinstances.- Parameters:
obj – If this is a JSON reference object, a
JsonRefinstance will be created. If obj is not a JSON reference object, a deep copy of it will be created with all contained JSON reference objects replaced byJsonRefinstancesbase_uri – URI to resolve relative references against
loader – Callable that takes a URI and returns the parsed JSON (defaults to global
jsonloader, aJsonLoaderinstance)jsonschema – Flag to turn on JSON Schema mode. ‘id’ keyword changes the base_uri for references contained within the object
load_on_repr – If set to
False,repr()call on aJsonRefobject will not cause the reference to be loaded if it hasn’t already. (defaults toTrue)
- resolve_pointer(document, pointer)
Resolve a json pointer
pointerwithin the referenceddocument.- Parameters:
document – the referent document
pointer (str) – a json pointer URI fragment to resolve within it
- exception obsinfo.misc.jsonref.JsonRefError(message, reference, uri='', base_uri='', path=(), cause=None)
Bases:
Exception
- obsinfo.misc.jsonref.dump(obj, fp, **kwargs)
Serialize obj, which may contain
JsonRefobjects, as a JSON formatted stream to file-like fp. JsonRef objects will be dumped as the original reference object they were created from.- Parameters:
obj – Object to serialize
fp – File-like to output JSON string
kwargs – Keyword arguments are the same as to
json.dump()
- obsinfo.misc.jsonref.dumps(obj, **kwargs)
Serialize obj, which may contain
JsonRefobjects, to a JSON formatted string. JsonRef objects will be dumped as the original reference object they were created from.- Parameters:
obj – Object to serialize
kwargs – Keyword arguments are the same as to
json.dumps()
- obsinfo.misc.jsonref.load(fp, base_uri='', loader=None, jsonschema=False, load_on_repr=True, **kwargs)
Drop in replacement for
json.load(), where JSON references are proxied to their referent data.- Parameters:
fp – File-like object containing JSON document
kwargs – This function takes any of the keyword arguments from
JsonRef.replace_refs(). Any other keyword arguments will be passed tojson.load()
- obsinfo.misc.jsonref.load_uri(uri, base_uri=None, loader=None, jsonschema=False, load_on_repr=True)
Load JSON data from
uriwith JSON references proxied to their referent data.- Parameters:
uri – URI to fetch the JSON from
kwargs – This function takes any of the keyword arguments from
JsonRef.replace_refs()
- obsinfo.misc.jsonref.loads(s, base_uri='', loader=None, jsonschema=False, load_on_repr=True, **kwargs)
Drop in replacement for
json.loads(), where JSON references are proxied to their referent data.- Parameters:
s – String containing JSON document
kwargs – This function takes any of the keyword arguments from
JsonRef.replace_refs(). Any other keyword arguments will be passed tojson.loads()
obsinfo.misc.printobs module
Functions to print obsinfo objects
- class obsinfo.misc.printobs.PrintObs
Bases:
objectCollection of methods to print obsinfo objects at different levels of depth. All methods are static.
- \*None*
- static print_component(obj, level='all')
Prints comoponent information and continues if level is not “component” or “channel”.
If level is not “channel” detailed equipment information is not printed.
- Parameters:
level (str) – determines to which level the obsinfo object will be printed
- static print_instrumentation(obj, level='all')
Prints instrumentation information and continues if level is not “instrumentation”.
If level is “response” or “all” response stages information will be printed (if it exists). Recall at this point all the response is gathered in
instrument.stages.sgatesIf level is “all” or “filter” (i.e. not “response”) all information will be printed (only filter is left at this point…)- Parameters:
level (str) – determines to which level the obsinfo object will be printed
- static print_network(obj, level='all')
Prints network information and continues if level is not “network”.
- Parameters:
level (str) – determines to which level the obsinfo object will be printed
- static print_station(obj, level='all')
Prints station information and continues if level is not “station”.
- Parameters:
level (str) – determines to which level the obsinfo object will be printed
obsinfo.misc.remoteGitLab module
- class obsinfo.misc.remoteGitLab.gitLabFile
Bases:
objectProvide the methods to use the gitlab API to read a remote file and decode it
- \*None*
- static get_gitlab_file(uri, read_file=True)
Get the file content pointed at by uri and decode it.
Uses b64 first to get the remote file and convert to a byte string, and then utf-8 to convert to regular string.
- Parameters:
uri (string or path-like) – uri to read
(bool) (read_file) – If true, reads the content. If not, simply checks if the file exists
- Returns:
read content
- Return type:
(str)
Raises: FileNotFoundError, ValueError
- static isRemote(file)
Checks if scheme means file is remote.
- Parameters:
file (str) – filename to be checked, with complete uri
- Returns:
boolean. True if remote, False otherwise
obsinfo.misc.yamlref module
Module to read and parse YAML or JSON files, locally or remotely (gitlab only)
subclasses “jsonref”, adding YAML reading and datapath discovery
- class obsinfo.misc.yamlref.YAMLLoader(store=(), cache_results=True)
Bases:
JsonLoaderAdds YAML read
- get_remote_json(uri, **kwargs)
Adds yaml read and possibility to get a gitlab remote file (using gitlab API version 4)
- class obsinfo.misc.yamlref.YAMLRef(*args, **kwargs)
Bases:
JsonRefDatapath-aware version of JsonRef
- Additional Attributes:
datapath (
Datapath): stores directories to search for files
- __init__(*args, **kwargs)
- property full_uri
This method/property returns the full uri to reference a
$refobject. It’s the heart of how a datapath is used to either access a local or remote (gitlab) file. All schema files are supposed to be local, part of the obsinfo distribution- Returns:
updated full uri
- Raises:
ValueError
- obsinfo.misc.yamlref.dump(*args, **kwargs)
- obsinfo.misc.yamlref.dumps(*args, **kwargs)
- obsinfo.misc.yamlref.load(fp, base_uri='', loader=None, jsonschema=False, load_on_repr=True, datapath=None, **kwargs)
jsonref:load() plus datapath and yaml reading
- Parameters:
datapath (
Datapath) – object to implement file discovery
- obsinfo.misc.yamlref.load_uri(uri, base_uri=None, loader=None, jsonschema=False, load_on_repr=True, datapath=None)
jsonref:load_uri() plus datapath and yaml reading
- Parameters:
datapath (
Datapath) – object to implement file discovery- Returns:
parsed YAML or JSON formats
- Return type:
newref (dict)
- obsinfo.misc.yamlref.loads(s, base_uri='', loader=None, jsonschema=False, load_on_repr=True, datapath=None, recursive=True, **kwargs)
jsonref:loads() plus datapath and yaml reading
- Parameters:
datapath (
Datapath) – object to implement file discovery