#!/usr/bin/env python3
import configparser
import json
import os
import sys
import time
from string import Template
from provider import getDefaultProvider
from provider import getProviderData
OS_CONFIG = {
'osx': """
@ApplicationsDir@/$APPNAME.app
$APPNAME.app
open
Start $APPNAME now!
@TargetDir@
mac
""",
'windows': """
@ApplicationsDir@/DemoLibVPN
$APPNAME
@TargetDir@/$BINNAME.exe
"""
}
def getData():
config = configparser.ConfigParser()
configPath = os.path.join(here(), '../../branding/config/vendor.conf')
config.read(configPath)
provider = os.environ.get('PROVIDER')
if not provider:
provider = getDefaultProvider(config)
return getProviderData(provider, config)
def generateQtInstallerBoilerplate(data, platform, outDir):
generateConfig(data, platform, outDir)
generatePackageMetadata(data, platform, outDir)
def generateConfig(data, platform, outDir):
templateData = {
'APPNAME': data['applicationName'],
'BINNAME': data['binaryName'],
'VERSION': getVersion(),
'TIMESTAMP': time.strftime('%Y-%m-%d'),
}
platformStr = OS_CONFIG[platform]
platBlock = Template(platformStr).substitute(**templateData)
templateData['PLATFORM_BLOCK'] = platBlock
renderTemplate(
templatePath='../templates/qtinstaller/config/config.xml',
outPath=os.path.join(outDir, 'config/config.xml'),
data=templateData)
def generatePackageMetadata(data, platform, outDir):
templateData = {
'APPNAME': data['applicationName'],
'BINNAME': data['binaryName'],
'VERSION': getVersion(),
'TIMESTAMP': time.strftime('%Y-%m-%d')
}
renderTemplate(
templatePath='../templates/qtinstaller/packages/bitmaskvpn/meta/package.xml',
outPath=os.path.join(outDir, 'packages/bitmaskvpn/meta/package.xml'),
data=templateData)
renderTemplate(
templatePath='../templates/qtinstaller/packages/bitmaskvpn/meta/install.js',
outPath=os.path.join(outDir, 'packages/bitmaskvpn/meta/install.js'),
data=templateData)
def renderTemplate(templatePath=None, outPath=None, data=None):
with open(os.path.join(here(), templatePath), 'r') as f:
t = f.read()
rendered = Template(t).substitute(**data)
os.makedirs(os.path.dirname(outPath), exist_ok=True)
with open(outPath, 'w') as out:
out.write(rendered)
def here():
return os.path.abspath(os.path.dirname(__file__))
def bail(msg=None):
if not msg:
print("ERROR: not enough arguments!")
print('Usage: {scriptname}.py