Util

Project helpers, and associated functionality which have no home.

Disk Registry

gordo.util.disk_registry.delete_value(registry_dir: Union[os.PathLike, str], key: str) → bool[source]

Deletes the value with key reg_key from the registry, and returns True if it existed.

Parameters
  • registry_dir (Union[os.PathLike, str]) – Path to the registry. Does not need to exist

  • key (str) – Key to look up in the registry.

Returns

True if the key existed, false otherwise

Return type

bool

gordo.util.disk_registry.get_value(registry_dir: Union[os.PathLike, str], key: str) → Optional[AnyStr][source]

Retrieves the value with key reg_key from the registry, None if it does not exists.

Parameters
  • registry_dir (Union[os.PathLike, str]) – Path to the registry. If it does not exist we return None

  • key (str) – Key to look up in the registry.

Returns

The value of key in the registry, None if no value is registered with that key in the registry.

Return type

Optional[AnyStr]

gordo.util.disk_registry.logger = <Logger gordo.util.disk_registry (WARNING)>

A simple file-based key/value registry. Each key gets a file with filename = key, and the content of the file is the value. No fancy. Why? Simple, and there is no problems with concurrent writes to different keys. Concurrent writes to the same key will break stuff.

gordo.util.disk_registry.write_key(registry_dir: Union[os.PathLike, str], key: str, val: AnyStr)[source]

Registers a key-value combination into the register. Key must valid as a filename.

Parameters
  • registry_dir (Union[os.PathLike, str]) – Path to the registry. If it does not exists it will be created, including any missing folders in the path.

  • key (str) – Key to use for the key/value. Must be valid as a filename.

  • val (AnyStr) – Value to write to the registry.

Examples

In the following example we use the temp directory as the registry >>> import tempfile >>> with tempfile.TemporaryDirectory() as tmpdir: … write_key(tmpdir, “akey”, “aval”) … get_value(tmpdir, “akey”) ‘aval’

Utils

gordo.util.utils.capture_args(method: Callable)[source]

Decorator that captures args and kwargs passed to a given method. This assumes the decorated method has a self, which has a dict of kwargs assigned as an attribute named _params.

Parameters

method (Callable) – Some method of an object, with ‘self’ as the first parameter.

Returns

Returns whatever the original method would return

Return type

Any