[SCM] build.samba.org - branch master updated
Jelmer Vernooij
jelmer at samba.org
Fri Nov 19 10:57:30 MST 2010
The branch, master has been updated
via 2b0f377 Fix sorting, right builds in results.
from 6650dcc remove unused variables.
http://gitweb.samba.org/?p=build-farm.git;a=shortlog;h=master
- Log -----------------------------------------------------------------
commit 2b0f377663586319c14cf8387f52cf9e9f0c7079
Author: Jelmer Vernooij <jelmer at samba.org>
Date: Fri Nov 19 18:56:55 2010 +0100
Fix sorting, right builds in results.
-----------------------------------------------------------------------
Summary of changes:
buildfarm/__init__.py | 16 +++++++++-------
buildfarm/data.py | 18 +++++++++++++++---
buildfarm/sqldb.py | 12 +++++++-----
buildfarm/tests/__init__.py | 11 +++++++----
buildfarm/tests/test_buildfarm.py | 29 +++++++++++++----------------
buildfarm/tests/test_data.py | 4 ++--
6 files changed, 53 insertions(+), 37 deletions(-)
Changeset truncated at 500 lines:
diff --git a/buildfarm/__init__.py b/buildfarm/__init__.py
index 71bf02a..2411862 100644
--- a/buildfarm/__init__.py
+++ b/buildfarm/__init__.py
@@ -95,11 +95,13 @@ class BuildFarm(object):
def _open_build_results(self):
from buildfarm import data
- return data.BuildResultStore(os.path.join(self.path, "data", "oldrevs"))
+ path = os.path.join(self.path, "data", "oldrevs")
+ return data.BuildResultStore(path)
def _open_upload_build_results(self):
from buildfarm import data
- return data.UploadBuildResultStore(os.path.join(self.path, "data", "upload"))
+ path = os.path.join(self.path, "data", "upload")
+ return data.UploadBuildResultStore(path)
def _open_hostdb(self):
from buildfarm import hostdb
@@ -142,15 +144,15 @@ class BuildFarm(object):
yield build
def get_last_builds(self):
- return self.get_new_builds()
+ return sorted(self.get_new_builds(), reverse=True)
def get_tree_builds(self, tree):
- yielded = set()
+ ret = []
for build in self.builds.get_all_builds():
if build.tree == tree:
- if not (build.host, build.compiler) in yielded:
- yielded.add((build.host, build.compiler))
- yield build
+ ret.append(build)
+ ret.sort(reverse=True)
+ return ret
def get_host_builds(self, host):
from buildfarm import data
diff --git a/buildfarm/data.py b/buildfarm/data.py
index cf87904..96b68e6 100644
--- a/buildfarm/data.py
+++ b/buildfarm/data.py
@@ -216,8 +216,14 @@ class Build(object):
self.compiler = compiler
self.commit_revision = self.revision = rev
+ def __cmp__(self, other):
+ return cmp(
+ (self.upload_time, self.revision, self.host, self.tree, self.compiler),
+ (other.upload_time, other.revision, other.host, other.tree, other.compiler))
+
def __eq__(self, other):
- return (self.log_checksum() == other.log_checksum())
+ return (isinstance(other, Build) and
+ self.log_checksum() == other.log_checksum())
def __repr__(self):
if self.revision is not None:
@@ -234,10 +240,16 @@ class Build(object):
self.remove_logs()
@property
+ def upload_time(self):
+ """get timestamp of build"""
+ st = os.stat("%s.log" % self.basename)
+ return st.st_mtime
+
+ @property
def age(self):
"""get the age of build"""
st = os.stat("%s.log" % self.basename)
- return time.time() - st.st_ctime
+ return time.time() - self.upload_time
def read_log(self):
"""read full log file"""
@@ -399,7 +411,7 @@ class BuildResultStore(object):
for build in self.get_all_builds():
if build.tree == tree and build.host == host and build.compiler == compiler:
ret.append(build)
- ret.sort(lambda a, b: cmp(a.age, b.age))
+ ret.sort(lambda a, b: cmp(a.upload_time, b.upload_time))
return ret
def upload_build(self, build):
diff --git a/buildfarm/sqldb.py b/buildfarm/sqldb.py
index f816dd6..540e8a5 100644
--- a/buildfarm/sqldb.py
+++ b/buildfarm/sqldb.py
@@ -52,7 +52,7 @@ class StormBuild(Build):
host = RawStr()
compiler = RawStr()
checksum = RawStr()
- age = Int()
+ upload_time = Int(name="age")
status_str = RawStr(name="status")
commit_revision = RawStr()
@@ -205,7 +205,7 @@ class StormCachingBuildResultStore(BuildResultStore):
new_build = StormBuild(new_basename, build.tree, build.host,
build.compiler, rev)
new_build.checksum = build.log_checksum()
- new_build.age = build.age
+ new_build.upload_time = build.upload_time
new_build.status_str = build.status().__serialize__()
self.store.add(new_build)
return new_build
@@ -214,7 +214,7 @@ class StormCachingBuildResultStore(BuildResultStore):
return self.store.find(StormBuild,
StormBuild.tree == tree,
StormBuild.host == host,
- StormBuild.compiler == compiler).order_by(Desc(StormBuild.age))
+ StormBuild.compiler == compiler).order_by(Desc(StormBuild.upload_time))
class StormCachingBuildFarm(BuildFarm):
@@ -250,10 +250,12 @@ class StormCachingBuildFarm(BuildFarm):
def get_tree_builds(self, tree):
return self._get_store().find(StormBuild,
- StormBuild.tree == tree).group_by(StormBuild.compiler, StormBuild.host)
+ StormBuild.tree == tree).order_by(Desc(StormBuild.upload_time))
def get_last_builds(self):
- return self._get_store().find(StormBuild).group_by(StormBuild.tree, StormBuild.compiler, StormBuild.host)
+ return self._get_store().find(StormBuild).group_by(
+ StormBuild.tree, StormBuild.compiler, StormBuild.host).order_by(
+ Desc(StormBuild.upload_time))
def commit(self):
self.store.commit()
diff --git a/buildfarm/tests/__init__.py b/buildfarm/tests/__init__.py
index 26cbebe..b510dbb 100644
--- a/buildfarm/tests/__init__.py
+++ b/buildfarm/tests/__init__.py
@@ -29,15 +29,16 @@ class BuildFarmTestCase(TestCase):
"""Test case class that provides a build farm data directory and convenience methods.
"""
- def upload_mock_logfile(self, store, tree, host, compiler, stdout_contents="", stderr_contents=None):
- log_path = self.create_mock_logfile(tree, host, compiler, contents=stdout_contents)
+ def upload_mock_logfile(self, store, tree, host, compiler,
+ stdout_contents="", stderr_contents=None, mtime=None):
+ log_path = self.create_mock_logfile(tree, host, compiler, contents=stdout_contents, mtime=mtime)
if stderr_contents is not None:
- err_path = self.create_mock_logfile(tree, host, compiler, kind="stderr", contents=stderr_contents)
+ err_path = self.create_mock_logfile(tree, host, compiler, kind="stderr", contents=stderr_contents, mtime=mtime)
build = Build(log_path[:-4], tree, host, compiler)
store.upload_build(build)
def create_mock_logfile(self, tree, host, compiler, rev=None,
- kind="stdout", contents="FOO"):
+ kind="stdout", contents="FOO", mtime=None):
basename = "build.%s.%s.%s" % (tree, host, compiler)
if rev is not None:
basename += "-%s" % rev
@@ -55,6 +56,8 @@ class BuildFarmTestCase(TestCase):
f.write(contents)
finally:
f.close()
+ if mtime is not None:
+ os.utime(path, (mtime, mtime))
return path
def write_compilers(self, compilers):
diff --git a/buildfarm/tests/test_buildfarm.py b/buildfarm/tests/test_buildfarm.py
index 986462f..a2af72a 100644
--- a/buildfarm/tests/test_buildfarm.py
+++ b/buildfarm/tests/test_buildfarm.py
@@ -90,32 +90,29 @@ class BuildFarmTestBase(object):
def test_get_tree_builds(self):
path = self.upload_mock_logfile(self.x.builds, "tdb", "myhost", "cc",
- "BUILD COMMIT REVISION: 12\n")
+ stdout_contents="BUILD COMMIT REVISION: 12\n", mtime=1200)
path = self.upload_mock_logfile(self.x.builds, "tdb", "myhost", "cc",
- "BUILD COMMIT REVISION: 13\n")
+ stdout_contents="BUILD COMMIT REVISION: 13\n", mtime=1300)
path = self.upload_mock_logfile(self.x.builds, "tdb", "myhost", "cc",
- "BUILD COMMIT REVISION: 42\n")
+ stdout_contents="BUILD COMMIT REVISION: 42\n", mtime=4200)
builds = list(self.x.get_tree_builds("tdb"))
- self.assertEquals(1, len(builds))
- build = builds[0]
- self.assertEquals("42", build.revision)
+ self.assertEquals(["42", "13", "12"], [x.revision for x in builds])
def test_get_last_builds(self):
path = self.upload_mock_logfile(self.x.builds, "other", "myhost", "cc",
- "BUILD COMMIT REVISION: 12\n")
+ "BUILD COMMIT REVISION: 12\n", mtime=1200)
path = self.upload_mock_logfile(self.x.builds, "trivial", "myhost", "cc",
- "BUILD COMMIT REVISION: 13\n")
+ "BUILD COMMIT REVISION: 13\n", mtime=1300)
path = self.upload_mock_logfile(self.x.builds, "trivial", "myhost", "cc",
- "BUILD COMMIT REVISION: 42\n")
+ "BUILD COMMIT REVISION: 42\n", mtime=4200)
builds = list(self.x.get_last_builds())
- builds.sort()
self.assertEquals(2, len(builds))
- build = builds[0]
- self.assertEquals("42", build.revision_details()[0])
- self.assertEquals("trivial", build.tree)
- build = builds[1]
- self.assertEquals("12", build.revision_details()[0])
- self.assertEquals("other", build.tree)
+ self.assertEquals(4200, builds[0].upload_time)
+ self.assertEquals("42", builds[0].revision_details()[0])
+ self.assertEquals("trivial", builds[0].tree)
+ self.assertEquals(1200, builds[1].upload_time)
+ self.assertEquals("12", builds[1].revision_details()[0])
+ self.assertEquals("other", builds[1].tree)
def test_get_host_builds_empty(self):
self.assertEquals([], list(self.x.get_host_builds("myhost")))
diff --git a/buildfarm/tests/test_data.py b/buildfarm/tests/test_data.py
index cf4d906..4fdd149 100755
--- a/buildfarm/tests/test_data.py
+++ b/buildfarm/tests/test_data.py
@@ -58,9 +58,9 @@ class BuildResultStoreTestBase(object):
def test_build_age_ctime(self):
path = self.create_mock_logfile("tdb", "charis", "cc", "12")
# Set mtime to something in the past
+ os.utime(path, (5, 5))
build = self.x.get_build("tdb", "charis", "cc", "12")
- age = build.age
- self.assertTrue(age >= 0 and age <= 10, "age was %d" % age)
+ self.assertEquals(5, build.upload_time)
def test_read_log(self):
path = self.create_mock_logfile("tdb", "charis", "cc", "12",
--
build.samba.org
More information about the samba-cvs
mailing list