[Buildbot-commits] buildbot/buildbot/scripts checkconfig.py, NONE, 1.1 runner.py, 1.59, 1.60

Brian Warner warner at users.sourceforge.net
Fri Mar 28 05:55:49 UTC 2008


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

Modified Files:
	runner.py 
Added Files:
	checkconfig.py 
Log Message:
[project @ add 'buildbot checkconfig' command from Ben Hearsum]

Original author: warner at lothar.com
Date: 2008-03-28 05:50:38+00:00

--- NEW FILE: checkconfig.py ---
import sys
import os
from shutil import copy, rmtree
from tempfile import mkdtemp
from os.path import isfile
import traceback

from buildbot import master

class ConfigLoader(master.BuildMaster):
    def __init__(self, configFileName="master.cfg"):
        master.BuildMaster.__init__(self, ".", configFileName)
        dir = os.getcwd()
        # Use a temporary directory since loadConfig() creates a bunch of
        # directories and compiles .py files
        tempdir = mkdtemp()
        try:
            copy(configFileName, tempdir)
            for entry in os.listdir("."):
                # Any code in a subdirectory will _not_ be copied! This is a bug
                if isfile(entry):
                    copy(entry, tempdir)
        except:
            raise

        try:
            os.chdir(tempdir)
            # Add the temp directory to the library path so local modules work
            sys.path.append(tempdir)
            configFile = open(configFileName, "r")
            self.loadConfig(configFile)
        except:
            os.chdir(dir)
            rmtree(tempdir)
            raise
        os.chdir(dir)
        rmtree(tempdir)

if __name__ == '__main__':
    try:
        if len(sys.argv) > 1:
            c = ConfigLoader(sys.argv[1])
        else:
            c = ConfigLoader()
    except IOError:
        print >> sys.stderr, "Could not open config file"
        sys.exit(2)
    except:
        print >> sys.stderr, "Error in config file:"
        t, v, tb = sys.exc_info()
        print >> sys.stderr, traceback.print_exception(t, v, tb)
        sys.exit(1)

Index: runner.py
===================================================================
RCS file: /cvsroot/buildbot/buildbot/buildbot/scripts/runner.py,v
retrieving revision 1.59
retrieving revision 1.60
diff -u -d -r1.59 -r1.60
--- runner.py	30 Sep 2007 18:03:14 -0000	1.59
+++ runner.py	28 Mar 2008 05:55:46 -0000	1.60
@@ -3,6 +3,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, sys, stat, re, time
+import traceback
 from twisted.python import usage, util, runtime
 
 # this is mostly just a front-end for mktap, twistd, and kill(1), but in the
@@ -809,6 +810,39 @@
     os.rename(tmpfile, newfile)
 
 
+class CheckConfigOptions(usage.Options):
+    optFlags = [
+        ['quiet', 'q', "Don't display error messages or tracebacks"],
+    ]
+
+    def getSynopsis(self):
+        return "Usage		:buildbot checkconfig [configFile]\n" + \
+         "		If not specified, 'master.cfg' will be used as 'configFile'"
+
+    def parseArgs(self, *args):
+        if len(args) >= 1:
+            self['configFile'] = args[0]
+        else:
+            self['configFile'] = 'master.cfg'
+
+
+def doCheckConfig(config):
+    quiet = config.get('quiet')
+    configFile = config.get('configFile')
+    try:
+        from buildbot.scripts.checkconfig import ConfigLoader
+        ConfigLoader(configFile)
+    except:
+        if not quiet:
+            # Print out the traceback in a nice format
+            t, v, tb = sys.exc_info()
+            traceback.print_exception(t, v, tb)
+        sys.exit(1)
+
+    if not quiet:
+        print "Config file is good!"
+
+
 class Options(usage.Options):
     synopsis = "Usage:    buildbot <command> [command options]"
 
@@ -847,6 +881,9 @@
         ['tryserver', None, TryServerOptions,
          "buildmaster-side 'try' support function, not for users"],
 
+        ['checkconfig', None, CheckConfigOptions,
+         "test the validity of a master.cfg config file"],
+
         # TODO: 'watch'
         ]
 
@@ -906,5 +943,7 @@
         doTry(so)
     elif command == "tryserver":
         doTryServer(so)
+    elif command == "checkconfig":
+        doCheckConfig(so)
 
 





More information about the Commits mailing list