clap.utils

Module Contents

Classes

CLAPFilter

Filter instances are used to perform arbitrary filtering of LogRecords.

Singleton

Creates a single instance class

Functions

defaultdict_to_dict(d)

float_time_to_string(timespec)

get_logger(name)

get_random_name(in_use_names = None, retries = 10)

get_random_object()

path_extend(*args)

setup_log(name = 'clap', verbosity_level = 0, filename = None)

sorted_groupby(iterable, key=None)

str_at_middle(text, maximum, delimiter = '-')

tmpdir(suffix=None, prefix='clap.', dir = None, remove = True)

yaml_load(filename)

Attributes

APP_NAME

clap.utils.APP_NAME = clap
class clap.utils.CLAPFilter(name='')

Bases: logging.Filter

Filter instances are used to perform arbitrary filtering of LogRecords.

Loggers and Handlers can optionally use Filter instances to filter records as desired. The base filter class only allows events which are below a certain point in the logger hierarchy. For example, a filter initialized with “A.B” will allow events logged by loggers “A.B”, “A.B.C”, “A.B.C.D”, “A.B.D” etc. but not “A.BB”, “B.A.B” etc. If initialized with the empty string, all events are passed.

Initialize a filter.

Initialize with the name of the logger which, together with its children, will have its events allowed through the filter. If no name is specified, allow every event.

filter(self, record)

Determine if the specified record is to be logged.

Is the specified record to be logged? Returns 0 for no, nonzero for yes. If deemed appropriate, the record may be modified in-place.

class clap.utils.Singleton

Bases: type

Creates a single instance class

_instances
__call__(cls, *args, **kwargs)

Call self as a function.

clap.utils.defaultdict_to_dict(d)
clap.utils.float_time_to_string(timespec)
Parameters

timespec (float) –

clap.utils.get_logger(name)
clap.utils.get_random_name(in_use_names=None, retries=10)
Parameters
  • in_use_names (List[str]) –

  • retries (int) –

Return type

str

clap.utils.get_random_object()
Return type

str

clap.utils.path_extend(*args)
Return type

str

clap.utils.setup_log(name='clap', verbosity_level=0, filename=None)
Parameters
  • name (str) –

  • verbosity_level (int) –

  • filename (str) –

clap.utils.sorted_groupby(iterable, key=None)
Parameters

iterable (Iterable) –

Return type

dict

clap.utils.str_at_middle(text, maximum, delimiter='-')
Parameters
  • text (str) –

  • maximum (int) –

  • delimiter (str) –

clap.utils.tmpdir(suffix=None, prefix='clap.', dir=None, remove=True)
Parameters
  • dir (str) –

  • remove (bool) –

clap.utils.yaml_load(filename)
Parameters

filename (str) –

Return type

dict