]> git.ipfire.org Git - ipfire.org.git/commitdiff
Did a rewrite of rpc.py and saving toolchain in database.
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 25 Jan 2009 15:58:53 +0000 (16:58 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 25 Jan 2009 15:58:53 +0000 (16:58 +0100)
build/builder.py
build/index.py
build/rpc.py

index cf9387a2ae9728535bd81cd8d0612f9949578216..8e1f391b40847b94865ea00fc3441665c0020f4c 100644 (file)
@@ -167,8 +167,8 @@ class DistccConfig(DatabaseConfig):
        def __str__(self):
                if not self.ping() or self.get() == "0":
                        return ""
-               return "%s:%s/%s,lzo   \t# %s" % \
-                       (socket.gethostbyname(self.hostname), self.get(), self.jobs or "4", self.hostname)
+               return "%s:%s/%s,lzo" % \
+                       (socket.gethostbyname(self.hostname), self.get(), self.jobs or "4",)
 
        def ping(self):
                if not self.hostname:
@@ -224,6 +224,7 @@ class Builder:
                self.state    = DatabaseConfig(self.db, "state")
                self.package  = DatabaseConfig(self.db, "package")
                self.target   = DatabaseConfig(self.db, "target")
+               self.toolchain= DatabaseConfig(self.db, "toolchain")
 
                self.duration = DurationsConfig(self.db)
                self.jobs     = DatabaseConfig(self.db, "jobs")
index 51bc6c3a3d17000953dd3ca01c41f12453e8d75a..7ebf502bd91fc1a689b65ab527a60ce4aac62f4d 100644 (file)
@@ -236,8 +236,8 @@ class Box:
                        print """</p></div>"""
 
        def footer(self):
-               print """<div class="footer"><p>cpu: %s - target: %s - jobs: %s</p></div>""" \
-                       % (self.builder.cpu(), self.builder.target(), self.builder.jobs(),)
+               print """<div class="footer"><p>cpu: %s - target: %s - jobs: %s - toolchain: %s</p></div>""" \
+                       % (self.builder.cpu(), self.builder.target(), self.builder.jobs(), self.builder.toolchain(),)
 
 class BoxCompiling(Box):
        def __init__(self, builder):
index b08a0b3a1c540514a01c731ac41de1f2b478833b..3a660b1b16da4f8e9dd7572bc0067d46971249ab 100644 (file)
@@ -2,7 +2,7 @@
 ###############################################################################
 #                                                                             #
 # IPFire.org - A linux based firewall                                         #
-# Copyright (C) 2008  Michael Tremer & Christian Schmidt                      #
+# Copyright (C) 2008,2009 Michael Tremer & Christian Schmidt                  #
 #                                                                             #
 # This program is free software: you can redistribute it and/or modify        #
 # it under the terms of the GNU General Public License as published by        #
 import os
 import sys
 import cgi
-import time
-import random
 
 sys.path.append(".")
 
 from builder import Builder, getAllBuilders
 from constants import config
 
-class Response:
-       def __init__(self, config):
-               self.config = config
-               
-               self.code = "200"
-               self.mesg = ""
-       
-       def __call__(self, exit=0):
-               print "Status: %s" % self.code
-               print "Content-type: text/plain"
-               print
-               print "%s" % self.mesg
-               if exit:
-                       os._exit(0)
-       
-       def set_code(self, code):
-               self.code = code
-       
-       def set_mesg(self, mesg):
-               self.mesg = mesg
-       
-       def write(self, s):
-               if self.mesg:
-                       self.mesg += "\n"
-               self.mesg += "[%s] - %s" % (time.ctime(), s,)
+ALLOWED_ACTIONS_SET = (        "distcc", "duration", "hostname", "jobs", "log", "state",
+                                               "package", "target", "toolchain", "cpu", "machine",)
+ALLOWED_ACTIONS_GET = ( "distcc",)
 
-response = Response(config)
+def run(uuid, action):
+       myself = Builder(config, uuid)
 
-data = cgi.FieldStorage()
+       if action == "get":
+               for key in ALLOWED_ACTIONS_GET:
+                       if key == "distcc":
+                               for value in data.getlist(key):
+                                       if value == "raw":
+                                               builders = getAllBuilders()
+                                               print "--randomize"
+                                               for builder in builders:
+                                                       # Print "localhost" for ourself
+                                                       if myself.uuid == builder.uuid:
+                                                               print "localhost/%s" % (builder.jobs() or "4")
+                                                       else:
+                                                               if myself.toolchain() == builder.toolchain():
+                                                                       print "%s" % (builder.distcc,)
 
-uuid = data.getfirst("uuid")
-action  = data.getvalue('action')
-if action == "set":
-       if not uuid:
-               response.set_code("406")
-               response.set_mesg("UUID is not valid!")
-               response(1)
-       
-       builder = Builder(config, uuid)
-       
-       key = None
-       for key in [ "distcc", "duration", "hostname", "jobs", "log", "state", "package", "target", "cpu", "machine" ]:
-               for value in data.getlist(key):
-                       ret = builder.set(key, value)
-                       if ret:
-                               response.write(ret)
-elif action == "get":
-       for key in [ "distcc", ]:
-               if key == "distcc":
+       elif action == "set":
+               for key in ALLOWED_ACTIONS_SET:
                        for value in data.getlist(key):
-                               if value == "raw":
-                                       builders = []
-                                       jobs = "4"
-                                       for builder in getAllBuilders():
-                                               if uuid == builder.uuid:
-                                                       jobs = builder.jobs()
-                                                       continue
-                                               builders.append("%s" % builder.distcc)
-                                       string = "localhost/%s\n--randomize\n" % (jobs or "4",)
-                                       while True:
-                                               if not builders: break
-                                               rand = random.randint(0, len(builders)-1)
-                                               if builders[rand]:
-                                                       string = "%s%s\n" % (string, builders[rand],)
-                                               builders.pop(rand)
-                                       response.set_mesg(string)
-                                       
-else:
-       response.set_code("501")
-       response.set_mesg("Don't know what to do with command \"%s\"" % action)
-       response(1)
+                               print myself.set(key, value)
+
+data = cgi.FieldStorage()
+
+print "Status: 200 - OK" # We always send okay.
+print
 
-response()
+try:
+       uuid   = data.getfirst("uuid")
+       action = data.getfirst("action")
+       if uuid and action:
+               run(uuid, action)
+except SystemExit:
+       pass