From 0eb36c6301187170b0703a1c18316281fdbff4e4 Mon Sep 17 00:00:00 2001 From: Charlie Jacomme Date: Thu, 9 Aug 2018 15:42:52 +0200 Subject: [PATCH] bug fix abs path --- main.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/main.py b/main.py index 8c173ff..186ec8b 100755 --- a/main.py +++ b/main.py @@ -13,9 +13,10 @@ from subprocess import call import os.path import sys +path =(os.path.dirname(os.path.abspath(__file__))) config = ConfigParser() -config.read('config.ini') +config.read(path+'/config.ini') api_hostname = config.get('Re2o', 'hostname') api_password = config.get('Re2o', 'password') @@ -25,10 +26,6 @@ api_client = Re2oAPIClient(api_hostname, api_username, api_password) client_hostname = socket.gethostname().split('.', 1)[0] -for arg in sys.argv: - if arg=="--force": - generate(api_client) - def generate(api_client): all_users = api_client.list("localemail/users") # Création de l'environnement Jinja @@ -36,10 +33,10 @@ def generate(api_client): template = env.get_template('templates/list') aliases_rendered = template.render(data=all_users) - fichier = open('generated/aliases','w') + fichier = open(path+'/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(path+'/aliases_local','r') for line in local.readlines(): fichier.write(line) local.close() @@ -50,6 +47,10 @@ def generate(api_client): call(["/usr/bin/newaliases"]) # Update the aliases config file call(["postfix", "reload"]) # force the reloading now +for arg in sys.argv: + if arg=="--force": + generate(api_client) + for service in api_client.list("services/regen/"): if service['hostname'] == client_hostname and \ service['service_name'] == 'mail-server' and \