# 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`

  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`()

    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`()

    Implementation of the diff command.

  `do_get`()

    Implementation of the get command.

  `do_help`()

    Implementation of the help command.

  `do_list`()

    Implementation of the list command.

  `do_load`()

    Implementation of the load command.

  `do_remove`()

    Implementation of the remove command.

  `do_rename`()

    Implementation of the rename command.

  `do_save`()

    Implementation of the save command.

  `do_set`()

    Implementation of the set command.

  `do_show`()

    Implementation of the show command.

  `do_status`()

    Implementation of the status command.

  static `invalid_config`(*exc)

    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`()

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

  static `overridden_config`(*exc)

    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)

    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.

  property `commands`

    A dictionary mapping command names to their sub-parser.

  property `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.

  property `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.

  property `store`

    The `Store` containing the current and stored boot configurations.