Utility
Contents
Utility#
This module bundles mostly technical utilities that might not be all this interesting for users.
Interface
#
Utils for the command line interface (CLI).
- clusterking.util.cli.yn_prompt(question: str, yes=None, no=None) bool [source]#
Ask yes-no question.
- Parameters
question – Description of the prompt
yes – List of strings interpreted as yes
no – List of strings interpreted as no
- Returns
True if yes, False if no.
- clusterking.util.cli.handle_overwrite(paths, behavior, log)[source]#
Do we want to overwrite a file that exists?
- Parameters
paths – List of pathlib.Paths
behavior – How to proceed if output file already exists: ‘ask’, ‘overwrite’, ‘raise’
log – logging.Logger instance
- Returns
True if overwrite will occur, False otherwise.
Log
#
Defines an easy function to set up a logger.
- clusterking.util.log.get_logger(name='Logger', level=30, sh_level=30)[source]#
Sets up a logging.Logger.
If the colorlog module is available, the logger will use colors, otherwise it will be in b/w. The colorlog module is available at https://github.com/borntyping/python-colorlog but can also easily be installed with e.g. ‘sudo pip3 colorlog’ or similar commands.
- Parameters
name – name of the logger
level – General logging level
sh_level – Logging level of stream handler
- Returns
Logger
Metadata
#
Miscellaneous utilities
- clusterking.util.metadata.nested_dict()[source]#
This is very clever and stolen from https://stackoverflow.com/questions/16724788/ Use it to initialize a dictionary-like object which automatically adds levels. E.g.
a = nested_dict() a['test']['this']['is']['working'] = "yaaay"
- clusterking.util.metadata.turn_into_nested_dict(nested)[source]#
Turn a dictionary of dictionaries into a nested_dict default dict.
- clusterking.util.metadata.get_git_info(log=None, path=None)[source]#
Return dictionary containing status of the git repository (commit hash, date etc.
- Parameters
log – logging.Logger object (optional)
path – path to .git subfolder or search path (optional)
- Returns
dictionary
- clusterking.util.metadata.save_git_info(output_path=None, *args, **kwargs) Dict[str, str] [source]#
Save output of git_info to a file.
- Parameters
output_path – Output path. If None, the default will be bclustering/git_info.json
*args – Passed on to git_info
**kwargs – Passed on to git_info
- Returns
Output of git_info
- clusterking.util.metadata.load_git_info(input_path=None) Dict[str, str] [source]#
Load previously saved output of git_info from a json file.
- Parameters
input_path – Input path to json file. If None, the default will be bclustering/git_info.json
- Returns
Parsed json file (should be identical to saved output of version_info).