radloggerpy.common.first_time_run module

class radloggerpy.common.first_time_run.FirstTimeRun[source]

Bases: object

Handles service wide first time initialization

FirstTimeRun should not be instantiated until all checks and tasks have been added. The FirstTimeRun will perform checks and if necessary perform all tasks upon construction.

Individual tasks should do basic checks before performing that task as it could otherwise potentially re-initialize. This is due to a limitation in FirstTimeRun were there is no correlation between tasks and checks. The result is that even though it can be determined initialization is in order it can not be determined due to which check.

Tasks and checks can be added globally by typing:

FirstTimeRun.add_task(task) FirstTimeRun.add_check(check)

If stronger coupling between tasks and checks is required use:

FirstTimeRun.add_check_task(check, task)

Since these can only be defined after the definition of class methods it might be necessary to add the statements to the bottom of the file. Take into account that these global statements are only executed if the file in which the reside is included in the main file.

Alternatively, a separate file can be created to handle all these registrations. This has as advance that all registrations can be observed in one overview. Additionally, it will provide cleaner imports since only the declaring files has all the combinations of imports. This has the potential to solve circular dependencies.

Finally, if unused imports are undesired all the registrations can be performed in the main file.

class CheckTask(check, task)[source]

Bases: object

Wrapper for associative check and task pair

check = None
task = None
_check_tasks = [<radloggerpy.common.first_time_run.FirstTimeRun.CheckTask object>]
_checks = []
_run_check_tasks()[source]

Run each of the checks and tasks as a pair

_run_checks(all_to_init=False)[source]

Run all checks from the internal list

Parameters:

all_to_init – True if all checks are required to init False if one check is sufficient

Returns:

True if first time init should be run False otherwise

_run_tasks()[source]

Will try to execute all calls from the internal list

_tasks = []
static _validate_check_task(obj)[source]

Validate the object as much as possible

Has the limitation that it does not verify check() return type to be boolean.

static add_check(check)[source]
static add_check_task(check, task)[source]
static add_task(task)[source]