From e635c5b43df0ed6f28c05429dae126d645ac8717 Mon Sep 17 00:00:00 2001 From: "Kali Kaneko (leap communications)" Date: Wed, 10 Jul 2019 17:12:00 +0200 Subject: [feat] windows templates --- branding/scripts/TODO | 2 ++ branding/scripts/__init__.py | 0 branding/scripts/generate-win.py | 44 ++++++++++++++++++++++++++++++++++++++++ branding/scripts/provider.py | 32 +++++++++++++++++++++++++++++ branding/scripts/vendorize.py | 40 +++++++----------------------------- 5 files changed, 85 insertions(+), 33 deletions(-) create mode 100644 branding/scripts/TODO create mode 100644 branding/scripts/__init__.py create mode 100755 branding/scripts/generate-win.py create mode 100644 branding/scripts/provider.py (limited to 'branding/scripts') diff --git a/branding/scripts/TODO b/branding/scripts/TODO new file mode 100644 index 0000000..95ca345 --- /dev/null +++ b/branding/scripts/TODO @@ -0,0 +1,2 @@ +-[ ] sanity check scrit +-[ ] assets convertion script diff --git a/branding/scripts/__init__.py b/branding/scripts/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/branding/scripts/generate-win.py b/branding/scripts/generate-win.py new file mode 100755 index 0000000..fb15f22 --- /dev/null +++ b/branding/scripts/generate-win.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python3 + +import json +import os +import sys + +import configparser + +from provider import getDefaultProvider +from provider import getProviderData + + +VERSION = os.environ.get('VERSION', 'unknown') + + +def writeOutput(data, outfile): + + with open(outfile, 'w') as outf: + outf.write(json.dumps(data)) + + +if __name__ == "__main__": + env_provider_conf = os.environ.get('PROVIDER_CONFIG') + if env_provider_conf: + if os.path.isfile(env_provider_conf): + print("[+] Overriding provider config per " + "PROVIDER_CONFIG variable") + configfile = env_provider_conf + + config = configparser.ConfigParser() + config.read(configfile) + provider = getDefaultProvider(config) + data = getProviderData(provider, config) + + if len(sys.argv) != 2: + print('Usage: generate-win.py ') + sys.exit(1) + + outputf = sys.argv[1] + + data['applicationNameLower'] = data.get('applicationName').lower() + data['URL'] = data.get('infoURL') + data['version'] = VERSION + writeOutput(data, outputf) diff --git a/branding/scripts/provider.py b/branding/scripts/provider.py new file mode 100644 index 0000000..867007e --- /dev/null +++ b/branding/scripts/provider.py @@ -0,0 +1,32 @@ +import datetime +import os + + +def getDefaultProvider(config): + provider = os.environ.get('PROVIDER') + if provider: + print('[+] Got provider {} from environemnt'.format(provider)) + else: + print('[+] Using default provider from config file') + provider = config['default']['provider'] + return provider + + +def getProviderData(provider, config): + print("[+] Configured provider:", provider) + + c = config[provider] + d = dict() + + keys = ('name', 'applicationName', 'binaryName', + 'providerURL', 'tosURL', 'helpURL', + 'donateURL', 'apiURL', 'geolocationAPI', 'caCertString') + + for value in keys: + d[value] = c.get(value) + + d['timeStamp'] = '{:%Y-%m-%d %H:%M:%S}'.format( + datetime.datetime.now()) + + return d + diff --git a/branding/scripts/vendorize.py b/branding/scripts/vendorize.py index dc19952..59edae0 100755 --- a/branding/scripts/vendorize.py +++ b/branding/scripts/vendorize.py @@ -1,47 +1,20 @@ #!/usr/bin/env python3 -import datetime import os import sys from string import Template import configparser +from provider import getDefaultProvider +from provider import getProviderData + OUTFILE = 'config.go' -INFILE = 'config.go.tmpl' -CONFIGFILE = 'config/vendor.conf' +INFILE = '../templates/golang/config.go' +CONFIGFILE = '../config/vendor.conf' SCRIPT_NAME = 'vendorize' -def getDefaultProvider(config): - provider = os.environ.get('PROVIDER') - if provider: - print('[+] Got provider {} from environemnt'.format(provider)) - else: - print('[+] Using default provider from config file') - provider = config['default']['provider'] - return provider - - -def getProviderData(provider, config): - print("[+] Configured provider:", provider) - - c = config[provider] - d = dict() - - keys = ('name', 'applicationName', 'binaryName', - 'providerURL', 'tosURL', 'helpURL', - 'donateURL', 'apiURL', 'geolocationAPI', 'caCertString') - - for value in keys: - d[value] = c.get(value) - - d['timeStamp'] = '{:%Y-%m-%d %H:%M:%S}'.format( - datetime.datetime.now()) - - return d - - def addCaData(data, configfile): provider = data.get('name').lower() folder, f = os.path.split(configfile) @@ -91,7 +64,8 @@ if __name__ == "__main__": env_provider_conf = os.environ.get('PROVIDER_CONFIG') if env_provider_conf: if os.path.isfile(env_provider_conf): - print("[+] Overriding provider config per PROVIDER_CONFIG variable") + print("[+] Overriding provider config per " + "PROVIDER_CONFIG variable") configfile = env_provider_conf if not os.path.isfile(infile): -- cgit v1.2.3