[Buildbot-commits] buildbot/buildbot/scripts runner.py,1.7,1.8

Brian Warner warner at users.sourceforge.net
Thu Apr 21 20:56:25 UTC 2005


Update of /cvsroot/buildbot/buildbot/buildbot/scripts
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31889/buildbot/scripts

Modified Files:
	runner.py 
Log Message:
(createMaster,createSlave): rewrite 'buildbot' command to put a little
Makefile in the target that helps you re-create the buildbot.tap file, start
or stop the master/slave, and reconfigure (i.e. SIGHUP) the master. Also
chmod all the files 0600, since they contain passwords.

(start): if there is a Makefile, and /usr/bin/make exists, use 'make start'
in preference to a raw twistd command. This lets slave admins put things like
PYTHONPATH variables in their Makefiles and have them still work when the
slave is started with 'buildbot start ~/slave/foo'. The test is a bit clunky,
it would be nice to first try the 'make' command and only fall back to twistd
if it fails. TODO: the Makefile's "start" command does not add the
--reactor=win32 argument when running under windows.


Index: runner.py
===================================================================
RCS file: /cvsroot/buildbot/buildbot/buildbot/scripts/runner.py,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- runner.py	8 Nov 2004 09:03:21 -0000	1.7
+++ runner.py	21 Apr 2005 20:56:22 -0000	1.8
@@ -10,79 +10,103 @@
 # the create/start/stop commands should all be run as the same user,
 # preferably a separate 'buildbot' account.
 
-def createMaster(config):
-    basedir = os.path.abspath(config['basedir'])
-    force = config['force']
-    quiet = config['quiet']
-    if os.path.exists(basedir) and not force:
-        print "basedir %s already exists and --force not used" % basedir
-        print "refusing to touch existing setup"
-        sys.exit(1)
-    if not os.path.exists(basedir):
-        if not quiet: print "mkdir", basedir
-        os.mkdir(basedir)
+class Maker:
+    def __init__(self, config):
+        self.basedir = os.path.abspath(config['basedir'])
+        self.force = config['force']
+        self.quiet = config['quiet']
 
-    if not quiet: print "chdir", basedir
-    os.chdir(basedir)
+    def mkdir(self):
+        if os.path.exists(self.basedir) and not self.force:
+            print ("basedir %s already exists and --force not used"
+                   % self.basedir)
+            print "refusing to touch existing setup"
+            sys.exit(1)
+        if not os.path.exists(self.basedir):
+            if not self.quiet: print "mkdir", self.basedir
+            os.mkdir(self.basedir)
 
-    cmd = "mktap buildbot master --basedir %s" % basedir
-    if not quiet: print cmd
-    status = os.system(cmd)
-    if status != 0:
-        print "mktap failed, bailing.."
-        sys.exit(1)
+    def chdir(self):
+        if not self.quiet: print "chdir", self.basedir
+        os.chdir(self.basedir)
 
-    target = "master.cfg"
-    if os.path.exists(target):
-        print "not touching existing master.cfg"
-        print "installing sample in master.cfg.sample instead"
-        target = "master.cfg.sample"
-    sampleconfig = util.sibpath(__file__, "sample.cfg")
-    shutil.copy(sampleconfig, target)
+    def mktap(self, cmd):
+        if not self.quiet: print cmd
+        status = os.system(cmd)
+        if status != 0:
+            print "mktap failed, bailing.."
+            sys.exit(1)
+        if not os.path.exists("buildbot.tap"):
+            print "mktap failed to create buildbot.tap, bailing.."
+            sys.exit(1)
+        os.chmod("buildbot.tap", 0600)
 
-    target = "Makefile"
-    if os.path.exists(target):
-        print "not touching existing Makefile"
-        print "installing sample in Makefile.sample instead"
-        target = "Makefile.sample"
-    samplemk = util.sibpath(__file__, "sample.mk")
-    shutil.copy(samplemk, target)
+    def makefile(self, source, cmd):
+        target = "Makefile"
+        if os.path.exists(target):
+            print "not touching existing Makefile"
+            print "installing sample in Makefile.sample instead"
+            target = "Makefile.sample"
+        shutil.copy(source, target)
+        f = open(target, "a")
+        f.write("\n")
+        f.write("tap:\n")
+        f.write("\t" + cmd + "\n")
+        f.write("\n")
+        f.close()
+        os.chmod(target, 0600)
 
-    if not quiet: print "buildmaster configured in %s" % basedir
+    def sampleconfig(self, source):
+        target = "master.cfg"
+        if os.path.exists(target):
+            print "not touching existing master.cfg"
+            print "installing sample in master.cfg.sample instead"
+            target = "master.cfg.sample"
+        shutil.copy(source, target)
+        os.chmod(target, 0600)
+
+def createMaster(config):
+    m = Maker(config)
+    m.mkdir()
+    m.chdir()
+
+    cmd = "mktap buildbot master --basedir %s" % m.basedir
+
+    m.mktap(cmd)
+    m.sampleconfig(util.sibpath(__file__, "sample.cfg"))
+    m.makefile(util.sibpath(__file__, "sample.mk"), cmd)
+
+    if not m.quiet: print "buildmaster configured in %s" % m.basedir
     sys.exit(0)
 
 def createSlave(config):
-    basedir = os.path.abspath(config['basedir'])
-    force = config['force']
-    quiet = config['quiet']
-    if os.path.exists(basedir) and not force:
-        print "basedir %s already exists and --force not used" % basedir
-        print "refusing to touch existing setup"
-        sys.exit(1)
-    if not os.path.exists(basedir):
-        if not quiet: print "mkdir", basedir
-        os.mkdir(basedir)
-    if not quiet: print "chdir", basedir
-    os.chdir(basedir)
+    m = Maker(config)
+    m.mkdir()
+    m.chdir()
+
     cmd = ("mktap buildbot slave " +
            "--basedir %s --master %s --name %s --passwd %s" \
-           % (basedir, config['master'], config['name'], config['passwd']))
-    if not quiet: print cmd
-    status = os.system(cmd)
-    if status != 0:
-        print "mktap failed, bailing.."
-        sys.exit(1)
-    if not quiet: print "buildslave configured in %s" % basedir
+           % (m.basedir, config['master'], config['name'], config['passwd']))
+
+    m.mktap(cmd)
+    m.makefile(util.sibpath(__file__, "sample.mk"), cmd)
+
+    if not m.quiet: print "buildslave configured in %s" % m.basedir
     sys.exit(0)
 
 def start(config):
     basedir = config['basedir']
     quiet = config['quiet']
     os.chdir(basedir)
-    reactor_arg = ""
-    if sys.platform == "win32":
-        reactor_arg = "--reactor=win32"
-    cmd = "twistd %s --no_save -f buildbot.tap" % reactor_arg
+    if os.path.exists("/usr/bin/make") and os.path.exists("Makefile"):
+        # yes, this is clunky. Preferring the Makefile lets slave admins do
+        # useful things like set up environment variables for the buildslave.
+        cmd = "make start"
+    else:
+        reactor_arg = ""
+        if sys.platform == "win32":
+            reactor_arg = "--reactor=win32"
+        cmd = "twistd %s --no_save -f buildbot.tap" % reactor_arg
     if not quiet: print cmd
     os.system(cmd)
     sys.exit(0)





More information about the Commits mailing list