]>
Commit | Line | Data |
---|---|---|
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 | ||
22 | import os | |
23 | import sys | |
24 | import cgi | |
25 | import time | |
26 | import random | |
27 | ||
28 | sys.path.append(".") | |
29 | ||
30 | from builder import Builder, getAllBuilders | |
31 | from constants import config | |
32 | ||
33 | class 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 | ||
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 | ||
54 | response = Response(config) | |
55 | ||
56 | data = cgi.FieldStorage() | |
57 | ||
161111d2 | 58 | uuid = data.getfirst("uuid") |
2b60fce9 MT |
59 | action = data.getvalue('action') |
60 | if action == "set": | |
2b60fce9 MT |
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 | |
0e744e5a | 69 | for key in [ "distcc", "duration", "hostname", "jobs", "log", "state", "package", "target" ]: |
2b60fce9 MT |
70 | for value in data.getlist(key): |
71 | builder.set(key, value) | |
72 | elif action == "get": | |
73 | for key in [ "distcc", ]: | |
74 | if key == "distcc": | |
75 | for value in data.getlist(key): | |
76 | if value == "raw": | |
77 | builders = [] | |
10da7ad4 | 78 | jobs = "4" |
2b60fce9 | 79 | for builder in getAllBuilders(): |
10da7ad4 MT |
80 | if uuid == builder.uuid: |
81 | jobs = builder.jobs() | |
82 | continue | |
2b60fce9 | 83 | builders.append("%s" % builder.distcc) |
10da7ad4 | 84 | string = "localhost/%s\n--randomize\n" % (jobs or "4",) |
2b60fce9 MT |
85 | while True: |
86 | if not builders: break | |
87 | rand = random.randint(0, len(builders)-1) | |
8d484bc2 MT |
88 | if builders[rand]: |
89 | string = "%s%s\n" % (string, builders[rand],) | |
2b60fce9 MT |
90 | builders.pop(rand) |
91 | response.set_mesg(string) | |
92 | ||
93 | else: | |
94 | response.set_code("501") | |
95 | response.set_mesg("Don't know what to do with command \"%s\"" % action) | |
96 | response(1) | |
97 | ||
98 | response() |