Module util
Various tools used be the administrative commands
- Imports:
- configobj, nagare, os, pkg_resources, sys
- Classes:
- Command: The base class of all the administration commands
- Methods:
- activate_WSGIApp(app, cfgfile, aconf, error, project_name='', static_path=None, static_url=None, data_path=None, publisher=None, sessions_manager=None, debug=False): Set all the properties of a WSGIApp application
- get_database(conf, debug): Read the database settings
- load_app(app, _): Load a registered application
- load_egg(dist, app): Load a registered application of a distribution
- load_entry_point(app, entry_point): Load an object registered under an entry point
- load_file(filename, app): Load an object from a file
- load_module(module, app): Load an object from a Python module
- load_object(path): Load an object from a path
- read_application(cfgfile, error): Read the configuration file for the application and create the application object
- read_application_options(cfgfile, error, default={ }): Read the configuration file for the application
- Attributes:
- application_options_spec = { 'application' : dict(path = 'string()', name = 'string()', debug = 'boolean(default=False)', redirect_after_post = 'boolean(default=False)', always_html = 'boolean(default=True)', wsgi_pipe = 'string(default="")'), 'database' : dict(activated = 'boolean(default=False)', uri = 'string(default="")', metadata = 'string(default="")', populate = 'string(default="")', debug = 'boolean(default=False)', __many__ = dict(activated = 'boolean(default=False)', populate = 'string(default="")')), 'logging' : dict() }
- loaders = { '' : load_module, 'python' : load_module, 'egg' : load_egg, 'file' : load_file, 'app' : load_app }
Class util.Command
- Bases:
- None
The base class of all the administration commands
- Methods:
- run(cls, options, args):
- set_options(cls, parser):
- Attributes:
- desc = ''
Method util.activate_WSGIApp
- Arguments:
- app, cfgfile, aconf, error, project_name='', static_path=None, static_url=None, data_path=None, publisher=None, sessions_manager=None, debug=False
Set all the properties of a WSGIApp application
- In:
- app -- the WSGIApp application or the application root object factory
- cfgfile -- the path to the configuration file
- aconf -- the ConfigObj object, created from the configuration file
- error -- the function to call in case of configuration errors
- project_name -- name of the distutils distribution where the app is located
- static_path -- the directory where the static contents of the application are located
- static_url -- the url of the static contents of the application
- data_path -- the directory where the data of the application are located
- publisher -- the publisher of the application
- session_manager -- the sessions manager
- debug -- flag to display the generated SQL statements
- Return:
- a tuple:
- the wsgi.WSGIApp object
- tuples (application databases settings, application databases populate functions)
Method util.get_database
- Arguments:
- conf, debug
Read the database settings
The location of the metadata object is read from the configuration file
- In:
- conf -- the ConfigObj object, created from the configuration file
- debug -- debug mode for the database engine
- Return:
- the tuple: - metadata object - database uri - database debug mode - database engines settings
Method util.load_app
- Arguments:
- app, _
Load a registered application
- In:
- app -- name of the application
- _ -- unused*
- Return:
- (the application, the distribution of the application)
Method util.load_egg
- Arguments:
- dist, app
Load a registered application of a distribution
- In:
- dist -- name of the distribution
- app -- name of the application
- Return:
- (the application, the distribution of the application)
Method util.load_entry_point
- Arguments:
- app, entry_point
Load an object registered under an entry point
- In:
- app -- name of the object
- entry_point -- name of the entry_point
- Return:
- (the object, the distribution of the object)
Method util.load_file
- Arguments:
- filename, app
Load an object from a file
- In:
- filename -- name of the file
- app -- name of the object to load
- Return:
- (the object, None)
Method util.load_module
- Arguments:
- module, app
Load an object from a Python module
- In:
- module -- name of the module
- app -- name of the object to load
- Return:
- (the object, None)
Method util.load_object
- Arguments:
- path
Load an object from a path
The possible path syntaxes are:
- 'python <module>:<object>' -- loads an object from a Python module (for example: 'python os.path:isfile')
- '<module>:<object>' -- same as 'python <module>:<object>'
- 'file <file>:<object>' -- loads an object from a file (for example: 'file /tmp/counter.py:Counter')
- 'egg <dist>:<app>' -- loads the registered application <app> from the <dist> distribution (for example: 'egg nagare:admin' or 'egg nagare.examples:wiki')
- 'app <app>' -- load the registered application <app> (for example: 'app examples')
- Return:
- a tuple (object loaded, distribution where this object is located or None)
Method util.read_application
- Arguments:
- cfgfile, error
Read the configuration file for the application and create the application object
- In:
- cfgfile -- name of a registered application or path to an application configuration file
- error -- the function to call in case of configuration errors
- Return:
- a tuple:
- name of the application configuration file
- the application object
- the distribution of the application
- a ConfigObj of the application parameters
- a tuple:
Method util.read_application_options
- Arguments:
- cfgfile, error, default={ }
Read the configuration file for the application
- In:
- cfgfile -- path to an application configuration file
- error -- the function to call in case of configuration errors
- default -- optional default values
- Return:
- a ConfigObj of the application parameters