]> git.ipfire.org Git - ipfire.org.git/commitdiff
Updated some things in builder.
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 15 Nov 2008 21:58:47 +0000 (22:58 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 15 Nov 2008 21:58:47 +0000 (22:58 +0100)
I added a box for distcc hosts and some lines that
clean up the databases by themselves. Nice, eh?

build/builder.py
build/constants.py
build/index.py

index b83591f088ad6464905922264df4cb255776671f..bef9b0a23515a74d08dff44e79e2f54b44296912 100644 (file)
@@ -24,6 +24,7 @@ import sys
 import time
 import socket
 import base64
+import shutil
 from pysqlite2 import dbapi2 as sqlite
 
 sys.path.append(".")
@@ -223,6 +224,31 @@ class Builder:
                self.distcc   = DistccConfig(self.db, "distcc", self.hostname(), self.jobs())
 
                self.log      = FileConfig(self.path, "log")
+               
+               # If host was longer than 3 days in state compiling we set it as idle.
+               if self.state() == "compiling" and \
+                               (time.time() - self.state.time()) > 3*24*60*60:
+                       self.state.set("idle")
+               
+               # If host is idle and distcc is not disabled we set it as distcc host.
+               if self.state() == "idle" and self.distcc() != "0":
+                       self.state.set("distcc")
+
+               # If host is longer than 24h in error state we set it as distcc host.
+               if self.state() == "error" and \
+                               (time.time() - self.state.time()) > 24*60*60:
+                       self.state.set("distcc")
+               
+               # If host was longer than two weeks in distcc state we set it as unknown.
+               if self.state() == "error" and \
+                               (time.time() - self.state.time()) > 2*7*24*60*60:
+                       self.state.set("unknown")
+
+               # If host was longer than four weels in distcc state we delete it.
+               if self.state() == "unknown" and \
+                               (time.time() - self.state.time()) > 4*7*24*60*60:
+                       del self.db
+                       shutil.rmtree(self.path)
 
        def set(self, key, value):
                eval("self.%s.set(\"%s\")" % (key, value,))
index 3c55dd15586d1a502b8f4d8dcc0d9e91bbe00eb8..33008ee1abbfd960668db5f3b7908bda7b1c591e 100644 (file)
 import os
 import time
 
+POINTS_UNKNOWN   = 0
+POINTS_IDLE      = 1
+POINTS_DISTCC    = 2
+POINTS_ERROR     = 4
+POINTS_COMPILING = 8
+
 config = {
        "title"       : "IPFire - Builder",
        "nightly_url" : ("ftp://ftp.ipfire.org/pub/nightly-builds/", "http://www.rowie.at/upload/ipfire/builds/",),
@@ -36,6 +42,7 @@ statedesc = {
        "compiling" : "The host is really hard working at the moment...",
        "error" : "Oops! The host had an error...",
        "idle" : "The host is idle at the moment...",
+       "distcc" : "This host is waiting for distcc requests...",
 }
 
 ping2class = {
@@ -46,6 +53,7 @@ ping2class = {
 state2style = {
        None        : "",
        "compiling" : "background: #8C8; border: 1px solid #0e0;",
+       "distcc"    : "background: #58c; border: 1px solid #8ac;",
        "error"     : "background: #c33; border: 1px solid #e00;",
        "idle"      : "background: #ddd; border: 1px solid #eee;",
 }
index 3a78d12f1b2de352fcee5a5e4c8918581b3d3af2..4315b9bc389ba6950e6b181392d9555739b047b5 100644 (file)
@@ -143,14 +143,6 @@ class Site:
                <body>
                        <div id="header">
                                <h1>IPFire Builder</h1>""" % self.config
-               if self.builders:
-                       print """\
-                               <p>
-                                       """,
-                       for builder in self.builders:
-                               print builder,
-                       print """
-                               </p>"""
                for i in self.config["nightly_url"]:
                        print """\
                                <p><a href="%s" target="_blank">%s</a></p>""" % (i, i,)
@@ -163,52 +155,46 @@ class Site:
 
        def content(self):
                if self.builders:
-                       count = 0
                        print """\
                        <div id="content">"""
                        for builder in self.builders:
-                               builder(count)
-                               count += 1
+                               builder()
                        print """\
                        </div>"""
 
 class Box:
        def __init__(self, builder):
-               self.builder =  builder
-       
-       def __call__(self, count):
-               print """\
-                               <a name="%s"></a>
-                               <div class="box" style="%s">"""\
-                               % (self.builder.hostname(), state2style[self.builder.state()],)
-               print """\
-                                       <div class="infobox">"""
-               self.distccinfo()
-               self.package()
-               self.time()
-               print """\
-                                       </div>"""
-               self.header()
-               self.stateinfo()
-               self.durations()
-               if self.builder.state() == "error":
-                       self.log()
-               self.footer()
-               print """\
-                               </div>"""
+               self.builder = builder
+               self.points = POINTS_UNKNOWN
        
+       def __cmp__(self, other):
+               if self.points > other.points:
+                       return -1
+               elif self.points == other.points:
+                       return 0
+               elif self.points < other.points:
+                       return 1
+
        def __str__(self):
                return """<a href="#%(hostname)s">%(hostname)s</a>""" % { "hostname" : self.builder.hostname(), }
 
+       def open_bigbox(self):
+               print """<a name="%s"></a><div class="box" style="%s">""" \
+                       % (self.builder.hostname(), state2style[self.builder.state()],)
+
+       def open_infobox(self):
+               print """<div class="infobox">"""
+
+       def close_bigbox(self):
+               print """</div>"""
+
+       close_infobox = close_bigbox
+
        def header(self):
-               print """\
-                                       <p class="boxheader">
-                                               %(hostname)s <span>[%(uuid)s]</span>
-                                       </p>
-                                       <!-- <img class="right" src="/images/%(state)s.png" /> -->""" \
-                               % { "hostname" : self.builder.hostname(),
-                                       "state"    : self.builder.state(),
-                                       "uuid"     : self.builder.uuid, }
+               print """<p class="boxheader">%(hostname)s <span>[%(uuid)s]</span></p>""" \
+                       % { "hostname" : self.builder.hostname(),
+                               "state"    : self.builder.state(),
+                               "uuid"     : self.builder.uuid, }
        
        def package(self):
                if self.builder.state() in [ "compiling", "error", ]:
@@ -217,23 +203,18 @@ class Box:
                                % self.builder.package()
        
        def time(self):
-               print """\
-                                               <p>%s</p>""" \
-                               % time.ctime(float(self.builder.state.time()))
+               print """<p>%s</p>""" \
+                       % time.ctime(float(self.builder.state.time()))
        
        def stateinfo(self):
-               if self.builder.state() in [ "compiling", "error", "idle", ]:
-                       print """\
-                                       <p class="desc">%s</p>""" \
-                                % statedesc[self.builder.state()]
+               print """<p class="desc">%s</p>""" \
+                       % statedesc[self.builder.state()]
        
        def durations(self):
-               print """\
-                                       <p>Average Build Duration: %s</p>""" \
-                               % format_time(self.builder.duration.get_avg())
+               print """<p>Average Build Duration: %s</p>""" \
+                       % format_time(self.builder.duration.get_avg())
                if self.builder.state() == "compiling":
-                       print """\
-                                       <p>ETA: %s</p>""" \
+                       print """<p>ETA: %s</p>""" \
                                % self.builder.duration.get_eta(self.builder.state.time())
        
        def distccinfo(self):
@@ -242,34 +223,109 @@ class Box:
                if port == "0":
                        state = False
                        port = "disabled"
-               print """\
-                                               <p class="%s">Distcc: %s</p>""" \
+               print """<p class="%s">Distcc: %s</p>""" \
                                % (ping2class[state], port,)
        
        def log(self):
                log = self.builder.log()
                if log:
-                       print """\
-                                       <div class="log">
-                                               <p>"""
+                       print """<div class="log"><p>"""
                        for i in log:
                                print "%s<br />" % (i.rstrip("\n"),)
-                       print """\
-                                               </p>
-                                       </div>
-                       """
+                       print """</p></div>"""
 
        def footer(self):
-               print """\
-                                       <div class="footer">
-                                               <p>target: %s - jobs: %s</p>
-                                       </div>
-                       """ % (self.builder.target(), self.builder.jobs(),)
+               print """<div class="footer"><p>target: %s - jobs: %s</p></div>""" \
+                       % (self.builder.target(), self.builder.jobs(),)
+
+class BoxCompiling(Box):
+       def __init__(self, builder):
+               Box.__init__(self, builder)
+               self.points = POINTS_COMPILING
+
+       def __call__(self):
+               self.open_bigbox()
+               self.open_infobox()
+               self.distccinfo()
+               self.package()
+               self.time()
+               self.close_infobox()
+               self.header()
+               self.stateinfo()
+               self.durations()
+               self.footer()
+               self.close_bigbox()
+
+class BoxError(Box):
+       def __init__(self, builder):
+               Box.__init__(self, builder)
+               self.points = POINTS_ERROR
+
+       def __call__(self):
+               self.open_bigbox()
+               self.open_infobox()
+               self.distccinfo()
+               self.package()
+               self.time()
+               self.close_infobox()
+               self.header()
+               self.stateinfo()
+               self.durations()
+               self.log()
+               self.footer()
+               self.close_bigbox()
+
+class BoxDistcc(Box):
+       def __init__(self, builder):
+               Box.__init__(self, builder)
+               self.points = POINTS_DISTCC
+
+       def __call__(self):
+               self.open_bigbox()
+               self.open_infobox()
+               self.distccinfo()
+               self.time()
+               self.close_infobox()
+               self.header()
+               self.stateinfo()
+               self.durations()
+               self.footer()
+               self.close_bigbox()
+
+class BoxIdle(Box):
+       def __init__(self, builder):
+               Box.__init__(self, builder)
+               self.points = POINTS_IDLE
+
+       def __call__(self):
+               self.open_bigbox()
+               self.open_infobox()
+               self.distccinfo()
+               self.time()
+               self.close_infobox()
+               self.header()
+               self.stateinfo()
+               self.durations()
+               self.footer()
+               self.close_bigbox()
 
 site = Site(config)
 
 boxes = []
-for builder in getAllBuilders(3):
-       boxes.append(Box(builder))
+for builder in getAllBuilders():
+       box = None
+       if builder.state() == "compiling":
+               box = BoxCompiling(builder)
+       elif builder.state() == "error":
+               box = BoxError(builder)
+       elif builder.state() == "idle":
+               box = BoxIdle(builder)
+       elif builder.state() == "distcc":
+               if builder.distcc() == "0":
+                       continue
+               box = BoxDistcc(builder)
+       if box:
+               boxes.append(box)
 
+boxes.sort()
 site(boxes)