bug fix abs path

This commit is contained in:
Charlie Jacomme 2018-08-09 15:42:52 +02:00
parent 8efe64530a
commit 0eb36c6301

15
main.py
View file

@ -13,9 +13,10 @@ from subprocess import call
import os.path import os.path
import sys import sys
path =(os.path.dirname(os.path.abspath(__file__)))
config = ConfigParser() config = ConfigParser()
config.read('config.ini') config.read(path+'/config.ini')
api_hostname = config.get('Re2o', 'hostname') api_hostname = config.get('Re2o', 'hostname')
api_password = config.get('Re2o', 'password') 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] client_hostname = socket.gethostname().split('.', 1)[0]
for arg in sys.argv:
if arg=="--force":
generate(api_client)
def generate(api_client): def generate(api_client):
all_users = api_client.list("localemail/users") all_users = api_client.list("localemail/users")
# Création de l'environnement Jinja # Création de l'environnement Jinja
@ -36,10 +33,10 @@ def generate(api_client):
template = env.get_template('templates/list') template = env.get_template('templates/list')
aliases_rendered = template.render(data=all_users) 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 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(): for line in local.readlines():
fichier.write(line) fichier.write(line)
local.close() local.close()
@ -50,6 +47,10 @@ def generate(api_client):
call(["/usr/bin/newaliases"]) # Update the aliases config file call(["/usr/bin/newaliases"]) # Update the aliases config file
call(["postfix", "reload"]) # force the reloading now 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/"): for service in api_client.list("services/regen/"):
if service['hostname'] == client_hostname and \ if service['hostname'] == client_hostname and \
service['service_name'] == 'mail-server' and \ service['service_name'] == 'mail-server' and \