[Buildbot-commits] buildbot/buildbot/scripts runner.py,1.17,1.18 sample.mk,1.1,1.2

Brian Warner warner at users.sourceforge.net
Fri May 6 04:58:00 UTC 2005


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

Modified Files:
	runner.py sample.mk 
Log Message:
Revision: arch at buildbot.sf.net--2004/buildbot--dev--0--patch-139
Creator:  Brian Warner <warner at monolith.lothar.com>

Merged from warner at monolith.lothar.com--2005 (patch 4-5)

Stop using mktap, create buildbot.tac instead.

Patches applied:

 * warner at monolith.lothar.com--2005/buildbot--dev--0--patch-4
   stop using mktap, create buildbot.tac instead

 * warner at monolith.lothar.com--2005/buildbot--dev--0--patch-5
   remove more old mktap-related code


Index: runner.py
===================================================================
RCS file: /cvsroot/buildbot/buildbot/buildbot/scripts/runner.py,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- runner.py	4 May 2005 04:14:31 -0000	1.17
+++ runner.py	6 May 2005 04:57:58 -0000	1.18
@@ -2,7 +2,7 @@
 
 # N.B.: don't import anything that might pull in a reactor yet. Some of our
 # subcommands want to load modules that need the gtk reactor.
-import os, os.path, sys, shutil, stat
+import os, os.path, sys, shutil, stat, re
 from twisted.python import usage, util, runtime
 
 # this is mostly just a front-end for mktap, twistd, and kill(1), but in the
@@ -12,9 +12,32 @@
 # the create/start/stop commands should all be run as the same user,
 # preferably a separate 'buildbot' account.
 
+class MakerBase(usage.Options):
+    optFlags = [
+        ['help', 'h', "Display this message"],
+        ["quiet", "q", "Do not emit the commands being run"],
+        ]
+
+    #["basedir", "d", None, "Base directory for the buildmaster"],
+    opt_h = usage.Options.opt_help
+
+    def parseArgs(self, *args):
+        if len(args) > 0:
+            self['basedir'] = args[0]
+        else:
+            self['basedir'] = None
+        if len(args) > 1:
+            raise usage.UsageError("I wasn't expecting so many arguments")
+
+    def postOptions(self):
+        if self['basedir'] is None:
+            raise usage.UsageError("<basedir> parameter is required")
+        self['basedir'] = os.path.abspath(self['basedir'])
+
 class Maker:
     def __init__(self, config):
-        self.basedir = os.path.abspath(config['basedir'])
+        self.config = config
+        self.basedir = config['basedir']
         self.force = config['force']
         self.quiet = config['quiet']
 
@@ -49,31 +72,44 @@
         if not self.quiet: print "chdir", self.basedir
         os.chdir(self.basedir)
 
-    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)
+    def makeTAC(self, contents, secret=False):
+        tacfile = "buildbot.tac"
+        if os.path.exists(tacfile):
+            oldcontents = open(tacfile, "rt").read()
+            if oldcontents == contents:
+                print "buildbot.tac already exists and is correct"
+                return
+            print "not touching existing buildbot.tac"
+            print "creating buildbot.tac.new instead"
+            tacfile = "buildbot.tac.new"
+        f = open(tacfile, "wt")
+        f.write(contents)
+        f.close()
+        if secret:
+            os.chmod(tacfile, 0600)
 
-    def makefile(self, source, cmd):
+    def makeSlaveTAC(self):
+
+        tacfile = "buildbot.tac"
+        if os.path.exists(tacfile):
+            oldcontents = open(tacfile, "rt").read()
+            if oldcontents == contents:
+                print "buildbot.tac already exists and is correct"
+                return
+            print "not touching existing buildbot.tac"
+            print "creating buildbot.tac.new instead"
+            tacfile = "buildbot.tac.new"
+        f = open(tacfile, "wt")
+        f.write(contents)
+        f.close()
+
+    def makefile(self, source):
         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)
