| | 816 | from buildbot import master |
|---|
| | 817 | |
|---|
| | 818 | class 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 will 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 | |
|---|
| | 847 | class 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 | |
|---|
| | 863 | def 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 | |
|---|