return ret
+def lcov_extract_percentage(text):
+ m = re.search('\<td class="headerItem".*?\>Code\ \;covered\:\<\/td\>.*?\n.*?\<td class="headerValue".*?\>([0-9.]+) \%', text)
+ if m:
+ return m.group(1)
+ else:
+ return None
+
+
class BuildFarm(object):
+ LCOVHOST = "magni"
+ OLDAGE = 60*60*4,
+ DEADAGE = 60*60*24*4
+
def __init__(self, path=None):
if path is None:
path = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
if not os.path.isdir(path):
raise Exception("web directory %s does not exist" % self.webdir)
self.trees = read_trees_from_conf(os.path.join(self.webdir, "trees.conf"))
+ self.builds = self._open_build_results()
self.hostdb = self._open_hostdb()
self.compilers = self._load_compilers()
+ self.lcovdir = os.path.join(self.path, "lcov/data")
def __repr__(self):
return "%s(%r)" % (self.__class__.__name__, self.path)
+ def _open_build_results(self):
+ from buildfarm import data
+ return data.BuildResultStore(self.path)
+
def _open_hostdb(self):
from buildfarm import hostdb
return hostdb.HostDatabase(
def _load_compilers(self):
from buildfarm import util
return util.load_list(os.path.join(self.webdir, "compilers.list"))
+
+ def lcov_status(self, tree):
+ """get status of build"""
+ from buildfarm import data, util
+ cachefile = os.path.join(self.builds.cachedir, "lcov.%s.%s.status" % (
+ self.LCOVHOST, tree))
+ file = os.path.join(self.lcovdir, self.LCOVHOST, tree, "index.html")
+ try:
+ st1 = os.stat(file)
+ except OSError:
+ # File does not exist
+ raise data.NoSuchBuildError(tree, self.LCOVHOST, "lcov")
+ try:
+ st2 = os.stat(cachefile)
+ except OSError:
+ # file does not exist
+ st2 = None
+
+ if st2 and st1.st_ctime <= st2.st_mtime:
+ ret = util.FileLoad(cachefile)
+ if ret == "":
+ return None
+ return ret
+
+ lcov_html = util.FileLoad(file)
+ perc = lcov_extract_percentage(lcov_html)
+ if perc is None:
+ ret = ""
+ else:
+ ret = perc
+ if self.readonly:
+ util.FileSave(cachefile, ret)
+ return perc
return ret
-def lcov_extract_percentage(text):
- m = re.search('\<td class="headerItem".*?\>Code\ \;covered\:\<\/td\>.*?\n.*?\<td class="headerValue".*?\>([0-9.]+) \%', text)
- if m:
- return m.group(1)
- else:
- return None
-
-
class NoSuchBuildError(Exception):
"""The build with the specified name does not exist."""
class BuildResultStore(object):
"""The build farm build result database."""
- OLDAGE = 60*60*4,
- DEADAGE = 60*60*24*4
- LCOVHOST = "magni"
-
def __init__(self, basedir, readonly=False):
"""Open the database.
self.cachedir = os.path.join(basedir, "cache")
check_dir_exists("cache", self.cachedir)
- self.lcovdir = os.path.join(basedir, "lcov/data")
- check_dir_exists("lcov", self.lcovdir)
-
def get_build(self, tree, host, compiler, rev=None):
logf = self.build_fname(tree, host, compiler, rev) + ".log"
if not os.path.exists(logf):
return os.path.join(self.datadir, "oldrevs/build.%s.%s.%s-%s" % (tree, host, compiler, rev))
return os.path.join(self.datadir, "upload/build.%s.%s.%s" % (tree, host, compiler))
- def lcov_status(self, tree):
- """get status of build"""
- cachefile = os.path.join(self.cachedir, "lcov.%s.%s.status" % (
- self.LCOVHOST, tree))
- file = os.path.join(self.lcovdir, self.LCOVHOST, tree, "index.html")
- try:
- st1 = os.stat(file)
- except OSError:
- # File does not exist
- raise NoSuchBuildError(tree, self.LCOVHOST, "lcov")
- try:
- st2 = os.stat(cachefile)
- except OSError:
- # file does not exist
- st2 = None
-
- if st2 and st1.st_ctime <= st2.st_mtime:
- ret = util.FileLoad(cachefile)
- if ret == "":
- return None
- return ret
-
- lcov_html = util.FileLoad(file)
- perc = lcov_extract_percentage(lcov_html)
- if perc is None:
- ret = ""
- else:
- ret = perc
- if self.readonly:
- util.FileSave(cachefile, ret)
- return perc
-
def get_old_revs(self, tree, host, compiler):
"""get a list of old builds and their status."""
ret = []
# host.properties are unicode object and the framework expect string object
hosts = dict([(host.name.encode("utf-8"), host) for host in hostsdb.hosts()])
trees = buildfarm.trees
-OLDAGE = db.OLDAGE
+OLDAGE = buildfarm.OLDAGE
UNPACKED_BASE = "http://svn.samba.org/ftp/unpacked"
GITWEB_BASE = "http://gitweb.samba.org"
yield "<td>"
yield "%d</td>" % panic_count[tree]
try:
- lcov_status = db.lcov_status(tree)
+ lcov_status = buildfarm.lcov_status(tree)
except data.NoSuchBuildError:
yield "<td></td>"
else:
if lcov_status is not None:
- yield "<td><a href=\"/lcov/data/%s/%s\">%s %%</a></td>" % (db.LCOVHOST, tree, lcov_status)
+ yield "<td><a href=\"/lcov/data/%s/%s\">%s %%</a></td>" % (buildfarm.LCOVHOST, tree, lcov_status)
else:
yield "<td></td>"
yield "</tr>"