Make the fix script update revision details.
[amitay/build-farm.git] / tools / fix.py
1 #!/usr/bin/python
2
3 import os
4 import sys
5 sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
6
7 from buildfarm.data import (
8     build_status_from_logs,
9     LogFileMissing,
10     MissingRevisionInfo,
11     revision_from_log,
12     )
13
14 from buildfarm.sqldb import StormCachingBuildFarm, StormBuild
15
16 buildfarm = StormCachingBuildFarm()
17
18 store = buildfarm._get_store()
19
20 for build in store.find(StormBuild, StormBuild.status_str == None):
21     try:
22         log = build.read_log()
23     except LogFileMissing:
24         print "Killing build %r without status string or log." % build
25         log.remove()
26         continue
27     try:
28         err = build.read_err()
29         try:
30             status = build_status_from_logs(log, err)
31         finally:
32             err.close()
33     finally:
34         log.close()
35     build.status_str = status.__serialize__()
36     print "Updating status for %r" % build
37
38 for build in store.find(StormBuild, StormBuild.revision == None):
39     try:
40         log = build.read_log()
41     except LogFileMissing:
42         print "Killing build %r without revision or log." % build
43         build.remove()
44         continue
45     try:
46         (revision, revision_time) = revision_from_log(log)
47     except MissingRevisionInfo:
48         continue
49     assert revision
50     build.revision = revision
51     print "Updating revision for %r" % build
52
53 buildfarm.commit()