diff options
Diffstat (limited to 'branding/vendorize.py')
-rwxr-xr-x | branding/vendorize.py | 99 |
1 files changed, 0 insertions, 99 deletions
diff --git a/branding/vendorize.py b/branding/vendorize.py deleted file mode 100755 index 46cc1e6..0000000 --- a/branding/vendorize.py +++ /dev/null @@ -1,99 +0,0 @@ -#!/usr/bin/env python3 - -import os -import sys - -from string import Template -import configparser - -OUTFILE = 'config.go' -INFILE = 'config.go.tmpl' -CONFIGFILE = 'config/vendor.conf' -SCRIPT_NAME = 'vendorize' - - -def getProviderData(config): - default = config['default']['provider'] - print("[+] Configured provider:", default) - - c = config[default] - d = dict() - - keys = ('name', 'applicationName', 'binaryName', - 'providerURL', 'tosURL', 'helpURL', - 'donateURL', 'apiURL', 'geolocationAPI', 'caCertString') - - for value in keys: - d[value] = c.get(value) - - return d - - -def addCaData(data, configfile): - provider = data.get('name').lower() - folder, f = os.path.split(configfile) - caFile = os.path.join(folder, provider + '-ca.crt') - if not os.path.isfile(caFile): - bail('[!] Cannot find CA file in {path}'.format(path=caFile)) - with open(caFile) as ca: - data['caCertString'] = ca.read().strip() - - -def writeOutput(data, infile, outfile): - - with open(infile) as infile: - s = Template(infile.read()) - - with open(outfile, 'w') as outf: - outf.write(s.substitute(data)) - - -def bail(msg=None): - if not msg: - print('Usage: {scriptname}.py <template> <config> <output>'.format( - scriptname=SCRIPT_NAME)) - else: - print(msg) - sys.exit(1) - - -if __name__ == "__main__": - infile = outfile = "" - - if len(sys.argv) > 4: - bail() - - elif len(sys.argv) == 1: - infile = INFILE - outfile = OUTFILE - configfile = CONFIGFILE - else: - try: - infile = sys.argv[1] - configfile = sys.argv[2] - outfile = sys.argv[3] - except IndexError: - bail() - - if not os.path.isfile(infile): - bail('[!] Cannot find template in {path}'.format( - path=os.path.abspath(infile))) - elif not os.path.isfile(configfile): - bail('[!] Cannot find config in {path}'.format( - path=os.path.abspath(configfile))) - else: - print('[+] Using {path} as template'.format( - path=os.path.abspath(infile))) - print('[+] Using {path} as config'.format( - path=os.path.abspath(configfile))) - - config = configparser.ConfigParser() - config.read(configfile) - - data = getProviderData(config) - addCaData(data, configfile) - writeOutput(data, infile, outfile) - - print('[+] Wrote configuration for {provider} to {outf}'.format( - provider=data.get('name'), - outf=os.path.abspath(outfile))) |