Interfaces¶
An interface is the functional implementation for command line but usable from Python code without tricks involved by command lines requirements like importing settings or page modules.
- optimus.interfaces.starter.starter_interface(template, project_name, output_dir)[source]¶
Interface to create a new Optimus project from a cookiecutter template.
Be aware that cookiecutter emit a lot of logs, you may want to mute them.
- Raises:
exceptions – Any possible exceptions from cookiecutter.
- Parameters:
template (string) – Path to a template directory or an URL to a public template repository.
project_name (string) – Project name. It would be used to make the project directory name.
output_dir (string) – Path where the project directory will be created.
- Returns:
Path where the project has been created.
- Return type:
string
- optimus.interfaces.build.builder_interface(settings, views)[source]¶
Build all enabled pages from given views module.
- Parameters:
settings (optimus.conf.model.SettingsModel) – Settings object which defines everything required for building.
views (object) – Module which defines page views to build, in fact the module object require only a
PAGESattribute that is a list of Page view.
- Returns:
A dictionnary with initialized builder (
builderitem), asset manager (assets_envitem) and the list of builded pages (buildeditem).- Return type:
dict
- optimus.interfaces.watch.watcher_interface(settings, views, build_env)[source]¶
Initialize observer for views and possible assets according to settings and build environment.
Commonly before using this function you will use
builder_interfacefirst since it will perform a first (required) build and init the builder environment as expected inbuild_envargument.Once this interface returns the observer object, you may use it like so:
observer.start() try: while True: time.sleep(1) except KeyboardInterrupt: observer.stop() observer.join()
- Parameters:
settings (optimus.conf.model.SettingsModel) – Settings object which defines everything required for building.
views (object) – Module which defines page views to build, in fact the module object require only a
PAGESattribute that is a list of Page view.build_env (dict) – A dictionnary with initialized builder (
builderitem), asset manager (assets_envitem) and the list of builded pages (buildeditem).
- Returns:
The initialized and configured observer for setted watchers.
- Return type:
watchdog.observers.Observer
- optimus.interfaces.po.po_interface(settings, init=False, update=False, compile_opt=False)[source]¶
Manage project translation catalogs for all registred languages.
You may enable all available modes. Modes are always processed in the same order: “init” then “update” and finally “compile”.
- Parameters:
settings (optimus.conf.model.SettingsModel) – Settings object which define paths for locale directory and path for template sources to possibly scan.
- Keyword Arguments:
init (boolean) – Enable init mode to initialize POT file and “locale” directory.
update (boolean) – Enable update mode to refresh POT file and PO files for template changes.
compile_opt (boolean) – Enable compile mode to compile MO files from PO files.
- optimus.interfaces.runserver.server_interface(settings, hostname, index='index.html')[source]¶
Validate configuration, configurate cherrypy server and application to serve build directory.
- Parameters:
settings (optimus.conf.model.SettingsModel) – Settings object which defines everything required for building.
hostname (string) – Hostname required to bind on. This is the host address with optional port like
localhost:8001or without portlocalhost(default HTTP port80will be used).
- Keyword Arguments:
index (string) – Filename to consider as directory index. Default to
index.html.- Returns:
A dictionnary with cherrypy module object (
cherrypyitem), a dict for application config (app_confitem) and the relative URL to mount application (mount_onitem) which is usally the root.- Return type:
dict