Ticket #37: integrateConfigTester-v3.diff

File integrateConfigTester-v3.diff, 4.0 kB (added by bhearsum, 10 months ago)

config file tester - works on windows

  • old-trunk/buildbot/scripts/checkconfig.py

    old new  
     1import sys 
     2import os 
     3from shutil import copy, rmtree 
     4from tempfile import mkdtemp 
     5from os.path import isfile 
     6import traceback 
     7 
     8from buildbot import master 
     9 
     10class ConfigLoader(master.BuildMaster): 
     11    def __init__(self, configFileName="master.cfg"): 
     12        master.BuildMaster.__init__(self, ".", configFileName) 
     13        dir = os.getcwd() 
     14        # Use a temporary directory since loadConfig() creates a bunch of 
     15        # directories and compiles .py files 
     16        tempdir = mkdtemp() 
     17        file = configFileName 
     18        try: 
     19            copy(configFileName, tempdir) 
     20            for entry in os.listdir("."): 
     21                # Any code in a subdirectory will _not_ be copied! This is a bug 
     22                if isfile(entry): 
     23                    copy(entry, tempdir) 
     24        except: 
     25            raise 
     26 
     27        try: 
     28            os.chdir(tempdir) 
     29            # Add the temp directory to the library path so local modules work 
     30            sys.path.append(tempdir) 
     31            configFile = open(configFileName, "r") 
     32            self.loadConfig(configFile) 
     33        except: 
     34            os.chdir(dir) 
     35            rmtree(tempdir) 
     36            raise 
     37        os.chdir(dir) 
     38        rmtree(tempdir) 
     39 
     40if __name__ == '__main__': 
     41    try: 
     42        if len(sys.argv) > 1: 
     43            c = ConfigLoader(sys.argv[1]) 
     44        else: 
     45            c = ConfigLoader() 
     46    except IOError: 
     47        print >> sys.stderr, "Could not open config file" 
     48        sys.exit(2) 
     49    except: 
     50        print >> sys.stderr, "Error in config file:" 
     51        t, v, tb = sys.exc_info() 
     52        print >> sys.stderr, traceback.print_exception(t, v, tb) 
     53        sys.exit(1) 
  • old-trunk/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 
     6import traceback 
    67from twisted.python import usage, util, runtime 
    78 
    89# this is mostly just a front-end for mktap, twistd, and kill(1), but in the 
     
    809810    os.rename(tmpfile, newfile) 
    810811 
    811812 
     813class CheckConfigOptions(usage.Options): 
     814    optFlags = [ 
     815        ['quiet', 'q', "Don't display error messages or tracebacks"], 
     816    ] 
     817 
     818    def getSynopsis(self): 
     819        return "Usage           :buildbot checkconfig [configFile]\n" + \ 
     820         "              If not specified, 'master.cfg' will be used as 'configFile'" 
     821 
     822    def parseArgs(self, *args): 
     823        if len(args) >= 1: 
     824            self['configFile'] = args[0] 
     825        else: 
     826            self['configFile'] = 'master.cfg' 
     827 
     828 
     829def doCheckConfig(config): 
     830    quiet = config.get('quiet') 
     831    configFile = config.get('configFile') 
     832    try: 
     833        from buildbot.scripts.checkconfig import ConfigLoader 
     834        ConfigLoader(configFile) 
     835    except: 
     836        if not quiet: 
     837            # Print out the traceback in a nice format 
     838            t, v, tb = sys.exc_info() 
     839            traceback.print_exception(t, v, tb) 
     840        sys.exit(1) 
     841 
     842    if not quiet: 
     843        print "Config file is good!" 
     844 
     845 
    812846class Options(usage.Options): 
    813847    synopsis = "Usage:    buildbot <command> [command options]" 
    814848 
     
    847881        ['tryserver', None, TryServerOptions, 
    848882         "buildmaster-side 'try' support function, not for users"], 
    849883 
     884        ['checkconfig', None, CheckConfigOptions, 
     885         "test the validity of a master.cfg config file"], 
     886 
    850887        # TODO: 'watch' 
    851888        ] 
    852889 
     
    906943        doTry(so) 
    907944    elif command == "tryserver": 
    908945        doTryServer(so) 
     946    elif command == "checkconfig": 
     947        doCheckConfig(so) 
    909948 
    910949