[SCM] build.samba.org - branch master updated
Jelmer Vernooij
jelmer at samba.org
Tue Nov 2 03:53:09 MDT 2010
The branch, master has been updated
via 1fd8f4c Split off caching into a separate subclass.
from 0176213 Split out html formatting from build status.
http://gitweb.samba.org/?p=build-farm.git;a=shortlog;h=master
- Log -----------------------------------------------------------------
commit 1fd8f4c9855d0d607064e22688e8578c363192a6
Author: Jelmer Vernooij <jelmer at samba.org>
Date: Tue Nov 2 10:53:27 2010 +0100
Split off caching into a separate subclass.
-----------------------------------------------------------------------
Summary of changes:
buildfarm/data.py | 101 +++++++++++++++++++++++----------------
buildfarm/tests/test_history.py | 6 +-
2 files changed, 62 insertions(+), 45 deletions(-)
Changeset truncated at 500 lines:
diff --git a/buildfarm/data.py b/buildfarm/data.py
index 303885d..887ea6b 100644
--- a/buildfarm/data.py
+++ b/buildfarm/data.py
@@ -110,24 +110,6 @@ class Build(object):
:return: Tuple with revision id and timestamp (if available)
"""
file = self._store.build_fname(self.tree, self.host, self.compiler, self.rev)
- cachef = self._store.cache_fname(self.tree, self.host, self.compiler, self.rev)
-
- st1 = os.stat("%s.log" % file)
-
- try:
- st2 = os.stat("%s.revision" % cachef)
- except OSError:
- # File does not exist
- st2 = None
-
- # the ctime/mtime asymmetry is needed so we don't get fooled by
- # the mtime update from rsync
- if st2 and st1.st_ctime <= st2.st_mtime:
- (revid, timestamp) = util.FileLoad("%s.revision" % cachef).split(":", 1)
- if timestamp == "":
- return (revid, None)
- else:
- return (revid, timestamp)
revid = None
timestamp = None
@@ -143,9 +125,6 @@ class Build(object):
finally:
f.close()
- if not self._store.readonly:
- util.FileSave("%s.revision" % cachef, "%s:%s" % (revid, timestamp or ""))
-
return (revid, timestamp)
def status(self):
@@ -155,34 +134,55 @@ class Build(object):
"""
# FIXME: This should return a tuple
+ log = self.read_log()
+ err = self.read_err()
+
+ return self._store.html_build_status_from_logs(log, err)
+
+ def err_count(self):
+ """get status of build"""
file = self._store.build_fname(self.tree, self.host, self.compiler, self.rev)
- cachefile = self._store.cache_fname(self.tree, self.host, self.compiler, self.rev)+".status"
- st1 = os.stat("%s.log" % file)
try:
- st2 = os.stat(cachefile)
+ err = util.FileLoad("%s.err" % file)
except OSError:
- # No such file
- st2 = None
+ # File does not exist
+ return 0
- if st2 and st1.st_ctime <= st2.st_mtime:
- return util.FileLoad(cachefile)
+ return util.count_lines(err)
- log = self.read_log()
- err = self.read_err()
- ret = self._store.html_build_status_from_logs(log, err)
+class CachingBuild(Build):
+ """Build subclass that caches some of the results that are expensive
+ to calculate."""
- if not self._store.readonly:
- util.FileSave(cachefile, ret)
+ def revision_details(self):
+ file = self._store.build_fname(self.tree, self.host, self.compiler, self.rev)
+ cachef = self._store.cache_fname(self.tree, self.host, self.compiler, self.rev)
+ st1 = os.stat("%s.log" % file)
- return ret
+ try:
+ st2 = os.stat("%s.revision" % cachef)
+ except OSError:
+ # File does not exist
+ st2 = None
+
+ # the ctime/mtime asymmetry is needed so we don't get fooled by
+ # the mtime update from rsync
+ if st2 and st1.st_ctime <= st2.st_mtime:
+ (revid, timestamp) = util.FileLoad("%s.revision" % cachef).split(":", 1)
+ if timestamp == "":
+ return (revid, None)
+ else:
+ return (revid, timestamp)
+ (revid, timestamp) = super(CachingBuild, self).revision_details()
+ if not self._store.readonly:
+ util.FileSave("%s.revision" % cachef, "%s:%s" % (revid, timestamp or ""))
+ return (revid, timestamp)
def err_count(self):
- """get status of build"""
file = self._store.build_fname(self.tree, self.host, self.compiler, self.rev)
cachef = self._store.cache_fname(self.tree, self.host, self.compiler, self.rev)
-
st1 = os.stat("%s.err" % file)
try:
@@ -194,20 +194,37 @@ class Build(object):
if st2 and st1.st_ctime <= st2.st_mtime:
return util.FileLoad("%s.errcount" % cachef)
+ ret = super(CachingBuild, self).err_count()
+
+ if not self._store.readonly:
+ util.FileSave("%s.errcount" % cachef, str(ret))
+
+ return ret
+
+ def status(self):
+ file = self._store.build_fname(self.tree, self.host, self.compiler, self.rev)
+ cachefile = self._store.cache_fname(self.tree, self.host, self.compiler, self.rev)+".status"
+
+ st1 = os.stat("%s.log" % file)
+
try:
- err = util.FileLoad("%s.err" % file)
+ st2 = os.stat(cachefile)
except OSError:
- # File does not exist
- return 0
+ # No such file
+ st2 = None
- ret = util.count_lines(err)
+ if st2 and st1.st_ctime <= st2.st_mtime:
+ return util.FileLoad(cachefile)
+
+ ret = super(CachingBuild, self).status()
if not self._store.readonly:
- util.FileSave("%s.errcount" % cachef, str(ret))
+ util.FileSave(cachefile, ret)
return ret
+
def read_trees_from_conf(path):
"""Read trees from a configuration file."""
ret = {}
@@ -256,7 +273,7 @@ class BuildResultStore(object):
logf = self.build_fname(tree, host, compiler, rev) + ".log"
if not os.path.exists(logf):
raise NoSuchBuildError(tree, host, compiler, rev)
- return Build(self, tree, host, compiler, rev)
+ return CachingBuild(self, tree, host, compiler, rev)
def cache_fname(self, tree, host, compiler, rev=None):
if rev is not None:
diff --git a/buildfarm/tests/test_history.py b/buildfarm/tests/test_history.py
index 8945615..7f80259 100644
--- a/buildfarm/tests/test_history.py
+++ b/buildfarm/tests/test_history.py
@@ -5,16 +5,16 @@
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
-#
+#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
-#
+#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-import unittest
+import testtools
from buildfarm import history
--
build.samba.org
More information about the samba-cvs
mailing list