blob: f4da9ab2b9b939789e94e1a4e31517ef597ef26f [file] [log] [blame]
Benny Prijonoa6b3e7c2010-08-16 12:18:20 +00001#!/usr/bin/python
2import os
3import sys
4import time
Benny Prijono4adead22010-08-16 12:33:52 +00005import datetime
Benny Prijonoa6b3e7c2010-08-16 12:18:20 +00006import ccdash
7
Benny Prijonoa72cdca2010-08-17 14:53:09 +00008INTERVAL = 300
Benny Prijonoa10b3dd2010-08-23 09:16:03 +00009DELAY = 0
Benny Prijono719e5742010-08-25 12:51:29 +000010CMDLINE = ""
Benny Prijonoa6b3e7c2010-08-16 12:18:20 +000011
Benny Prijono719e5742010-08-25 12:51:29 +000012def run_cmdline(group):
13 cmdline = CMDLINE + " --group " + group
14 return os.system(cmdline)
Benny Prijono20c26f02010-08-18 03:18:24 +000015
16
Benny Prijonoa10b3dd2010-08-23 09:16:03 +000017def usage():
18 print """Periodically monitor working directory for Continuous and Nightly builds
19
20Usage:
Benny Prijono719e5742010-08-25 12:51:29 +000021 run_continuous.py [options] "cmdline"
22
23where:
24 cmdline is command to be executed to perform the test. Typically, this is
25 a script that calls configure.py and run_scenario.py for each scenario to
26 be performed. See perform_test.sh.sample and perform_test.bat.sample for
27 sample scripts. Note that the cmdline will be called with added group
28 argument (e.g. --group Nightly).
Benny Prijonoa10b3dd2010-08-23 09:16:03 +000029
30options:
31 These are options which will be processed by run_continuous.py:
32
33 --delay MIN Delay both Continuous and Nightly builds by MIN minutes.
34 This is useful to coordinate the build with other build
35 machines. By default, Continuous build will be done right
36 after changes are detected, and Nightly build will be done
37 at 00:00 GMT. MIN is a float number.
38
39"""
40 sys.exit(1)
41
Benny Prijonoa6b3e7c2010-08-16 12:18:20 +000042if __name__ == "__main__":
Benny Prijonoa10b3dd2010-08-23 09:16:03 +000043 if len(sys.argv)<=1 or sys.argv[1]=="-h" or sys.argv[1]=="--h" or sys.argv[1]=="--help" or sys.argv[1]=="/h":
44 usage()
Benny Prijonoa6b3e7c2010-08-16 12:18:20 +000045
Benny Prijono719e5742010-08-25 12:51:29 +000046 # Check args
Benny Prijonoa10b3dd2010-08-23 09:16:03 +000047 i = 1
48 while i < len(sys.argv):
49 if sys.argv[i]=="--delay":
50 i = i + 1
51 if i >= len(sys.argv):
52 print "Error: missing argument"
53 sys.exit(1)
54 DELAY = float(sys.argv[i]) * 60
55 print "Delay is set to %f minute(s)" % (DELAY / 60)
56 else:
Benny Prijono719e5742010-08-25 12:51:29 +000057 if CMDLINE:
58 print "Error: cmdline already specified"
Benny Prijonoa10b3dd2010-08-23 09:16:03 +000059 sys.exit(1)
Benny Prijono719e5742010-08-25 12:51:29 +000060 CMDLINE = sys.argv[i]
Benny Prijonoa10b3dd2010-08-23 09:16:03 +000061 i = i + 1
Benny Prijonoa6b3e7c2010-08-16 12:18:20 +000062
Benny Prijono719e5742010-08-25 12:51:29 +000063 if not CMDLINE:
64 print "Error: cmdline is needed"
Benny Prijonoa10b3dd2010-08-23 09:16:03 +000065 sys.exit(1)
Benny Prijonoa6b3e7c2010-08-16 12:18:20 +000066
Benny Prijono20c26f02010-08-18 03:18:24 +000067 # Current date
68 utc = time.gmtime(None)
69 day = utc.tm_mday
70
Benny Prijonoa6b3e7c2010-08-16 12:18:20 +000071 # Loop foreva
72 while True:
73 argv = []
74
75 # Anything changed recently?
76 argv.append("ccdash.py")
77 argv.append("status")
78 argv.append("-w")
79 argv.append("../..")
80 rc = ccdash.main(argv)
81
Benny Prijono20c26f02010-08-18 03:18:24 +000082 utc = time.gmtime(None)
Benny Prijonoa6b3e7c2010-08-16 12:18:20 +000083
Benny Prijono20c26f02010-08-18 03:18:24 +000084 if utc.tm_mday != day or rc != 0:
85 group = ""
86 if utc.tm_mday != day:
87 day = utc.tm_mday
88 group = "Nightly"
89 elif rc != 0:
90 group = "Continuous"
91 else:
92 group = "Experimental"
Benny Prijono457e18e2010-08-23 15:34:19 +000093 print "Will run %s after %f s.." % (group, DELAY)
94 time.sleep(DELAY)
Benny Prijono719e5742010-08-25 12:51:29 +000095 rc = run_cmdline(group)
Benny Prijono20c26f02010-08-18 03:18:24 +000096 # Sleep even if something does change
97 print str(datetime.datetime.now()) + \
98 ": done running " + group + \
99 "tests, will check again in " + str(INTERVAL) + "s.."
100 time.sleep(INTERVAL)
101 else:
102 # Nothing changed
103 print str(datetime.datetime.now()) + \
104 ": No update, will check again in " + str(INTERVAL) + "s.."
105 time.sleep(INTERVAL)
106
Benny Prijonoa6b3e7c2010-08-16 12:18:20 +0000107