From: Michael Tremer
Date: Sun, 25 Jan 2009 15:58:53 +0000 (+0100)
Subject: Did a rewrite of rpc.py and saving toolchain in database.
X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=18f334034681a6bfc252fa47d66552d81b111b60;p=ipfire.org.git
Did a rewrite of rpc.py and saving toolchain in database.
---
diff --git a/build/builder.py b/build/builder.py
index cf9387a2..8e1f391b 100644
--- a/build/builder.py
+++ b/build/builder.py
@@ -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")
diff --git a/build/index.py b/build/index.py
index 51bc6c3a..7ebf502b 100644
--- a/build/index.py
+++ b/build/index.py
@@ -236,8 +236,8 @@ class Box:
print """
"""
def footer(self):
- print """""" \
- % (self.builder.cpu(), self.builder.target(), self.builder.jobs(),)
+ print """""" \
+ % (self.builder.cpu(), self.builder.target(), self.builder.jobs(), self.builder.toolchain(),)
class BoxCompiling(Box):
def __init__(self, builder):
diff --git a/build/rpc.py b/build/rpc.py
index b08a0b3a..3a660b1b 100644
--- a/build/rpc.py
+++ b/build/rpc.py
@@ -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 #
@@ -22,84 +22,48 @@
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