Benny Prijono | a6b3e7c | 2010-08-16 12:18:20 +0000 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | import os |
| 3 | import sys |
| 4 | import time |
Benny Prijono | 4adead2 | 2010-08-16 12:33:52 +0000 | [diff] [blame] | 5 | import datetime |
Benny Prijono | a6b3e7c | 2010-08-16 12:18:20 +0000 | [diff] [blame] | 6 | import ccdash |
| 7 | |
Benny Prijono | a72cdca | 2010-08-17 14:53:09 +0000 | [diff] [blame] | 8 | INTERVAL = 300 |
Benny Prijono | a10b3dd | 2010-08-23 09:16:03 +0000 | [diff] [blame] | 9 | DELAY = 0 |
Benny Prijono | 719e574 | 2010-08-25 12:51:29 +0000 | [diff] [blame^] | 10 | CMDLINE = "" |
Benny Prijono | a6b3e7c | 2010-08-16 12:18:20 +0000 | [diff] [blame] | 11 | |
Benny Prijono | 719e574 | 2010-08-25 12:51:29 +0000 | [diff] [blame^] | 12 | def run_cmdline(group): |
| 13 | cmdline = CMDLINE + " --group " + group |
| 14 | return os.system(cmdline) |
Benny Prijono | 20c26f0 | 2010-08-18 03:18:24 +0000 | [diff] [blame] | 15 | |
| 16 | |
Benny Prijono | a10b3dd | 2010-08-23 09:16:03 +0000 | [diff] [blame] | 17 | def usage(): |
| 18 | print """Periodically monitor working directory for Continuous and Nightly builds |
| 19 | |
| 20 | Usage: |
Benny Prijono | 719e574 | 2010-08-25 12:51:29 +0000 | [diff] [blame^] | 21 | run_continuous.py [options] "cmdline" |
| 22 | |
| 23 | where: |
| 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 Prijono | a10b3dd | 2010-08-23 09:16:03 +0000 | [diff] [blame] | 29 | |
| 30 | options: |
| 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 Prijono | a6b3e7c | 2010-08-16 12:18:20 +0000 | [diff] [blame] | 42 | if __name__ == "__main__": |
Benny Prijono | a10b3dd | 2010-08-23 09:16:03 +0000 | [diff] [blame] | 43 | 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 Prijono | a6b3e7c | 2010-08-16 12:18:20 +0000 | [diff] [blame] | 45 | |
Benny Prijono | 719e574 | 2010-08-25 12:51:29 +0000 | [diff] [blame^] | 46 | # Check args |
Benny Prijono | a10b3dd | 2010-08-23 09:16:03 +0000 | [diff] [blame] | 47 | 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 Prijono | 719e574 | 2010-08-25 12:51:29 +0000 | [diff] [blame^] | 57 | if CMDLINE: |
| 58 | print "Error: cmdline already specified" |
Benny Prijono | a10b3dd | 2010-08-23 09:16:03 +0000 | [diff] [blame] | 59 | sys.exit(1) |
Benny Prijono | 719e574 | 2010-08-25 12:51:29 +0000 | [diff] [blame^] | 60 | CMDLINE = sys.argv[i] |
Benny Prijono | a10b3dd | 2010-08-23 09:16:03 +0000 | [diff] [blame] | 61 | i = i + 1 |
Benny Prijono | a6b3e7c | 2010-08-16 12:18:20 +0000 | [diff] [blame] | 62 | |
Benny Prijono | 719e574 | 2010-08-25 12:51:29 +0000 | [diff] [blame^] | 63 | if not CMDLINE: |
| 64 | print "Error: cmdline is needed" |
Benny Prijono | a10b3dd | 2010-08-23 09:16:03 +0000 | [diff] [blame] | 65 | sys.exit(1) |
Benny Prijono | a6b3e7c | 2010-08-16 12:18:20 +0000 | [diff] [blame] | 66 | |
Benny Prijono | 20c26f0 | 2010-08-18 03:18:24 +0000 | [diff] [blame] | 67 | # Current date |
| 68 | utc = time.gmtime(None) |
| 69 | day = utc.tm_mday |
| 70 | |
Benny Prijono | a6b3e7c | 2010-08-16 12:18:20 +0000 | [diff] [blame] | 71 | # 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 Prijono | 20c26f0 | 2010-08-18 03:18:24 +0000 | [diff] [blame] | 82 | utc = time.gmtime(None) |
Benny Prijono | a6b3e7c | 2010-08-16 12:18:20 +0000 | [diff] [blame] | 83 | |
Benny Prijono | 20c26f0 | 2010-08-18 03:18:24 +0000 | [diff] [blame] | 84 | 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 Prijono | 457e18e | 2010-08-23 15:34:19 +0000 | [diff] [blame] | 93 | print "Will run %s after %f s.." % (group, DELAY) |
| 94 | time.sleep(DELAY) |
Benny Prijono | 719e574 | 2010-08-25 12:51:29 +0000 | [diff] [blame^] | 95 | rc = run_cmdline(group) |
Benny Prijono | 20c26f0 | 2010-08-18 03:18:24 +0000 | [diff] [blame] | 96 | # 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 Prijono | a6b3e7c | 2010-08-16 12:18:20 +0000 | [diff] [blame] | 107 | |