Doer Manager

The DoerManager class is responsible for orchestrating the doers.

Commands for the different types of doers, for example the Shell doer, are provided to this class, which are then parsed and converted to their respective doer instances. The default doer is also taken into account for commands that don’t explicitly specify a doer.

As an example, the following code would parse out the command specified as the first argument and create a Shell doer from it.

>>> manager = DoerManager(['shell:echo "%f changed!"'], Shell)

In the above case, the shell: prefix wasn’t necessary, as the default doer (the second argument) was already set to Shell.

All of the doers can be run by calling the run_doers() method.

>>> manager.run_doers('my_file.txt')
class watch_do.doer_manager.DoerManager(commands, default_doer)[source]

This class creates and manages doers.

Commands are passed in, which then get parsed and converted to instances of doers. All doers can be run using the run_doers() method with relevant output returned.

Initialise the DoerManager and parse all commands.

The commands that get passed into this class are parsed (removing their doer: prefix if required) and have the relevant doer instances created for them.

Parameters:
  • commands (list) – A list of strings containing the commands to create doers for. Each command (str) in the list of commands should be prefixed with doer:, where ‘doer’ is the name of the doer (i.e. shell). If the command is not prefixed with doer: the default_doer will be used.
  • default_doer (Doer) – A reference to a doer class to use as the default doer if one is not explicitly specified using the doer: prefix.
commands

list – The list of stings that this DoerManager is managing.

default_doer

Doer – The doer that is used if one is explicitly specified in the command.

doers

list – The doers that were created as a result of passing the commands.

run_doers(file_name)[source]

Run each doer in turn and yield its output.

Yields:

str

A string that contains the combined output of stdout and

stderr from the doers.