changeset 282:2cda5a640ae7

make this more of a script and add a --stop option
author Jeff Hammel <jhammel@mozilla.com>
date Wed, 01 Aug 2012 14:00:55 -0700
parents 6ac4cfa28465
children b5a06935d996
files autobot/template/restart_buildbot.py
diffstat 1 files changed, 32 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/autobot/template/restart_buildbot.py	Tue Jul 31 17:04:36 2012 -0700
+++ b/autobot/template/restart_buildbot.py	Wed Aug 01 14:00:55 2012 -0700
@@ -2,22 +2,42 @@
 
 """(re)start the buildbot"""
 
+import optparse
 import os
 import sys
 from subprocess import call
 from time import sleep
 
-os.chdir(os.path.abspath(os.path.dirname(sys.argv[0])))
-
+here = os.path.abspath(os.path.dirname(sys.argv[0]))
 debug = {{debug}}
-if debug:
-    call(['rm', '-f', 'master/twistd.log'])
-    call(['rm', '-f', 'slave/twistd.log'])
-    call(['rm', '-rf', 'slave/full'])
-call(['buildbot', 'stop', 'master'])
-call(['buildslave', 'stop', 'slave'])
-call(['buildbot', 'start', 'master'])
-call(['buildslave', 'start', 'slave'])
+
+def main(args=sys.argv[1:]):
+
+    # parse command line options
+    usage = '%prog [options]'
+    parser = optparse.OptionParser(usage=usage, description=__doc__)
+    parser.add_option('--stop', dest='stop',
+                      action='store_true', default=False,
+                      help="stop the buildbot only")
+    # could force a build here
+    # buildbot sendchange ...
+    options, args = parser.parse_args(args)
 
-# could force a build here
-# buildbot sendchange ...
+    # cleanup
+    if debug:
+        call(['rm', '-f', 'master/twistd.log'], cwd=here)
+        call(['rm', '-f', 'slave/twistd.log'], cwd=here)
+        call(['rm', '-rf', 'slave/full'], cwd=here)
+
+    # stop running instance
+    call(['buildbot', 'stop', 'master'], cwd=here)
+    call(['buildslave', 'stop', 'slave'], cwd=here)
+
+    # start new instance
+    if not options.stop:
+        call(['buildbot', 'start', 'master'], cwd=here)
+        call(['buildslave', 'start', 'slave'], cwd=here)
+
+
+if __name__ == '__main__':
+    main()