diff options
author | Will Woods <wwoods@redhat.com> | 2009-09-14 16:41:40 -0400 |
---|---|---|
committer | Will Woods <wwoods@redhat.com> | 2009-09-14 16:41:40 -0400 |
commit | 3a8875e7785e4597f3802ef5a95230d8eaa1903c (patch) | |
tree | 3d3c625b59a0fdc3f12ce9b2d088e9f6e6b86f12 | |
parent | eaea9a91254ea3b950bdee53c938eeaa8a47c695 (diff) | |
download | israwhidebroken-3a8875e7785e4597f3802ef5a95230d8eaa1903c.tar.gz israwhidebroken-3a8875e7785e4597f3802ef5a95230d8eaa1903c.tar.xz israwhidebroken-3a8875e7785e4597f3802ef5a95230d8eaa1903c.zip |
Add some json RPCs to list trees/tests and to add a test result
-rw-r--r-- | israwhidebroken/controllers.py | 50 |
1 files changed, 48 insertions, 2 deletions
diff --git a/israwhidebroken/controllers.py b/israwhidebroken/controllers.py index 8873f77..14e0fb6 100644 --- a/israwhidebroken/controllers.py +++ b/israwhidebroken/controllers.py @@ -1,21 +1,67 @@ import turbogears as tg from turbogears import controllers, expose, flash -from israwhidebroken import model +from israwhidebroken.model import Test, Tree, TestResult, hub +from sqlobject import AND from turbogears import identity, redirect from cherrypy import request, response # from israwhidebroken import json # import logging # log = logging.getLogger("israwhidebroken.controllers") +def to_int(fstr): + '''Returns fstr converted to int, or None if fstr is None''' + return fstr and int(float(fstr)) + class Root(controllers.RootController): + # Main index page @expose(template="israwhidebroken.templates.index") def index(self): # TODO: find most recent tree(s) return dict(in_qa='qa' in identity.current.groups, admin='qa-admin' in identity.current.groups, - tests=model.Test.select(), + tests=Test.select(), treeid=0) # fake treeid + # JSON RPC calls + @expose("json") + def list_tests(self): + tests = Test.select() + return dict(tests=list(tests)) + + @expose("json") + def get_trees(self, arch=None, tree_time=None, repodata_time=None): + trees = [] + tree = None + if tree_time: + trees = list(Tree.select( + AND(Tree.q.tree_time == to_int(tree_time), + Tree.q.arch == arch), + orderBy='tree_time')) + elif repodata_time: + trees = list(Tree.select( + AND(Tree.q.repodata_time == to_int(repodata_time), + Tree.q.arch == arch), + orderBy='repodata_time')) + return dict(trees=trees) + + @expose("json") + @identity.require(identity.in_group("qa")) + def add_testresult(self, arch=None, tree_time=None, repodata_time=None, testid=0, result=0): + # First, check to see if we have an existing Tree that matches + r = self.get_trees(arch, tree_time, repodata_time) + trees = r['trees'] + if len(trees): + tree = trees[-1] # Pick the newest tree + else: + tree = Tree(arch = arch, + tree_time = to_int(tree_time), + repodata_time = to_int(repodata_time)) + hub.commit() + tr = TestResult(test=testid, tree=tree.id, result=result) + hub.commit() # XXX redundant? + return dict(id=tr.id) + + # Identity stuff (login/logout) @expose(template="israwhidebroken.templates.login") def login(self, forward_url=None, *args, **kw): |