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 settings attribute with a valid SettingsModel instance 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

get_relative_asset_path(path)[source]

Retrieve relative path from assets directory.

Parameters:

path (str) – Path to an asset file.

Returns:

Relative path either from assets directory or untouched if file does not belong to assets directory.

Return type:

string

get_relative_data_path(path)[source]

Retrieve relative path from datas directory.

Parameters:

path (str) – Path to a data file.

Returns:

Relative path either from datas directory or untouched if file does not belong to datas directory.

Return type:

string

class optimus.watchers.templates.TemplatesWatchEventHandler(settings, builder, *args, **kwargs)[source]

Template events handler.

Parameters:
Keyword Arguments:

kwargs – Optionnal keyword arguments commonly for watchdog API.

settings

As given from arguments.

Type:

optimus.conf.model.SettingsModel

builder

As given from arguments.

Type:

optimus.pages.builder.PageBuilder

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 *.part then move it to the final filename.

Parameters:

event – Watchdog event, either watchdog.events.DirMovedEvent or watchdog.events.FileModifiedEvent.

on_created(event)[source]

Called when a new file or directory is created.

Parameters:

event – Watchdog event, either watchdog.events.DirCreatedEvent or watchdog.events.FileCreatedEvent.

on_modified(event)[source]

Called when a file or directory is modified.

Parameters:

event – Watchdog event, watchdog.events.DirModifiedEvent or watchdog.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.html use a bundle main.css and singlepage.html do not use any bundle or asset. If main.css is changed, both skeleton.html and singlepage.html will be rebuild.

Parameters:
Keyword Arguments:

kwargs – Optionnal keyword arguments commonly for watchdog API.

settings

As given from arguments.

Type:

optimus.conf.model.SettingsModel

assets_env

Environment As given from arguments.

Type:

webassets.Environment

builder

As given from arguments.

Type:

optimus.pages.builder.PageBuilder

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 *.part then move it to the final filename, so they will trigger this move event.

Parameters:

event – Watchdog event, either watchdog.events.DirMovedEvent or watchdog.events.FileModifiedEvent.

on_created(event)[source]

Called when a new file or directory is created.

Parameters:

event – Watchdog event, either watchdog.events.DirCreatedEvent or watchdog.events.FileCreatedEvent.

on_modified(event)[source]

Called when a file or directory is modified.

Parameters:

event – Watchdog event, watchdog.events.DirModifiedEvent or watchdog.events.FileModifiedEvent.