From c709a28d08387fdb9caa952a5b201baef156553e Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Mon, 21 Jun 2021 21:56:11 -0700 Subject: [PATCH] Add operatornotify.main_decorator to reduce application boilerplate. --- voussoirkit/operatornotify.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/voussoirkit/operatornotify.py b/voussoirkit/operatornotify.py index 5ffd882..a1da4d1 100644 --- a/voussoirkit/operatornotify.py +++ b/voussoirkit/operatornotify.py @@ -163,6 +163,19 @@ class LogHandlerContext: self.handler.notify() self.log.removeHandler(self.handler) +def main_decorator(subject, *args, **kwargs): + ''' + Add this decorator to your application's main function to automatically + wrap it in a main_log_context. + ''' + def wrapper(main): + def wrapped(argv): + (context, argv) = main_log_context(argv, subject, *args, **kwargs) + with context: + return main(argv) + return wrapped + return wrapper + def main_log_context(argv, subject, *args, **kwargs): ''' This function is for accelerating the common use case of adding