deepcave.runs.handler

# Handler

This module provides utilities to handle a run.

It can retrieve working directories, run paths, run names, as well as groups of runs. It provides utilities to update and remove runs as well as groups of runs.

# Classes
  • RunHandler: Handle the runs.

Classes

RunHandler(config, cache, run_cache)

Handle the runs.

class deepcave.runs.handler.RunHandler(config, cache, run_cache)[source]

Bases: object

Handle the runs.

Based on the meta data in the cache, automatically selects the right converter and switches to the right (plugin) cache.

Provides utilities to retrieve working directories, run paths, run names, and groups of runs. Also update and remove runs as well a groups of runs.

Properties

cCache

The cache containing information about a run(s).

rcRunCaches

The caches for the selected runs.

loggerLogger

The logger for the run handler.

available_run_yfesList[Type[Run]]

A list of the available converters.

runsDict[str, AbstractRun]

A dictionary of runs with their path as key.

groupsDict[str, Group]

A dictionary of the groups.

available_run_classesList[Type[Run]]

Contains the available run classes.

add_run(run_path)[source]

Add a run path to the cache.

If run path is already in cache, do nothing.

Parameters:

run_path (str) – Path of a run.

Returns:

True if all selected runs could be loaded, False otherwise.

Return type:

bool

get_available_run_paths()[source]

Return the available run paths from the current directory.

Return type:

Dict[str, str]

Returns:

  • Dict[str, str] – Run path as key and run name as value.

  • Exceptions

  • ———-

  • FileNotFoundError

get_groups()[source]

Return instantiated grouped runs.

Returns:

Instances of grouped runs.

Return type:

List[GroupedRun]

get_run(run_id)[source]

Look inside self.runs and self.groups and if the run id is found, returns the run.

Parameters:

run_id (str) – Internal id of the run. Referred to run.id.

Returns:

Run.

Return type:

AbstractRun

Raises:

RuntimeError – If run_id was not found in self.runs or self.groups.

get_run_name(run_path)[source]

Return the stem of the path.

Parameters:

run_path (Union[Path, str]) – Path, which should be converted to a name.

Returns:

Run name of the path.

Return type:

str

get_runs(include_groups=False)[source]

Return the runs from the internal cache.

The runs are already loaded and ready to use. Optional, if include_groups is set to True, the groups are also included.

Parameters:

include_groups (bool, optional) – Includes the groups, by default False.

Returns:

Instances of runs.

Return type:

List[AbstractRun]

get_selected_groups()[source]

Get the selected groups.

Returns:

Dictionary with the selected groups.

Return type:

Dict[str, List[str]]

Raises:

AssertionError – If groups in cache is not a dictionary, an error is thrown.

get_selected_run_names()[source]

Return the run names of the selected runs.

Returns:

List of run names of the selected runs.

Return type:

List[str]

get_selected_run_paths()[source]

Return the selected run paths from the cache.

Returns:

Run paths as a list.

Return type:

List[str]

Raises:

AssertionError. – If the selected run paths are not a list, an error is thrown.

get_working_directory()[source]

Return the current working directory in the cache.

Returns:

Path of the working directory.

Return type:

Path

Raises:

AssertionError – If the working directory is not a string or a Path, an error is thrown.

remove_run(run_path)[source]

Remove a run path from the cache.

If run path is not in cache, do nothing.

Parameters:

run_path (str) – Path of a run.

Raises:

TypeError – If selected_run_paths or groups is None, an error is thrown.

Return type:

None

set_working_directory(working_directory)[source]

Set the working directory to the meta cache.

Parameters:

working_directory (Union[Path, str]) – Directory to be set.

Return type:

None

update()[source]

Update the internal run and group instances but only if a hash changed.

Return type:

None

update_groups(groups=None)[source]

Load chosen groups.

If groups is passed, it is used to instantiate the groups and saved to the cache. Otherwise, groups is loaded from the cache.

Parameters:

groups (Optional[Dict[str, str]], optional) – A dictionary with the groups. Default is None.

Raises:
  • NotMergeableError – If runs can not be merged, an error is thrown.

  • TypeError – If groups is None, an error is thrown.

Return type:

None

update_run(run_path, class_hint=None)[source]

Load the run from self.runs or create a new one.

Parameters:
  • run_path (str) – The path of the run.

  • class_hint (Optional[Type[Run]], optional) – A hint/suggestion of what the Type of the Run is. Default is None.

Returns:

The Run added to the cache.

Return type:

Optional[AbstractRun]

Raises:

NotValidRunError – If directory can not be transformed into a run, an error is thrown.

update_runs()[source]

Load selected runs and update cache if files changed.

Returns:

True if all selected runs could be loaded, False otherwise.

Return type:

bool

Raises:

NotValidRunError – If directory can not be transformed into a run, an error is thrown.