From: Michael Tremer Date: Sat, 25 Oct 2008 22:16:08 +0000 (+0200) Subject: [build] Added "jobs" and "log". X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=10da7ad42ede37bb850c145cf8b57b4b81eb374d;p=ipfire.org.git [build] Added "jobs" and "log". --- diff --git a/build/builder.py b/build/builder.py index 6b0658c4..80ff9002 100644 --- a/build/builder.py +++ b/build/builder.py @@ -23,6 +23,7 @@ import os import sys import time import socket +import base64 from pysqlite2 import dbapi2 as sqlite sys.path.append(".") @@ -152,15 +153,16 @@ class DurationsConfig: return time.ctime(eta) class DistccConfig(DatabaseConfig): - def __init__(self, db, key, hostname): + def __init__(self, db, key, hostname, jobs): DatabaseConfig.__init__(self, db, key) self.hostname = hostname + self.jobs = jobs def __str__(self): if not self.ping() or self.get() == "0": return "" - return "%s:%s/4,lzo" % \ - (socket.gethostbyname(self.hostname), self.get(),) + return "%s:%s/%s,lzo \t# %s" % \ + (socket.gethostbyname(self.hostname), self.get(), self.jobs or "4", self.hostname) def ping(self): if not self.hostname: @@ -170,6 +172,33 @@ class DistccConfig(DatabaseConfig): def version(self): return os.popen("distcc --version").readlines() +class FileConfig: + def __init__(self, path, filetype): + self.filename = os.path.join(path, config["path"][filetype]) + + # Create the file if not existant + if not os.access(self.filename, os.R_OK): + f = open(self.filename, "w") + f.close() + + def get(self): + ret = [] + try: + f = open(self.filename) + ret = f.readlines() + f.close() + except: + pass + return ret or ["Log is empty."] + + __call__ = get + + def set(self, lines): + f = open(self.filename, "w") + for line in base64.b64decode(lines).split("\n"): + f.write("%s\n" % line.rstrip("\n")) + f.close() + class Builder: def __init__(self, config, uuid): self.uuid = uuid @@ -183,13 +212,16 @@ class Builder: pass self.db = Database(self.path) - + self.hostname = DatabaseConfig(self.db, "hostname") self.state = DatabaseConfig(self.db, "state") self.package = DatabaseConfig(self.db, "package") - + self.duration = DurationsConfig(self.db) - self.distcc = DistccConfig(self.db, "distcc", self.hostname.get()) + self.jobs = DatabaseConfig(self.db, "jobs") + self.distcc = DistccConfig(self.db, "distcc", self.hostname(), self.jobs()) + + self.log = FileConfig(self.path, "log") def set(self, key, value): eval("self.%s.set(\"%s\")" % (key, value,)) diff --git a/build/constants.py b/build/constants.py index 5e99fc7d..3c55dd15 100644 --- a/build/constants.py +++ b/build/constants.py @@ -25,7 +25,7 @@ import time config = { "title" : "IPFire - Builder", "nightly_url" : ("ftp://ftp.ipfire.org/pub/nightly-builds/", "http://www.rowie.at/upload/ipfire/builds/",), - "path" : { "db" : "db", }, + "path" : { "db" : "db", "log" : "error.log", }, "script" : os.environ['SCRIPT_NAME'], "db_name" : "builder.db", } @@ -47,5 +47,5 @@ state2style = { None : "", "compiling" : "background: #8C8; border: 1px solid #0e0;", "error" : "background: #c33; border: 1px solid #e00;", - "idle" : "height: 60px; background: #ddd; border: 1px solid #eee;", + "idle" : "background: #ddd; border: 1px solid #eee;", } diff --git a/build/index.py b/build/index.py index 75c800e6..8e817109 100644 --- a/build/index.py +++ b/build/index.py @@ -87,13 +87,22 @@ class Site: div.box { padding: 5px; margin: 10px 0 10px 0; - height: 80px; + /* height: 80px; */ border: 1px solid; } div.infobox { float: right; width: 240px; } + div.log { + background: #e55; + border: 1px dotted; + margin-top: 12px; + /* visibility: hidden; */ + } + div.log p { + font-family: Courier New; + } p { margin: 2px; } @@ -176,6 +185,8 @@ class Box: self.header() self.stateinfo() self.durations() + if self.builder.state() == "error": + self.log() print """\ """ @@ -227,6 +238,19 @@ class Box: print """\

Distcc: %s

""" \ % (ping2class[state], port,) + + def log(self): + log = self.builder.log() + if log: + print """\ +
+

""" + for i in log: + print "%s
" % (i.rstrip("\n"),) + print """\ +

+
+ """ site = Site(config) diff --git a/build/rpc.py b/build/rpc.py index 81058485..a936161d 100644 --- a/build/rpc.py +++ b/build/rpc.py @@ -66,7 +66,7 @@ if action == "set": builder = Builder(config, uuid) key = None - for key in [ "distcc", "duration", "hostname", "state", "package", ]: + for key in [ "distcc", "duration", "hostname", "jobs", "log", "state", "package", ]: for value in data.getlist(key): builder.set(key, value) elif action == "get": @@ -75,10 +75,13 @@ elif action == "get": for value in data.getlist(key): if value == "raw": builders = [] + jobs = "4" for builder in getAllBuilders(): - if uuid == builder.uuid: continue + if uuid == builder.uuid: + jobs = builder.jobs() + continue builders.append("%s" % builder.distcc) - string = "localhost/1\n--randomize\n" + string = "localhost/%s\n--randomize\n" % (jobs or "4",) while True: if not builders: break rand = random.randint(0, len(builders)-1)