The manager module

Utility functions for running various ferenda tasks from the command line, including registering classes in the configuration file. If you’re using the DocumentRepository API directly in your code, you’ll probably only need makeresources(), frontpage() and possibly setup_logger(). If you’re using the ferenda-build.py tool, you don’t need to directly call any of these methods – ferenda-build.py calls run(), which calls everything else, for you.

ferenda.manager.makeresources(repos, resourcedir=u'data/rsrc', combine=False, cssfiles=, []jsfiles=, []imgfiles=, []staticsite=False, legacyapi=False, sitename=u'MySite', sitedescription=u'Just another Ferenda site', url=u'http://localhost:8000/')[source]

Creates the web assets/resources needed for the web app (concatenated and minified js/css files, resources.xml used by most XSLT stylesheets, etc).

Parameters:
  • repos (list) – The repositories to create resources for, as instantiated and configured docrepo objects
  • combine (bool) – whether to combine and compact/minify CSS and JS files
  • resourcedir (str) – where to put generated/copied resources
Returns:

All created/copied css, js and resources.xml files

Return type:

dict of lists

ferenda.manager.frontpage(repos, path=u'data/index.html', stylesheet=u'res/xsl/frontpage.xsl', sitename=u'MySite', staticsite=False)[source]

Create a suitable frontpage.

Parameters:
  • repos (list) – The repositories to list on the frontpage, as instantiated and configured docrepo objects
  • path (str) – the filename to create.
ferenda.manager.runserver(repos, port=8000, documentroot=u'data', apiendpoint=u'/api/', searchendpoint=u'/search/', url=u'http://localhost:8000/', indextype=u'WHOOSH', indexlocation=u'data/whooshindex', legacyapi=False)[source]

Starts up a internal webserver and runs the WSGI app (see make_wsgi_app()) using all the specified document repositories. Runs forever (or until interrupted by keyboard).

Parameters:
  • repos (list) – Object instances for the repositories that should be served over HTTP
  • port (int) – The port to use
  • documentroot (str) – The root document, used to locate files not directly handled by any repository
  • apiendpoint (str) – The part of the URI space handled by the API functionality
  • searchendpoint (str) – The part of the URI space handled by the search functionality
ferenda.manager.make_wsgi_app(inifile=None, **kwargs)[source]
Creates a callable object that can act as a WSGI application by
mod_wsgi, gunicorn, the built-in webserver, or any other WSGI-compliant webserver.
Parameters:
  • inifile (str) – The full path to a ferenda.ini configuration file
  • **kwargs – Configuration values for the wsgi app (must include documentroot, apiendpoint and searchendpoint). Only used if inifile is not provided.
Returns:

A WSGI application

Return type:

callable

ferenda.manager.setup_logger(level=u'INFO', filename=None, logformat=u'%(asctime)s %(name)s %(levelname)s %(message)s', datefmt=u'%H:%M:%S')[source]
Sets up the logging facilities and creates the module-global log
object as a root logger.
Parameters:
  • name (str) – The name of the logger (used in log messages)
  • level (str) – ‘DEBUG’,’INFO’,’WARNING’,’ERROR’ or ‘CRITICAL’
  • filename (str) – The name of the file to log to. If None, log to stdout
ferenda.manager.shutdown_logger()[source]

Shuts down the configured logger. In particular, closes any FileHandlers, which is needed on win32.

ferenda.manager.run(argv)[source]

Runs a particular action for either a particular class or all enabled classes.

Parameters:argv – a sys.argv-style list of strings specifying the class to load, the action to run, and additional parameters. The first parameter is either the name of the class-or-alias, or the special value “all”, meaning all registered classes in turn. The second parameter is the action to run, or the special value “all” to run all actions in correct order. Remaining parameters are either configuration parameters (if prefixed with --, e.g. --loglevel=INFO, or positional arguments to the specified action).
ferenda.manager.enable(classname)[source]

Registers a class by creating a section for it in the configuration file (ferenda.ini). Returns the short-form alias for the class.

>>> enable("ferenda.DocumentRepository") == 'base'
True
>>> os.unlink("ferenda.ini")
Parameters:classname (str) – The fully qualified name of the class
Returns:The short-form alias for the class
Return type:str
ferenda.manager.runsetup()[source]

Runs setup() and exits with a non-zero status if setup failed in any way

Note

The ferenda-setup script that gets installed with ferenda is a tiny wrapper around this function.

ferenda.manager.setup(argv=None, force=False, verbose=False, unattended=False)[source]

Creates a project, complete with configuration file and ferenda-build tool.

Checks to see that all required python modules and command line utilities are present. Also checks which triple store(s) are available and selects the best one (in order of preference: Sesame, Fuseki, RDFLib+Sleepycat, RDFLib+SQLite).