86 lines
2.3 KiB
Python
86 lines
2.3 KiB
Python
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
|
|
import sys, getpass, socket, cjson, os
|
|
from pyeole.ihm import print_line, question_ouinon
|
|
from pyeole.ansiprint import print_orange, print_red
|
|
from creole.client import CreoleClient
|
|
from collections import OrderedDict
|
|
|
|
|
|
def display_help():
|
|
print("Modification de la valeur d'une variable d'un serveur")
|
|
print("{} [--var nom_variable --value valeur --save --no-save]".format(sys.argv[0]))
|
|
|
|
|
|
def argparser():
|
|
# récupère l'ID du groupe
|
|
arglen = len(sys.argv)
|
|
save = None
|
|
if "--save" in sys.argv:
|
|
save = True
|
|
if "--no-save" in sys.argv:
|
|
save = False
|
|
if arglen == 1:
|
|
return None, None, save
|
|
|
|
if sys.argv[1] in ['-h', '--help']:
|
|
display_help()
|
|
sys.exit(0)
|
|
|
|
if sys.argv[1] in ['-v', '--var']:
|
|
varc = sys.argv[2]
|
|
if sys.argv[3] in ['-l', '--value']:
|
|
valvar = sys.argv[4]
|
|
return varc, valvar, save
|
|
else:
|
|
return varc, None, save
|
|
|
|
return None, None, save
|
|
|
|
|
|
def main():
|
|
# import des fonctions communes de Zéphir client
|
|
varc, valvar, save = argparser()
|
|
|
|
fh = open("/etc/eole/config.eol", 'r')
|
|
store = cjson.decode(fh.read(), all_unicode=True)
|
|
fh.close
|
|
|
|
if varc is None :
|
|
print
|
|
print('Liste des variables modifiables :')
|
|
for var in store:
|
|
print(' - ' + var)
|
|
varc = raw_input("Variable à modifier : ")
|
|
|
|
if valvar is None :
|
|
valvar = raw_input("Valeur de la variable : ")
|
|
|
|
if varc in store:
|
|
if "|" in valvar:
|
|
valvar = valvar.split("|")
|
|
store[varc]['val'] = valvar
|
|
|
|
fh = open("/etc/eole/config.eol", 'w')
|
|
fh.write(cjson.encode(store))
|
|
fh.close()
|
|
|
|
if save is None :
|
|
if question_ouinon("Souhaitez vous sauvegarder la configuration sur Zephir ?", default='non') == 'oui':
|
|
print("Sauvegarde de la configuration sur zephir")
|
|
save=True
|
|
else:
|
|
print("La configuration ne sera pas sauvegardé sur zephir")
|
|
|
|
if save:
|
|
cmd="""/usr/share/zephir/scripts/zephir_client save_files"""
|
|
output = os.popen(cmd)
|
|
output.close()
|
|
else:
|
|
print_orange('Erreur : variable {} inconnue'.format(varc))
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|