mtes-scripts/scripts/module/set_var.py
2021-05-10 15:40:55 +02:00

61 lines
1.4 KiB
Python

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys, getpass, socket, cjson
from pyeole.ihm import print_line
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]".format(sys.argv[0]))
def argparser():
# récupère l'ID du groupe
arglen = len(sys.argv)
if arglen == 1:
return None, None
if sys.argv[1] in ['-h', '--help']:
display_help()
sys.exit(0)
if sys.argv[1] in ['-v', '--var']:
varc = sys.argv[2]
return varc, None
if sys.argv[3] in ['-l', '--value']:
valvar = sys.argv[4]
return varc, valvar
return None, None
def main():
# import des fonctions communes de Zéphir client
varc, valvar = argparser()
if varc is None :
varc = raw_input("Variable à modifier : ")
if valvar is None :
valvar = raw_input("Valeur de la variable : ")
fh = open("/etc/eole/config.eol", 'r')
store = cjson.decode(fh.read(), all_unicode=True)
fh.close
if varc in store:
store[varc]['val'] = valvar
fh = open("/etc/eole/config.eol", 'w')
fh.write(cjson.encode(store))
fh.close()
if __name__ == '__main__':
main()