run_continuous.py 3.4 KB

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