#!/usr/bin/python2.7

from ConfigParser import RawConfigParser

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
parser = RawConfigParser()
with open(app.get_cache_file('settings'), 'rb') as f:
	parser.readfp(f)
	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'), 'wb') as f:
	parser.write(f)

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