Add operatornotify.main_decorator to reduce application boilerplate.

master
voussoir 2021-06-21 21:56:11 -07:00
parent 81d09ad3bc
commit c709a28d08
No known key found for this signature in database
GPG Key ID: 5F7554F8C26DACCB
1 changed files with 13 additions and 0 deletions

View File

@ -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