verifie si il y a besoin de regénérer

This commit is contained in:
grisel-davy 2018-08-07 17:38:12 +02:00
parent dac9cca994
commit 570dc611d4

28
main.py Executable file → Normal file
View file

@ -25,22 +25,30 @@ client_hostname = socket.gethostname().split('.', 1)[0]
all_users = api_client.list("mail/alias") all_users = api_client.list("mail/alias")
# Création de l'environnement Jinja
env = Environment(loader=FileSystemLoader('.'))
template = env.get_template('templates/list')
aliases_rendered = template.render(data=all_users)
fichier = open('generated/aliases','w') def generate(api_client):
# Création de l'environnement Jinja
env = Environment(loader=FileSystemLoader('.'))
template = env.get_template('templates/list')
aliases_rendered = template.render(data=all_users)
if os.path.isfile('aliases_local'): # if a local aliases file exist, add it's content at the beginning fichier = open('generated/aliases','w')
if os.path.isfile('aliases_local'): # if a local aliases file exist, add it's content at the beginning
local = open('aliases_local','r') local = open('aliases_local','r')
for line in local.readlines(): for line in local.readlines():
fichier.write(line) fichier.write(line)
local.close() local.close()
fichier.write(aliases_rendered) fichier.write(aliases_rendered)
fichier.close() fichier.close()
call(["newalias", "generated/aliases"]) # Update the aliases config file
call(["postfix", "reload"]) # force the reloading now
call(["newalias", "generated/aliases"]) # Update the aliases config file for service in api_client.list("services/regen/"):
call(["postfix", "reload"]) # force the reloading now if service['hostname'] == client_hostname and \
service['service_name'] == 'mail-server' and \
service['need_regen']:
generate(api_client)
api_client.patch(service['api_url'], data={'need_regen': False})