ReleaseEngineering/BuildAPI

< ReleaseEngineering
Revision as of 21:40, 14 October 2010 by Ssalbiz (talk | contribs) (Created page with "= Overview = The BuildAPI is a Pylons project used by RelEng to surface information collected from two databases updated through our buildbot masters as they run jobs. = Project...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Overview

The BuildAPI is a Pylons project used by RelEng to surface information collected from two databases updated through our buildbot masters as they run jobs.

Project Requirements

To run an instance of the buildAPI locally, you will need the following:

  • Python w/ easy_install
  • MySQL
  • Snapshots of our two databases 'statusdb' and 'schedulerdb'. They are available here and here respectively.

Not required, but it would be highly recommended to set up a python virtualenv to work under.

Getting Started

The source for the buildapi is available here: buildapi source

Before you get started with that, you should setup your MySQL database instances. To do that all you need to do is download, extract and load the sql dumps provided.

Now, to get started with the pylons project, simply run:

 easy_install buildapi

which should handle grabbing pylon project dependencies. You will also need to grab and install the google python visualization library from here.

Next you will need to generate a config file for your project, do this by running:

 paster make-config buildapi config.ini

Now you will need to edit that config.ini to use the correct host(localhost should be fine), and database URLs. Note: MySQL databases take the format `mysql://[username][:password][@hostname]/database_name`

You should now be all set up now! Running the project locally can be done through:

 paster serve --reload --daemon config.ini

Which starts running the buildapi on your local machine. To view it, open up http://localhost:5000.

Building a simple controller

The buildAPI is built on top of the pylons framework, which enforces a strict MVC stack. To add a new feature to the buildapi you will typically want to create a new controller and associate it with one or more models and views.

To create a simple 'hello world' controller, first use paster to create a template to work with.

 paster controller hello_world

This automatically creates a workable template and a functional test case for your new controller. You can now hack the newly created file under buildapi/controllers to your heart's content. Models associated with your controller can be created under buildapi/model. Views are created using Mako python templates. Create a template file under buildapi/templates for your new controller.

To associate with a model, simply add

 from buildapi.model.<model_name> import <functions to import>

Lastly, once you're done, and you want to render a page, you can call render('/<template-name>.mako') to render a view with your results.