kentauros.init package

Submodules

kentauros.init.cli module

This module contains functions for constructing an argparse command line argument parser, and parsing the determined command line arguments. It also contains classes which provide methods that return parsed CLI arguments, depending on where the kentauros module is used from.

class kentauros.init.cli.CLIArgs[source]

Bases: object

This class represents the parsed command line arguments and switches used with a kentauros script. It stores the parsed CLI arguments between class instantiations (in a class variable), so the CLI will be parsed only once. It also provides simple method calls for getting settings from the parsed CLI.

args = None

This class variable contains the permanent (instance-independent) storage of parsed CLI arguments. It is initially set to None and generated at the time of the first class initialisation.

Type:ArgumentParser
get_action() → kentauros.definitions.ActionType[source]

This method returns which package action has been specified at the command line. If this is None, something went wrong and no action type will be returned.

Returns:ActionType – type of action that will be executed
get_debug() → bool[source]

This method simply returns whether the –debug or -d switch has been set at the command line.

Returns:bool – debug on or off
get_force() → bool[source]

This method simply returns whether the –force or -f switch has been set at the command line.

Returns:bool – force package actions on or off
get_message() → str[source]

This method returns the changelog message specified by command line argument.

Returns:str – specified changelog message
get_packages() → list[source]

This method returns all the package names which were collected from the CLI arguments.

Returns:list – specified packages in a list
get_packages_all() → bool[source]

This method simply returns whether the –all or -a switch has been set at the command line.

Returns:bool – parse all packages on or off
get_remove() → bool[source]

This method simply returns whether the –remove or -r switch has been set at the command line.

Returns:bool – remove package from database as part of cleanup on or off
get_verby() → int[source]

This method returns how often the –verbose or -v switch has been set at the command line, subtracted from 2. This results in a lowest verbosity level of 2 (comparable to –quiet), a medium verbosity level of 1 (normal verbosity) and a high verbosity level of 0 (very verbose).

Returns:int – verbosity level (0 to 2)
parser = None
kentauros.init.cli.get_cli_parser(cli_parser: argparse.ArgumentParser) → argparse.ArgumentParser[source]

This function constructs and returns a parser for command line arguments, which is used for “normal” execution (e.g. invoking the ktr script).

The arguments parsed by this parser include those from the basic parser, and, additionally:

  • package name(s) to specify which packages to process explicitly
  • –all (-a) switch to enable processing all packages in CONFDIR
  • –force (-f) switch to force actions which would not be executed
Parameters:cli_parser (ArgumentParser) – basic argument parser got from get_cli_parser_base()
Returns:ArgumentParser – CLI argument parser for ktr script
kentauros.init.cli.get_cli_parser_base() → argparse.ArgumentParser[source]

This function constructs and returns a basic parser for command line arguments, which will be further processed and added to by other functions.

The arguments parsed by this basic parser include:

  • –debug (-d) switch to enable debug messages in kentauros
  • –verbose (-v, -vv) switch to control how many informational messages will be printed (twice for extra verbosity)
Returns:ArgumentParser – basic CLI argument parser
kentauros.init.cli.package_name_completer(prefix, **kwargs)[source]

This function returns a list of package names (found in the package configs directory by glob) that start with the ‘prefix’ argument.

Parameters:prefix (str) – string prefix
Returns:list – list of matching package names

kentauros.init.env module

This module contains simple functions for parsing environment variables needed for basic functions and determining debug and verbosity level.

kentauros.init.env.get_env_debug() → bool[source]

This function returns True if the “KTR_DEBUG” environment variable was set to anything parse-able to True by python. If not (or the variable has not been set), it returns False.

Returns:bool – debug on or off
kentauros.init.env.get_env_home() → str[source]

This function tries to get the home directory of the user running ktr. If the HOME variable is not set, the current directory is used.

Returns:str – environment variable for HOME or the current directory
kentauros.init.env.get_env_verby() → int[source]

This function returns the parsed value of the KTR_VERBOSITY environment variable (anything parse-able to an int by python. If it has not been set, it will return 2 (the lowest verbosity level).

Returns:int – verbosity level

Module contents

This subpackage contains functions for parsing environment variables and the functions necessary for getting and parsing command line arguments, which are then held in the CLIArgs class.