]> git.ipfire.org Git - ipfire.org.git/blame - build/rpc.py
I rather prefer the hosts in one line.
[ipfire.org.git] / build / rpc.py
CommitLineData
2b60fce9
MT
1#!/usr/bin/python
2###############################################################################
3# #
4# IPFire.org - A linux based firewall #
5# Copyright (C) 2008 Michael Tremer & Christian Schmidt #
6# #
7# This program is free software: you can redistribute it and/or modify #
8# it under the terms of the GNU General Public License as published by #
9# the Free Software Foundation, either version 3 of the License, or #
10# (at your option) any later version. #
11# #
12# This program is distributed in the hope that it will be useful, #
13# but WITHOUT ANY WARRANTY; without even the implied warranty of #
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15# GNU General Public License for more details. #
16# #
17# You should have received a copy of the GNU General Public License #
18# along with this program. If not, see <http://www.gnu.org/licenses/>. #
19# #
20###############################################################################
21
22import os
23import sys
24import cgi
25import time
26import random
27
28sys.path.append(".")
29
30from builder import Builder, getAllBuilders
31from constants import config
32
33class Response:
34 def __init__(self, config):
35 self.config = config
36
37 self.code = "200"
38 self.mesg = "OK"
39
40 def __call__(self, exit=0):
41 print "Status: %s" % self.code
42 print "Content-type: text/plain"
43 print
44 print "%s" % self.mesg
45 if exit:
46 os._exit(0)
47
48 def set_code(self, code):
49 self.code = code
50
51 def set_mesg(self, mesg):
52 self.mesg = mesg
53
54response = Response(config)
55
56data = cgi.FieldStorage()
57
58action = data.getvalue('action')
59if action == "set":
60 uuid = data.getfirst("uuid")
61 if not uuid:
62 response.set_code("406")
63 response.set_mesg("UUID is not valid!")
64 response(1)
65
66 builder = Builder(config, uuid)
67
68 key = None
69 for key in [ "distcc", "duration", "hostname", "state", "package", ]:
70 for value in data.getlist(key):
71 builder.set(key, value)
72elif action == "get":
73 for key in [ "distcc", ]:
74 if key == "distcc":
75 for value in data.getlist(key):
76 if value == "raw":
77 builders = []
78 for builder in getAllBuilders():
79 builders.append("%s" % builder.distcc)
80 string = ""
81 while True:
82 if not builders: break
83 rand = random.randint(0, len(builders)-1)
687a408d 84 string = "%s %s" % (string, builders[rand],)
2b60fce9
MT
85 builders.pop(rand)
86 response.set_mesg(string)
87
88else:
89 response.set_code("501")
90 response.set_mesg("Don't know what to do with command \"%s\"" % action)
91 response(1)
92
93response()