pestifer.core.command module

Class for handling and running external commands and managing their output.

class pestifer.core.command.Command(command: str, *args, **options)[source]

Bases: object

Class for running external commands in a subprocess. This class allows you to create a command with its arguments and options, and then run it while capturing its output. The command is run in a shell, and you can specify a logfile to write the output to. If the command returns a non-zero exit code, an error is logged, and the stdout and stderr buffers are printed. You can also specify a tuple of (needle, message) to override the default behavior and log a custom message if the needle is found in the stdout or stderr. The command can be run with a progress bar and elapsed time display using a LogParser instance. The command can also be run quietly, suppressing the output to the console.

divider_line_length = 55

The length of the divider line used in logging output to separate sections of the log.

run(logfile=None, override=(), ignore_codes=[], quiet=True, logparser: LogParser = None, log_stderr=False, **kwargs)[source]

Runs this Command instance

Parameters:
  • logfile (str) – name of log file to write process’ stdout and stderr. If None (default), stdout and stderr are retained only in this instance’s stdout and stderr attributes.

  • override (tuple) – tuple composed of a “needle” and a “message”. If the needle is found in the stdout or stderr of the process, the message is displayed and an error is thrown, halting the program.

  • ignore_codes (list) – a list of integer exit codes that are ignored in addition to 0

  • quiet (bool) – if True, suppresses all output from the command

  • logparser (LogParser) – used for progress bar/elapsed time displays and log parsing