verifie si il y a besoin de regénérer
This commit is contained in:
parent
dac9cca994
commit
570dc611d4
1 changed files with 22 additions and 14 deletions
36
main.py
Executable file → Normal file
36
main.py
Executable file → Normal file
|
@ -25,22 +25,30 @@ client_hostname = socket.gethostname().split('.', 1)[0]
|
|||
|
||||
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
|
||||
local = open('aliases_local','r')
|
||||
for line in local.readlines():
|
||||
fichier.write(line)
|
||||
local.close()
|
||||
fichier = open('generated/aliases','w')
|
||||
|
||||
fichier.write(aliases_rendered)
|
||||
fichier.close()
|
||||
if os.path.isfile('aliases_local'): # if a local aliases file exist, add it's content at the beginning
|
||||
local = open('aliases_local','r')
|
||||
for line in local.readlines():
|
||||
fichier.write(line)
|
||||
local.close()
|
||||
|
||||
fichier.write(aliases_rendered)
|
||||
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
|
||||
call(["postfix", "reload"]) # force the reloading now
|
||||
|
||||
for service in api_client.list("services/regen/"):
|
||||
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})
|
||||
|
|
Loading…
Reference in a new issue