| 1 |
|
| 2 |
import os |
| 3 |
import sys |
| 4 |
import time |
| 5 |
import datetime |
| 6 |
import ccdash |
| 7 |
|
| 8 |
INTERVAL = 300 |
| 9 |
DELAY = 0 |
| 10 |
ONCE = False |
| 11 |
SUFFIX = "" |
| 12 |
FORCE = False |
| 13 |
|
| 14 |
def run_scenarios(scenarios, group): |
| 15 |
|
| 16 |
rc = 0 |
| 17 |
for scenario in scenarios: |
| 18 |
argv = [] |
| 19 |
argv.append("ccdash.py") |
| 20 |
argv.append("scenario") |
| 21 |
argv.append(scenario) |
| 22 |
argv.append("--group") |
| 23 |
argv.append(group) |
| 24 |
thisrc = ccdash.main(argv) |
| 25 |
if rc==0 and thisrc: |
| 26 |
rc = thisrc |
| 27 |
return rc |
| 28 |
|
| 29 |
|
| 30 |
def usage(): |
| 31 |
print """Periodically monitor working directory for Continuous and Nightly builds |
| 32 |
|
| 33 |
Usage: |
| 34 |
run_continuous.py [options] scenario1.xml [scenario2.xml ...] |
| 35 |
|
| 36 |
options: |
| 37 |
These are options which will be processed by run_continuous.py: |
| 38 |
|
| 39 |
--delay MIN Delay both Continuous and Nightly builds by MIN minutes. |
| 40 |
This is useful to coordinate the build with other build |
| 41 |
machines. By default, Continuous build will be done right |
| 42 |
after changes are detected, and Nightly build will be done |
| 43 |
at 00:00 GMT. MIN is a float number. |
| 44 |
|
| 45 |
--once Just run one loop to see if anything needs to be done and |
| 46 |
if so just do it once. Quit after that. |
| 47 |
|
| 48 |
--suffix SFX Set group suffix to SFX. For example, if SFX is "-2.x", then |
| 49 |
tests will be submitted to "Nightly-2.x", "Continuous-2.x", |
| 50 |
and "Experimental-2.x" |
| 51 |
|
| 52 |
--force Force running the test even when nothing has changed. |
| 53 |
""" |
| 54 |
sys.exit(1) |
| 55 |
|
| 56 |
if __name__ == "__main__": |
| 57 |
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": |
| 58 |
usage() |
| 59 |
|
| 60 |
|
| 61 |
scenarios = [] |
| 62 |
i = 1 |
| 63 |
while i < len(sys.argv): |
| 64 |
if sys.argv[i]=="--delay": |
| 65 |
i = i + 1 |
| 66 |
if i >= len(sys.argv): |
| 67 |
print "Error: missing argument" |
| 68 |
sys.exit(1) |
| 69 |
DELAY = float(sys.argv[i]) * 60 |
| 70 |
print "Delay is set to %f minute(s)" % (DELAY / 60) |
| 71 |
elif sys.argv[i]=="--suffix": |
| 72 |
i = i + 1 |
| 73 |
if i >= len(sys.argv): |
| 74 |
print "Error: missing argument" |
| 75 |
sys.exit(1) |
| 76 |
SUFFIX = sys.argv[i] |
| 77 |
print "Suffix is set to %s" % (SUFFIX) |
| 78 |
elif sys.argv[i]=="--once": |
| 79 |
ONCE = True |
| 80 |
elif sys.argv[i]=="--force": |
| 81 |
FORCE = True |
| 82 |
else: |
| 83 |
|
| 84 |
scenario = sys.argv[i] |
| 85 |
if not os.path.exists(scenario): |
| 86 |
print "Error: file " + scenario + " does not exist" |
| 87 |
sys.exit(1) |
| 88 |
scenarios.append(scenario) |
| 89 |
print "Scenario %s added" % (scenario) |
| 90 |
i = i + 1 |
| 91 |
|
| 92 |
if len(scenarios) < 1: |
| 93 |
print "Error: scenario is required" |
| 94 |
sys.exit(1) |
| 95 |
|
| 96 |
|
| 97 |
utc = time.gmtime(None) |
| 98 |
day = utc.tm_mday |
| 99 |
|
| 100 |
|
| 101 |
while True: |
| 102 |
argv = [] |
| 103 |
|
| 104 |
|
| 105 |
argv.append("ccdash.py") |
| 106 |
argv.append("status") |
| 107 |
argv.append("-w") |
| 108 |
argv.append("../..") |
| 109 |
rc = ccdash.main(argv) |
| 110 |
|
| 111 |
utc = time.gmtime(None) |
| 112 |
|
| 113 |
if utc.tm_mday != day or rc != 0 or FORCE: |
| 114 |
group = "" |
| 115 |
if utc.tm_mday != day: |
| 116 |
day = utc.tm_mday |
| 117 |
group = "Nightly" + SUFFIX |
| 118 |
elif rc != 0: |
| 119 |
group = "Continuous" + SUFFIX |
| 120 |
else: |
| 121 |
group = "Experimental" + SUFFIX |
| 122 |
if DELAY > 0: |
| 123 |
print "Will run %s after %f s.." % (group, DELAY) |
| 124 |
time.sleep(DELAY) |
| 125 |
rc = run_scenarios(scenarios, group) |
| 126 |
msg = str(datetime.datetime.now()) + \ |
| 127 |
": done running " + group + \ |
| 128 |
"tests, will check again in " + str(INTERVAL) + "s.." |
| 129 |
if ONCE: |
| 130 |
sys.exit(0) |
| 131 |
else: |
| 132 |
|
| 133 |
msg = str(datetime.datetime.now()) + \ |
| 134 |
": No update, will check again in " + str(INTERVAL) + "s.." |
| 135 |
if ONCE: |
| 136 |
sys.exit(1) |
| 137 |
|
| 138 |
print msg |
| 139 |
time.sleep(INTERVAL) |
| 140 |
|