pibootctl.main

The pibootctl.main module defines the Application class, and an instance of this called main. Instances of Application are callable and thus main is the entry-point for the pibootctl script.

From an API perspective, this module is primarily useful for providing an instance of the Store class:

from pibootctl.main import main
from pibootctl.store import Store, Current, Default

store = main.store
store[Current] = store['foo']
pibootctl.main.main

The instance of Application which is the entry-point for the pibootctl script.

class pibootctl.main.Application[source]

An instance of this class (main) is the entry point for the application. The instance is callable, accepting the command line arguments as its single (optional) argument. The arguments will be derived from sys.argv if not provided:

>>> from pibootctl.main import main
>>> try:
...     main(['-h'])
... except SystemExit:
...     pass
usage:  [-h] [--version]
{help,?,status,dump,get,set,save,load,diff,show,cat,list,ls,remove,rm,rename,mv}
...

Warning

Calling main will raise SystemExit in several cases (usually when requesting help output). It will also replace the system exception hook (sys.excepthook()).

This is intended and by design. If you wish to use pibootctl as an API, you are better off investigating the Store class, or treating pibootctl as a self-contained script and calling it with subprocess.

backup_if_needed()[source]

Tests whether the active boot configuration is also present in the store (by checking for the calculated hash). If it isn’t, constructs a unique filename (backup-<timestamp>) and saves a copy of the active boot configuration under it.

do_diff()[source]

Implementation of the diff command.

do_get()[source]

Implementation of the get command.

do_help()[source]

Implementation of the help command.

do_list()[source]

Implementation of the list command.

do_load()[source]

Implementation of the load command.

do_remove()[source]

Implementation of the remove command.

do_rename()[source]

Implementation of the rename command.

do_save()[source]

Implementation of the save command.

do_set()[source]

Implementation of the set command.

do_show()[source]

Implementation of the show command.

do_status()[source]

Implementation of the status command.

static invalid_config(*exc)[source]

Generates the error message for unhandled InvalidConfiguration exceptions. These are caused when a configuration fails to validate, and have an errors attribute listing all the exceptions that occurred during validation.

mark_reboot_required()[source]

Writes the necessary files to indicate that the system requires a reboot.

static overridden_config(*exc)[source]

Generates the error message for unhandled IneffectiveConfiguration exceptions. These are caused when a boot configuration is split across multiple files; the application is permitted to modify a file before the final one, but a later file overrides a value the application has tried to set in the file it is permitted to modify.

static permission_error(*exc)[source]

Generates the error message for unhandled PermissionError exceptions. As these are very likely to be caused by non-root execution, this is customzied to warn about this in the event that the effective UID is not 0.

commands

A dictionary mapping command names to their sub-parser.

config

Returns the script’s configuration as derived from the files in the three pre-defined locations (see pibootctl for more information). Returns a Namespace containing the parsed configuration.

parser

The parser for all the sub-commands that the script accepts. The parser’s defaults are derived from the configuration obtained from config. Returns the newly constructed argument parser.

store

The Store containing the current and stored boot configurations.