Make the fix script update revision details.
authorJelmer Vernooij <jelmer@samba.org>
Sun, 21 Nov 2010 21:35:31 +0000 (22:35 +0100)
committerJelmer Vernooij <jelmer@samba.org>
Sun, 21 Nov 2010 21:35:31 +0000 (22:35 +0100)
buildfarm/data.py
tools/fix-status.py [deleted file]
tools/fix.py [new file with mode: 0755]

index d1b8f17..90345f8 100644 (file)
@@ -45,7 +45,7 @@ BuildStageResult = collections.namedtuple("BuildStageResult", "name result")
 class MissingRevisionInfo(Exception):
     """Revision info could not be found in the build log."""
 
-    def __init__(self, build):
+    def __init__(self, build=None):
         self.build = build
 
 
@@ -199,6 +199,19 @@ def build_status_from_logs(log, err):
     return ret
 
 
+def revision_from_log(log):
+    revid = None
+    timestamp = None
+    for l in log:
+        if l.startswith("BUILD COMMIT REVISION: "):
+            revid = l.split(":", 1)[1].strip()
+        elif l.startswith("BUILD COMMIT TIME"):
+            timestamp = l.split(":", 1)[1].strip()
+    if revid is None:
+        raise MissingRevisionInfo()
+    return (revid, timestamp)
+
+
 class NoSuchBuildError(Exception):
     """The build with the specified name does not exist."""
 
@@ -236,7 +249,9 @@ class Build(object):
             return "<%s: %s on %s using %s>" % (self.__class__.__name__, self.tree, self.host, self.compiler)
 
     def remove_logs(self):
-        os.unlink(self.basename + ".log")
+        # In general, basename.log should *always* exist.
+        if os.path.exists(self.basename+".log"):
+            os.unlink(self.basename + ".log")
         if os.path.exists(self.basename+".err"):
             os.unlink(self.basename+".err")
 
@@ -286,23 +301,12 @@ class Build(object):
 
         :return: Tuple with revision id and timestamp (if available)
         """
-        revid = None
-        timestamp = None
         f = self.read_log()
         try:
-            for l in f:
-                if l.startswith("BUILD COMMIT REVISION: "):
-                    revid = l.split(":", 1)[1].strip()
-                elif l.startswith("BUILD COMMIT TIME"):
-                    timestamp = l.split(":", 1)[1].strip()
+            return revision_from_log(f)
         finally:
             f.close()
 
-        if revid is None:
-            raise MissingRevisionInfo(self)
-
-        return (revid, timestamp)
-
     def status(self):
         """get status of build
 
diff --git a/tools/fix-status.py b/tools/fix-status.py
deleted file mode 100644 (file)
index 958475f..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-#!/usr/bin/python
-
-from buildfarm.data import build_status_from_logs, LogFileMissing
-
-from buildfarm.sqldb import StormCachingBuildFarm, StormBuild
-
-x = StormCachingBuildFarm()
-
-store = x._get_store()
-for build in store.find(StormBuild, StormBuild.status_str == None):
-    try:
-        log = build.read_log()
-    except LogFileMissing:
-        log.remove()
-        continue
-    try:
-        err = build.read_err()
-        try:
-            status = build_status_from_logs(log, err)
-        finally:
-            err.close()
-    finally:
-        log.close()
-    build.status_str = status.__serialize__()
diff --git a/tools/fix.py b/tools/fix.py
new file mode 100755 (executable)
index 0000000..c57cf6c
--- /dev/null
@@ -0,0 +1,53 @@
+#!/usr/bin/python
+
+import os
+import sys
+sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
+
+from buildfarm.data import (
+    build_status_from_logs,
+    LogFileMissing,
+    MissingRevisionInfo,
+    revision_from_log,
+    )
+
+from buildfarm.sqldb import StormCachingBuildFarm, StormBuild
+
+buildfarm = StormCachingBuildFarm()
+
+store = buildfarm._get_store()
+
+for build in store.find(StormBuild, StormBuild.status_str == None):
+    try:
+        log = build.read_log()
+    except LogFileMissing:
+        print "Killing build %r without status string or log." % build
+        log.remove()
+        continue
+    try:
+        err = build.read_err()
+        try:
+            status = build_status_from_logs(log, err)
+        finally:
+            err.close()
+    finally:
+        log.close()
+    build.status_str = status.__serialize__()
+    print "Updating status for %r" % build
+
+for build in store.find(StormBuild, StormBuild.revision == None):
+    try:
+        log = build.read_log()
+    except LogFileMissing:
+        print "Killing build %r without revision or log." % build
+        build.remove()
+        continue
+    try:
+        (revision, revision_time) = revision_from_log(log)
+    except MissingRevisionInfo:
+        continue
+    assert revision
+    build.revision = revision
+    print "Updating revision for %r" % build
+
+buildfarm.commit()