Warning
This is the documentation for a development version of flagman.
API Reference¶
This part of the documentation covers all of the interfaces exposed by flagman
.
The Action Class¶
This class is the abstract class you should inherit from to write your own actions.
The Core Module¶
These functions and members are imported from the flagman.core
module to be used
if using flagman
as a library instead of a standalone tool.
-
flagman.
HANDLED_SIGNALS
List[signal.Signals]¶ Signals in this list are handled by flagman. The CLI module auto-generates the appropriate CLI option for each signal.
-
flagman.
KNOWN_ACTIONS
Mapping[ActionName, Type[Action]]¶ Mapping of action entry point names to Action classes. Populated from the pkg_resources flagman.action entry point group.
-
flagman.
create_action_bundles
(args_dict)[source]¶ Parse the enabled actions and insert them into the global ACTION_BUNDLES mapping.
The input dictionary should be like:
{'usr1': [['action1', 'arg1a', 'arg2a'], ['action2', 'arg2a']], 'usr2': [['action3'], ['action4', 'arg4a', 'arg4b']]}
Parameters: args_dict ( Mapping
[str
,Iterable
[Sequence
[str
]]]) – a mapping of strings to an Iterable of Action namesReturn type: int
Returns: The number of configured actions
Errors and Exceptions¶
Built-in Actions¶
Print Actions¶
Print actions for flagman.
Most likely only useful for debugging.
-
class
flagman.actions.
PrintAction
(*args)[source]¶ Bases:
flagman.actions.action.Action
A simple Action that prints messages at the various stages of execution.
(message: str)
-
class
flagman.actions.
DelayedPrintAction
(*args)[source]¶ Bases:
flagman.actions.print.PrintAction
An Action that prints messages at the various stages of execution and has a configurable delay in the run stage.
(message: str, delay: int)
Types¶
Type aliases used throughout flagman.
-
flagman.types.
ActionName
¶ Type alias for the name of an Action.
alias of
builtins.str
-
flagman.types.
ActionArgument
¶ Type alias for the the argument to an Action.
alias of
builtins.str
-
flagman.types.
SignalNumber
¶ Type alias for a signal number.
alias of
builtins.int
The CLI Module¶
Module that contains the command line for flagman.
Why does this file exist, and why not put this in __main__? You might be tempted to import things from __main__ later, but that will cause problems–the code will get executed twice:
- When you run python -m flagman python will execute __main__.py as a script. That means there won’t be any flagman.__main__ in sys.modules.
- When you import __main__ it will get executed again (as a module) because there’s no flagman.__main__ in sys.modules.
Also see (1) from http://click.pocoo.org/5/setuptools/#setuptools-integration
-
flagman.cli.
parse_args
(argv)[source]¶ Parse the arguments for the flagman CLI.
Parameters: argv ( Sequence
[str
]) – a Squence of argument stringsReturn type: Namespace
Returns: the parsed arguments as an argparse Namespace
-
flagman.cli.
list_actions
()[source]¶ Pretty-print the list of available actions to stdout.
Return type: None
Systemd Notify Utilities¶
Systemd notification protocol implementation.
-
class
flagman.sd_notify.
SystemdNotifier
(debug=False)[source]¶ This class holds a connection to the systemd notification socket.
It can be used to send messages to systemd using its notify method.
-
__init__
(debug=False)[source]¶ Instantiate a new notifier object.
This will initiate a connection to the systemd notification socket.
Normally this method silently ignores exceptions (for example, if the systemd notification socket is not available) to allow applications to function on non-systemd based systems. However, setting debug=True will cause this method to raise any exceptions generated to the caller, to aid in debugging.
Return type: None
-
notify
(state)[source]¶ Send a notification to systemd.
State is a string; see the man page of sd_notify (http://www.freedesktop.org/software/systemd/man/sd_notify.html) for a description of the allowable values.
Normally this method silently ignores exceptions (for example, if the systemd notification socket is not available) to allow applications to function on non-systemd based systems. However, setting debug=True will cause this method to raise any exceptions generated to the caller, to aid in debugging.
Return type: None
-