-        os.chmod(target, 0600)
-        f = open(target, "a")
-        f.write("\n")
-        f.write("tap:\n")
-        f.write("\t" + cmd + "\n")
-        f.write("\n")
-        f.close()
 
     def sampleconfig(self, source):
         target = "master.cfg"
@@ -84,31 +120,134 @@
         shutil.copy(source, target)
         os.chmod(target, 0600)
 
+class MasterOptions(MakerBase):
+    optFlags = [
+        ["force", "f",
+         "Re-use an existing directory (will not overwrite master.cfg file)"],
+        ]
+    optParameters = [
+        ["config", "c", "master.cfg", "name of the buildmaster config file"],
+        ]
+    def getSynopsis(self):
+        return "Usage:    buildbot master [options] <basedir>"
+
+    longdesc = """
+    This command creates a buildmaster working directory and buildbot.tac
+    file. The master will live in <dir> and create various files there.
+
+    At runtime, the master will read a configuration file (named
+    'master.cfg' by default) in its basedir. This file should contain python
+    code which eventually defines a dictionary named 'BuildmasterConfig'.
+    The elements of this dictionary are used to configure the Buildmaster.
+    See doc/config.xhtml for details about what can be controlled through
+    this interface."""
+
+masterTAC = """
+from twisted.application import service
+from buildbot.master import BuildMaster
+
+basedir = '%(basedir)s'
+configfile = '%(config)s'
+
+application = service.Application('buildmaster')
+BuildMaster(basedir, configfile).setServiceParent(application)
+
+"""
+
 def createMaster(config):
     m = Maker(config)
     m.mkdir()
     m.chdir()
-
-    cmd = "mktap buildbot master --basedir %s" % m.basedir
-
-    m.mktap(cmd)
+    contents = masterTAC % config
+    m.makeTAC(contents)
     m.sampleconfig(util.sibpath(__file__, "sample.cfg"))
-    m.makefile(util.sibpath(__file__, "sample.mk"), cmd)
+    m.makefile(util.sibpath(__file__, "sample.mk"))
 
     if not m.quiet: print "buildmaster configured in %s" % m.basedir
     sys.exit(0)
 
+class SlaveOptions(MakerBase):
+    optFlags = [
+        ["force", "f", "Re-use an existing directory"],
+        ]
+    optParameters = [
+#        ["name", "n", None, "Name for this build slave"],
+#        ["passwd", "p", None, "Password for this build slave"],
+#        ["basedir", "d", ".", "Base directory to use"],
+#        ["master", "m", "localhost:8007",
+#         "Location of the buildmaster (host:port)"],
+
+        ["keepalive", "k", 0,
+         "Interval at which keepalives should be sent (in seconds)"],
+        ["usepty", None, 1,
+         "(1 or 0) child processes should be run in a pty"],
+        ]
+    
+    longdesc = """
+    This command creates a buildslave working directory and buildbot.tac
+    file. The bot will use the <name> and <passwd> arguments to authenticate
+    itself when connecting to the master. All commands are run in a
+    build-specific subdirectory of <basedir>, which defaults to the working
+    directory that mktap was run from. <master> is a string of the form
+    'hostname:port', and specifies where the buildmaster can be reached.
+
+    <name>, <passwd>, and <master> will be provided by the buildmaster
+    administrator for your bot.
+    """
+
+    def getSynopsis(self):
+        return "Usage:    buildbot slave [options] <basedir> <master> <name> <passwd>"
+
+    def parseArgs(self, *args):
+        if len(args) < 4:
+            raise usage.UsageError("command needs more arguments")
+        basedir, master, name, passwd = args
+        self['basedir'] = basedir
+        self['master'] = master
+        self['name'] = name
+        self['passwd'] = passwd
+
+    def postOptions(self):
+        MakerBase.postOptions(self)
+        self['usepty'] = int(self['usepty'])
+        self['keepalive'] = int(self['keepalive'])
+
+slaveTAC = """
+from twisted.application import service
+from buildbot.slave.bot import BuildSlave
+
+basedir = '%(basedir)s'
+host = '%(host)s'
+port = %(port)d
+slavename = '%(name)s'
+passwd = '%(passwd)s'
+keepalive = %(keepalive)d
+usepty = %(usepty)d
+
+application = service.Application('buildslave')
+s = BuildSlave(host, port, slavename, passwd, basedir, keepalive, usepty)
+s.setServiceParent(application)
+
+"""
+
 def createSlave(config):
     m = Maker(config)
     m.mkdir()
     m.chdir()
