command_watcher¶
Module to watch the execution of shell scripts. Both streams (stdout and stderr) are captured.
watch = Watch()
watch.log.critical(msg)
watch.log.error(msg)
watch.log.warning(msg)
watch.log.info(msg)
watch.log.debug(msg)
watch.run(['rsync', '-av', '/home', '/backup'])
- class jflib.command_watcher.BeepChannel[source]¶
Send beep sounds.
- exception jflib.command_watcher.CommandWatcherError(msg, **data)[source]¶
Exception raised by this module.
- class jflib.command_watcher.EmailChannel(smtp_server, smtp_login, smtp_password, to_addr, from_addr='', to_addr_critical='')[source]¶
Send reports by e-mail.
- class jflib.command_watcher.LoggingHandler(master_logger=None)[source]¶
Store of all logging records in the memory. Print all records on emit.
- property all_records¶
All log messages joined by line breaks.
- property stderr¶
- property stdout¶
- class jflib.command_watcher.Message(**data)[source]¶
This message class bundles all available message data into an object. The different reporters can choose which data they use.
- class jflib.command_watcher.Process(args, master_logger=None, **kwargs)[source]¶
Run a process.
You can use all keyword arguments from
subprocess.Popen
except bufsize, stderr, stdout.- Parameters
args (
Union
[str
,List
[str
],Tuple
[str
]]) – List, tuple or string. A sequence of process arguments, like subprocess.Popen(args).
- args: Args¶
Process arguments in various types.
- log: ExtendedLogger¶
A ready to go and configured logger.
- log_handler: LoggingHandler¶
- subprocess: subprocess.Popen[Any]¶
- class jflib.command_watcher.Reporter[source]¶
Collect all channels.
- channels: List[BaseChannel]¶
- class jflib.command_watcher.Timer[source]¶
Measure the execution time of a command run.
- interval¶
The time interval between start and stop.
- result()[source]¶
Measure the time intervale
- Returns
A formatted string displaying the result.
- Return type
- start¶
“The start time. (UNIX timestamp)
- stop¶
“The time when the timer stops. (UNIX timestamp)
- class jflib.command_watcher.Watch(config_file=None, service_name='command_watcher', raise_exceptions=True, config_reader=None, report_channels=None)[source]¶
Watch the execution of a command. Capture all output of a command. provide and setup a logging facility.
- Parameters
config_file (
Optional
[str
]) – The file path of the configuration file in the INI format.service_name (
str
) – A name of the watched service.raise_exceptions (
bool
) – Raise exceptions if watch.run() exists with a non-zero exit code.config_reader (
Optional
[ConfigReader
]) – A custom configuration reader. Specify this parameter to not use the build in configuration reader.
- log: ExtendedLogger¶
A ready to go and configured logger.
- processes: List[Process]¶
A list of completed processes
Process
. Everytime you use the method run() the process object is appened in the list.
- property stderr¶
Alias / shortcut for self._log_handler.stderr.
- property stdout¶
Alias / shortcut for self._log_handler.stdout.