]>
git.ipfire.org Git - ipfire.org.git/blob - build/builder.py
2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2008 Michael Tremer & Christian Schmidt #
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. #
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. #
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/>. #
20 ###############################################################################
26 from pysqlite2
import dbapi2
as sqlite
30 from constants
import config
33 def __init__(self
, path
):
34 self
.db
= sqlite
.connect(os
.path
.join(path
, config
["db_name"]))
37 create table if not exists config(key, value, date);
38 create table if not exists durations(duration);
50 return self
.db
.cursor()
56 def __init__(self
, db
, key
):
65 c
.execute("SELECT value FROM %(table)s WHERE key = '%(key)s'" \
66 % { "table" : "config",
69 self
.data
= c
.fetchone()[0]
80 c
.execute("SELECT date FROM %(table)s WHERE key = '%(key)s'" \
81 % { "table" : "config",
84 self
.date
= float("%s" % c
.fetchone()[0])
88 return self
.date
or float(0)
94 sql
= "INSERT INTO %(table)s(key, value, date) VALUES('%(key)s', '%(value)s', '%(date)s')" \
95 % { "table" : "config",
98 "date" : time
.time(), }
101 sql
= "UPDATE %(table)s SET value='%(value)s', date='%(date)s' WHERE key='%(key)s'" \
102 % { "table" : "config",
105 "date" : time
.time(), }
111 class DurationsConfig
:
112 def __init__(self
, db
):
115 def get(self
, sort
=0):
117 c
.execute("SELECT duration FROM durations")
119 for value
in c
.fetchall():
120 value
= int("%s" % value
)
121 if value
< 5400: # 1,5h
128 def set(self
, value
):
131 c
.execute("INSERT INTO %(table)s(duration) VALUES('%(value)s')" \
132 % { "table" : "durations",
139 durations
= self
.get()
140 if not len(durations
):
142 for value
in durations
:
144 avg
= sum / len(durations
)
147 def get_eta(self
, timestamp
):
151 eta
= int(timestamp
) + avg
152 return time
.ctime(eta
)
154 class DistccConfig(DatabaseConfig
):
155 def __init__(self
, db
, key
, hostname
):
156 DatabaseConfig
.__init
__(self
, db
, key
)
157 self
.hostname
= hostname
160 if not self
.ping() or self
.get() == "0":
162 return "%s:%s/4,lzo" % \
163 (socket
.gethostbyname(self
.hostname
), self
.get(),)
166 if not self
.hostname
:
168 return not os
.system("ping -c1 -w1 %s &>/dev/null" % self
.hostname
)
171 return os
.popen("distcc --version").readlines()
174 def __init__(self
, config
, uuid
):
177 self
.path
= os
.path
.join(self
.config
['path']['db'], self
.uuid
)
179 if not os
.access(self
.path
, os
.R_OK
):
185 self
.db
= Database(self
.path
)
187 self
.hostname
= DatabaseConfig(self
.db
, "hostname")
188 self
.state
= DatabaseConfig(self
.db
, "state")
189 self
.package
= DatabaseConfig(self
.db
, "package")
191 self
.duration
= DurationsConfig(self
.db
)
192 self
.distcc
= DistccConfig(self
.db
, "distcc", self
.hostname
.get())
194 def set(self
, key
, value
):
195 eval("self.%s.set(\"%s\")" % (key
, value
,))
198 return eval("self.%s.get()" % (key
,))
200 def getAllBuilders():
202 for uuid
in os
.listdir(config
["path"]["db"]):
203 if uuid
== "empty.txt": continue
204 builder
= Builder(config
, uuid
)
205 builders
.append(builder
)