+    try:
+        master = config['master']
+        host, port = re.search(r'(.+):(\d+)', master).groups()
+        config['host'] = host
+        config['port'] = int(port)
+    except:
+        print "unparseable master location '%s'" % master
+        print " expecting something more like localhost:8007"
+        raise
+    contents = slaveTAC % config
 
-    cmd = ("mktap buildbot slave " +
-           "--basedir %s --master %s --name %s --passwd %s" \
-           % (m.basedir, config['master'], config['name'], config['passwd']))
+    m.makeTAC(contents, secret=True)
 
-    m.mktap(cmd)
-    m.makefile(util.sibpath(__file__, "sample.mk"), cmd)
+    m.makefile(util.sibpath(__file__, "sample.mk"))
     m.mkinfo()
 
     if not m.quiet: print "buildslave configured in %s" % m.basedir
@@ -199,49 +338,11 @@
             del localDict[k]
     return localDict
 
-class Base(usage.Options):
-    optFlags = [
-        ['help', 'h', "Display this message"],
-        ["quiet", "q", "Do not emit the commands being run"],
-        ]
-    opt_h = usage.Options.opt_help
-
-    def parseArgs(self, basedir=None):
-        if basedir is None:
-            raise usage.UsageError("<basedir> parameter is required")
-        self['basedir'] = basedir
-
-class MasterOptions(Base):
-    optFlags = [
-        ["force", "f",
-         "Re-use an existing directory (will not overwrite master.cfg file)"],
-        ]
-    def getSynopsis(self):
-        return "Usage:    buildbot master [options] <basedir>"
-
-class SlaveOptions(Base):
-    optFlags = [
-        ["force", "f", "Re-use an existing directory"],
-#        ["nopty", None, "Do *not* run child commands under a PTY"],
-        ]
-
-    def getSynopsis(self):
-        return "Usage:    buildbot slave [options] <basedir> <master> <name> <passwd>"
-
-    def parseArgs(self, *args):
-        if len(args) < 4:
-            raise usage.UsageError("command needs more arguments")
-        basedir, master, name, passwd = args
-        self['basedir'] = basedir
-        self['master'] = master
-        self['name'] = name
-        self['passwd'] = passwd
-
-class StartOptions(Base):
+class StartOptions(MakerBase):
     def getSynopsis(self):
         return "Usage:    buildbot start <basedir>"
 
-class StopOptions(Base):
+class StopOptions(MakerBase):
     def getSynopsis(self):
         return "Usage:    buildbot stop <basedir>"
 

Index: sample.mk
===================================================================
RCS file: /cvsroot/buildbot/buildbot/buildbot/scripts/sample.mk,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- sample.mk	12 Oct 2004 17:49:16 -0000	1.1
+++ sample.mk	6 May 2005 04:57:58 -0000	1.2
@@ -1,16 +1,19 @@
 # -*- makefile -*-
 
 # This is a simple makefile which lives in a buildmaster/buildslave
-# directory (next to the buildbot.tap file). It allows you to start/stop the
-# master ot slave by doing 'make start' or 'make stop'.
+# directory (next to the buildbot.tac file). It allows you to start/stop the
+# master or slave by doing 'make start' or 'make stop'.
 
 # The 'reconfig' target will tell a buildmaster to reload its config file.
 
 start:
-	twistd --no_save -f buildbot.tap
+	twistd --no_save -y buildbot.tac
 
 stop:
 	kill `cat twistd.pid`
 
 reconfig:
 	kill -HUP `cat twistd.pid`
+
+log:
+	tail -f twistd.log





More information about the Commits mailing list