]> git.ipfire.org Git - ipfire.org.git/blame - build/rpc.py
Changed footer on build.ipfire.org.
[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"
76bb443a 38 self.mesg = ""
2b60fce9
MT
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
76bb443a
MT
53
54 def write(self, s):
55 if self.mesg:
56 self.mesg += "\n"
57 self.mesg += "[%s] - %s" % (time.ctime(), s,)
2b60fce9
MT
58
59response = Response(config)
60
61data = cgi.FieldStorage()
62
161111d2 63uuid = data.getfirst("uuid")
2b60fce9
MT
64action = data.getvalue('action')
65if action == "set":
2b60fce9
MT
66 if not uuid:
67 response.set_code("406")
68 response.set_mesg("UUID is not valid!")
69 response(1)
70
71 builder = Builder(config, uuid)
72
73 key = None
0359f8fc 74 for key in [ "distcc", "duration", "hostname", "jobs", "log", "state", "package", "target", "cpu", "machine" ]:
2b60fce9 75 for value in data.getlist(key):
76bb443a
MT
76 ret = builder.set(key, value)
77 if ret:
78 response.write(ret)
2b60fce9
MT
79elif action == "get":
80 for key in [ "distcc", ]:
81 if key == "distcc":
82 for value in data.getlist(key):
83 if value == "raw":
84 builders = []
10da7ad4 85 jobs = "4"
2b60fce9 86 for builder in getAllBuilders():
10da7ad4
MT
87 if uuid == builder.uuid:
88 jobs = builder.jobs()
89 continue
2b60fce9 90 builders.append("%s" % builder.distcc)
10da7ad4 91 string = "localhost/%s\n--randomize\n" % (jobs or "4",)
2b60fce9
MT
92 while True:
93 if not builders: break
94 rand = random.randint(0, len(builders)-1)
8d484bc2
MT
95 if builders[rand]:
96 string = "%s%s\n" % (string, builders[rand],)
2b60fce9
MT
97 builders.pop(rand)
98 response.set_mesg(string)
99
100else:
101 response.set_code("501")
102 response.set_mesg("Don't know what to do with command \"%s\"" % action)
103 response(1)
104
105response()