Source code for chuda.plugins

'''
Module for Chuda Plugins
'''
[docs]class Plugin: ''' Class represent a Plugin for a Chuda application A plugin can register hooks for steps in the application lifecycle or enrich the app with new properties ''' priority = 0 def __init__(self): self.app = None
[docs] def setup(self, app): ''' Setup the app on the plugin ''' self.app = app
[docs] def enrich_app(self, name, value): ''' Add a new property to the app (with setattr) Args: name (str): the name of the new property value (any): the value of the new property ''' #Method shouldn't be added: https://stackoverflow.com/a/28060251/3042398 if type(value) == type(self.enrich_app): raise ValueError("enrich_app can't add method") setattr(self.app, name, value)
[docs] def on_create(self): ''' Called at the app creation ''' pass
[docs] def on_arguments_parsed(self): ''' Called after arguments have been parsed ''' pass
[docs] def on_config_read(self): ''' Called after configurations files have been read ''' pass
[docs] def on_signals_handled(self): ''' Called after signals handlers have been setuped ''' pass
[docs] def on_logger_created(self): ''' Called after logger have been created ''' pass
[docs] def on_run(self): ''' Called just before run the app ''' pass
[docs] def on_end(self): ''' Called after all steps and code have been executed ''' pass