Development - mobyle2/mobyle2.lib GitHub Wiki
Containers
Tips
How to instantiate a config object
each entry point of the application must instantiate a config object with an explicit path to a configuration file before any other mobyle module import. for instance:
import mobyle.common.config
cfg = mobyle.common.config.Config(file = os.path.normpath(os.path.join(os.path.dirname(__file__), '..', 'development.ini')))
this will create a kind of singleton of the config object, so the other call to config just return this object.
If you have a warning with the following message: No configuration file available, using defaults
then you need to check carefully the config object.
Create a new MongoKit class
- Create your class using MongoKit syntax ;-)
- import object connection from the mobyle.common.connection module.
- to register the class in mongokit add the decorator @connection.register
- if you need to use an object from mongokit you need to import the corresponding module. The registration of the class in the mongokit connection is made at the import step.
- If object need to be added to the web dashboard, on mobyle.web://mobyle/web/init.py, add your object to the Dashboard.register() method call.
Following an example to use retrieve User object in mongo. If the module is an entry point of the application then instantiate a config object with a the path of a configuration file
from mobyle.common.config import Config
config = Config( os.path.join( os.path.dirname(__file__), 'test.conf'))
Import the Mongokit connection object
from mobyle.common.connection import connection
By importing users all class in users which are decorated with @connection.register are registered in connection
from mobyle.common import users
Use Mongokit to retrieve User:
objects = connection.User.find({})
Travis status
https://api.travis-ci.org/repos/USERNAME/PROJECTNAME/builds
Errbit logger
To configure a log handler with errbit, add airbrakepy to requirements and add to config file:
[handler_errbitHandler]
class=airbrakepy.logging.handlers.AirbrakeHandler
level=DEBUG
args=(api_key="xxx", environment="dev", component_name="mobyle", node_name="mytestserver", use_ssl=False, timeout_in_ms=3000, airbrake_url="http://localhost:3000/notifier_api/v2/notices")
Do not forget to call logging.shutdown() to clean the logging on application shudown