Ticket #37: integrateConfigTester-v2.diff

File integrateConfigTester-v2.diff, 3.3 kB (added by bhearsum, 1 year ago)

fix stupid indentation error

  • buildbot/scripts/runner.py

    old new  
    33# N.B.: don't import anything that might pull in a reactor yet. Some of our 
    44# subcommands want to load modules that need the gtk reactor. 
    55import os, sys, stat, re, time 
     6from shutil import copy, rmtree 
     7from tempfile import mkdtemp 
     8from os.path import isfile 
     9import traceback 
    610from twisted.python import usage, util, runtime 
    711 
    812# this is mostly just a front-end for mktap, twistd, and kill(1), but in the 
     
    809813    os.rename(tmpfile, newfile) 
    810814 
    811815 
     816from buildbot import master 
     817 
     818class ConfigLoader(master.BuildMaster): 
     819    def __init__(self, configFileName="master.cfg"): 
     820        master.BuildMaster.__init__(self, ".", configFileName) 
     821        dir = os.getcwd() 
     822        # Use a temporary directory since loadConfig() creates a bunch of 
     823        # directories and compiles .py files 
     824        tempdir = mkdtemp() 
     825        file = configFileName 
     826        try: 
     827            copy(configFileName, tempdir) 
     828            for entry in os.listdir("."): 
     829                # Any code in a subdirectory will _not_ be copied! This is a bug 
     830                if isfile(entry): 
     831                    copy(entry, tempdir) 
     832        except: 
     833            raise Exception("Error copying file %s" % file) 
     834 
     835        try: 
     836            os.chdir(tempdir) 
     837            # Add the temp directory to the library path so local modules work 
     838            sys.path.append(tempdir) 
     839            configFile = open(configFileName, "r") 
     840            self.loadConfig(configFile) 
     841        except: 
     842            raise 
     843        finally: 
     844            os.chdir(dir) 
     845            rmtree(tempdir) 
     846 
     847class CheckConfigOptions(usage.Options): 
     848    optFlags = [ 
     849        ['quiet', 'q', "Don't display error messages or tracebacks"], 
     850    ] 
     851 
     852    def getSynopsis(self): 
     853        return "Usage           :buildbot checkconfig [configFile]\n" + \ 
     854         "              If not specified, 'master.cfg' will be used as 'configFile'" 
     855 
     856    def parseArgs(self, *args): 
     857        if len(args) >= 1: 
     858            self['configFile'] = args[0] 
     859        else: 
     860            self['configFile'] = 'master.cfg' 
     861 
     862 
     863def doCheckConfig(config): 
     864    quiet = config.get('quiet') 
     865    configFile = config.get('configFile') 
     866    try: 
     867        ConfigLoader(configFile) 
     868    except: 
     869        if not quiet: 
     870            # Print out the traceback in a nice format 
     871            t, v, tb = sys.exc_info() 
     872            traceback.print_exception(t, v, tb) 
     873        sys.exit(1) 
     874 
     875    if not quiet: 
     876        print "Config file is good!" 
     877 
     878 
    812879class Options(usage.Options): 
    813880    synopsis = "Usage:    buildbot <command> [command options]" 
    814881 
     
    847914        ['tryserver', None, TryServerOptions, 
    848915         "buildmaster-side 'try' support function, not for users"], 
    849916 
     917        ['checkconfig', None, CheckConfigOptions, 
     918         "test the validity of a master.cfg config file"], 
     919 
    850920        # TODO: 'watch' 
    851921        ] 
    852922 
     
    906976        doTry(so) 
    907977    elif command == "tryserver": 
    908978        doTryServer(so) 
     979    elif command == "checkconfig": 
     980        doCheckConfig(so) 
    909981 
    910982