update-master-json.py
author ffxbld
Mon, 09 Jul 2018 12:29:36 -0700
branchproduction
changeset 15793 948795e9a0eddcc13988eb94281048e9bc6dd4f4
parent 5131 5bb54371ebd90359c32b3e50d219dfc60be54cea
permissions -rwxr-xr-x
Added tag THUNDERBIRD_52_9_1_BUILD3, THUNDERBIRD_52_9_1_RELEASE for changeset d9b2617ef2e3

import commands, sys, json, os, shutil

""" A tool for generating a master_config.json file from 
    production_masters.json for a specific master 
    
"""

if len(sys.argv) == 3:
    all_masters_json = sys.argv[1]
    hostname = commands.getoutput('hostname')
    cwd = os.getcwd()
    if os.path.exists(all_masters_json):
        masters = json.load(open(all_masters_json))
        found = False
        for master in masters:
            if master['hostname'] == hostname and master['basedir'] == cwd and master['enabled']:
                found = True
                tmp = json.dumps(master, indent=2, sort_keys=True)
                if len(tmp) > 0:
                    print "writing new master_config.json file to %s" % sys.argv[2]
                    f = open(sys.argv[2], 'w')
                    f.write(tmp)
                    f.close()
                else:
                    print "no changes to master_config.json"
        if not found:
            print 'master not found in %s' % sys.argv[1]
            sys.exit(1)
    else:
        print '%s does not exist - please check path and try again' % sys.argv[1]
        sys.exit(1)
else:
    sys.stderr.write('Usage: %s production-masters.json master_config.json' % sys.argv[0])
    sys.exit(1)