Watcher handlers¶
This component contains watchdog handlers to use to watch a project sources.
- class optimus.watchers.BaseHandler[source]¶
Base class for handlers.
Assume children inheriting this class have a
settingsattribute with a validSettingsModelinstance as value.- get_relative_template_path(path)[source]¶
Retrieve relative path from templates directory.
- Parameters:
path (str) – Path to a template file.
- Returns:
Relative path either from templates directory or untouched if file does not belong to template directory.
- Return type:
string
- class optimus.watchers.templates.TemplatesWatchEventHandler(settings, builder, *args, **kwargs)[source]¶
Template events handler.
- Parameters:
settings (optimus.conf.model.SettingsModel) – Project settings.
builder (optimus.pages.builder.PageBuilder) – Page builder object that is used to perform page building.
args – Additional arguments to be passed to handler, commonly for watchdog API.
- Keyword Arguments:
kwargs – Optionnal keyword arguments commonly for watchdog API.
- settings¶
As given from arguments.
- builder¶
As given from arguments.
- logger¶
Optimus logger.
- Type:
logging.Logger
- build_for_item(path)[source]¶
Build all pages using given template path.
If template is a snippet included in other templates they will be flagged for build too. This is recursive so a snippet in a snippet in a snippet will raises also to page templates.
- Parameters:
path (string) – Template path.
- Returns:
List of builded pages.
- Return type:
list
- on_moved(event)[source]¶
Called when a file or a directory is moved or renamed.
Many editors don’t directly change a file, instead they make a transitional file like
*.partthen move it to the final filename.- Parameters:
event – Watchdog event, either
watchdog.events.DirMovedEventorwatchdog.events.FileModifiedEvent.
- class optimus.watchers.assets.AssetsWatchEventHandler(settings, assets_env, builder, *args, **kwargs)[source]¶
Assets events handler.
Since assets filename change when they are rebuiled, this handler also performs page rebuild to include the right assets urls.
Note
The assets handler or registry are not aware of templates and so it can not determine if an asset or a bundle is used in one or more specific templates.
It results in a rebuild of all page views when a single asset or bundle is changed.
For example, a
skeleton.htmluse a bundlemain.cssandsinglepage.htmldo not use any bundle or asset. Ifmain.cssis changed, bothskeleton.htmlandsinglepage.htmlwill be rebuild.- Parameters:
settings (optimus.conf.model.SettingsModel) – Project settings.
assets_env (webassets.Environment) – Webasset environment.
builder (optimus.pages.builder.PageBuilder) – Page builder object that is triggered to perform page building.
args – Additional arguments to be passed to handler, commonly for watchdog API.
- Keyword Arguments:
kwargs – Optionnal keyword arguments commonly for watchdog API.
- settings¶
As given from arguments.
- assets_env¶
Environment As given from arguments.
- Type:
webassets.Environment
- builder¶
As given from arguments.
- logger¶
Optimus logger.
- Type:
logging.Logger
- build_for_item(path)[source]¶
Build bundle containing given asset path and all pages.
- Parameters:
path (string) – Asset path.
- Returns:
List of builded pages.
- Return type:
list
- on_moved(event)[source]¶
Called when a file or a directory is moved or renamed.
Many editors don’t directly change a file, instead they make a transitional file like
*.partthen move it to the final filename, so they will trigger this move event.- Parameters:
event – Watchdog event, either
watchdog.events.DirMovedEventorwatchdog.events.FileModifiedEvent.