wapt-thunderbird-config/setup.py

49 lines
2.2 KiB
Python
Raw Normal View History

2018-12-05 16:46:30 +01:00
# -*- coding: utf-8 -*-
from setuphelpers import *
import os
from jinja2 import Environment, FileSystemLoader
uninstallkey = []
variables = {
'thunderbird_config_url': 'https://server/mcd/thunderbird.cfg',
'thunderbird_config_append_domain': ''
}
# Read local variables file if available
if isfile(makepath(programfiles32,'wapt','private','symetric.txt')) and isfile(makepath(programfiles32,'wapt','private','variables.txt')):
print('Reading local encrypted variables file')
2018-12-20 13:16:25 +01:00
from cryptography.fernet import Fernet
import yaml
2018-12-05 16:46:30 +01:00
f = Fernet(open(makepath(programfiles32,'wapt','private','symetric.txt'),'r').read())
2018-12-20 13:16:25 +01:00
variables.update(yaml.safe_load(f.decrypt(open(makepath(programfiles32,'wapt','private','variables.txt'),'r').read())))
2018-12-05 16:46:30 +01:00
def install():
2018-12-10 17:42:04 +01:00
filecopyto('autoconf.js', makepath(programfiles,'Mozilla Thunderbird','defaults','pref'))
if not isdir(makepath(programfiles, 'Mozilla Thunderbird','chrome')):
mkdirs(makepath(programfiles, 'Mozilla Thunderbird','chrome'))
filecopyto('custom-strings.txt', makepath(programfiles,'Mozilla Thunderbird','chrome'))
2018-12-05 16:46:30 +01:00
jinja2 = Environment(
2018-12-20 13:16:25 +01:00
loader=FileSystemLoader(os.getcwd()),
2018-12-05 16:46:30 +01:00
trim_blocks=True
)
2018-12-10 17:42:04 +01:00
open(makepath(programfiles,'Mozilla Thunderbird','thunderbird.cfg'),'w').write(
2018-12-05 16:46:30 +01:00
jinja2.get_template('thunderbird.cfg.j2').render(
thunderbird_config_url = variables['thunderbird_config_url'],
thunderbird_config_append_domain = variables['thunderbird_config_append_domain']
)
)
def uninstall():
2018-12-20 13:16:25 +01:00
remove_file(makepath(programfiles,'Mozilla Thunderbird','defaults','pref','autoconf.js'))
remove_file(makepath(programfiles,'Mozilla Thunderbird','chrome','custom-strings.txt'))
remove_file(makepath(programfiles,'Mozilla Thunderbird','thunderbird.cfg'))
2018-12-05 16:46:30 +01:00
def audit():
if (
2018-12-10 17:42:04 +01:00
not isfile(makepath(programfiles,'Mozilla Thunderbird','defaults','pref','autoconf.js')) or
not isfile(makepath(programfiles,'Mozilla Thunderbird','chrome','custom-strings.txt')) or
not isfile(makepath(programfiles,'Mozilla Thunderbird','thunderbird.cfg'))
2018-12-05 16:46:30 +01:00
):
print('At least one config file is missing')
return "ERROR"
return "OK"