#!/usr/bin/python3
# -*- coding: utf-8 -*-


from six.moves.configparser import ConfigParser

from univention.appcenter.log import log_to_stream
from univention.appcenter.actions import get_action
from univention.appcenter.app_cache import Apps
from univention.appcenter.ucr import ucr_save

log_to_stream()
update = get_action('update')
update.call()

app = Apps().find('relution')

print('Changing default settings for', app)
print(app.get_cache_file('settings'))
parser = ConfigParser()
parser.read_file(open(app.get_cache_file('settings')))
parser.set('SYSTEM_ADMIN_PASSWORD', 'InitialValue', 'secret-password123')
parser.set('ORGA_ADMIN_USERNAME', 'InitialValue', 'orga_admin')
parser.set('ORGA_ADMIN_PASSWORD', 'InitialValue', 'secret-password123')
parser.set('ORGA_ADMIN_GIVENNAME', 'InitialValue', 'John')
parser.set('ORGA_ADMIN_SURNAME', 'InitialValue', 'Doe')
parser.set('', 'InitialValue', '')

with open(app.get_cache_file('settings'), 'w') as f:
	parser.write(f)

Apps().clear_cache()
ucr_save({'appcenter/umc/update/always': 'false'})

