Thursday, July 1, 2010

Creating a new web interface for pony-build

Hello ,

In this tutorial i will try to explain the procedure that i follow to create a web interface for pony-build [0] which is a continuous integration system that i'm using in the GSoC project "pypi testing infrastructure"[1].

So first pony-build come with a default web interface created with Quixote and if you want to create a new web interface let say using Django in this tutorial i will show you how i interface the my web interface with pony-build .

1- First you have to run pony-build using the web interface in my project i created a script that i have called run.py where i have put this code:

from django.core.handlers.wsgi import WSGIHandler
from django.core.servers.basehttp import AdminMediaHandler

from adapter import CoordinatorAdapter
from pony_build import server, coordinator, dbsqlite


if __name__ == '__main__':
""" run pony-build server in local host

"""
_host = 'localhost'
_port = 8800

# create the sqlite database
_db_file = dbsqlite.open_shelf("pyti")
_db_file = coordinator.IntDictWrapper(_db_file)

# pass the database to the coordinator
my_coordinator = CoordinatorAdapter(db=_db_file)

# create the server using server module
pony_server = server.create(_host, _port, my_coordinator, AdminMediaHandler(WSGIHandler()))

print 'pony-build server started on host %s, port %d' % (_host, _port)

# run the server
pony_server.serve_forever()

2- Next i created a new implementation of the coordianator in my case i need it because i have two database the first one sqlite is used by the pony-build server to save packages build info and the other is used by Django , all this complexity is because i want to change the database layer to support not only sqlite and like that i will have only one database but not for now .

here my code :


import datetime
from django.contrib.auth.models import User

from pony_build.coordinator import PonyBuildCoordinator
from packages.models import Packages, History, Report

# inherit from the PonyBuildCoordinator
class CoordinatorAdapter(PonyBuildCoordinator):
""" Adapter design pattern

"""

# override add_result method so i can save the build info in the web interface DB
def add_results(self, client_ip, client_info, results):
""" copy build result to Django database.

"""

super(CoordinatorAdapter, self).add_results(client_ip, client_info, results)

#update existing package info or creating a new entry
new = Packages.objects.get_or_create(package_name=client_info['package'])[0]

new.package_description=client_info['package']
new.last_state = client_info['success']
new.last_build = datetime.datetime.now()
new.save()

package_history = History()

package_history.time = new.last_state
package_history.state = new.last_build
package_history.package_build = new

new_report = Report()
new_report.platform = client_info['arch']
new_report.report = 'TO ADD'
new_report.save()

package_history.report = new_report
package_history.save()

print "package saved"


if you want to see all the example go to [2]

[0] http://github.com/ctb/pony-build
[1] http://bitbucket.org/mouad/pypi-testing-infrastructure-pyti/
[2] http://bitbucket.org/mouad/pypi-testing-infrastructure-pyti/src/tip/GUI/

No comments:

Post a Comment