mtes-scripts/scripts/module/set_var.py

61 lines
1.4 KiB
Python
Raw Normal View History

2021-05-07 11:22:59 +02:00
#!/usr/bin/env python
# -*- coding: utf-8 -*-
2021-05-10 15:40:55 +02:00
import sys, getpass, socket, cjson
2021-05-07 11:22:59 +02:00
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")
2021-05-10 15:40:55 +02:00
print("{} [--var nom_variable --value valeur]".format(sys.argv[0]))
2021-05-07 11:22:59 +02:00
def argparser():
# récupère l'ID du groupe
arglen = len(sys.argv)
if arglen == 1:
2021-05-10 15:40:55 +02:00
return None, None
2021-05-07 11:22:59 +02:00
if sys.argv[1] in ['-h', '--help']:
display_help()
sys.exit(0)
2021-05-10 15:40:55 +02:00
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
2021-05-07 11:22:59 +02:00
2021-05-10 15:40:55 +02:00
return None, None
2021-05-07 11:22:59 +02:00
def main():
# import des fonctions communes de Zéphir client
2021-05-10 15:40:55 +02:00
varc, valvar = argparser()
2021-05-07 11:22:59 +02:00
if varc is None :
2021-05-10 15:40:55 +02:00
varc = raw_input("Variable à modifier : ")
2021-05-07 11:22:59 +02:00
if valvar is None :
2021-05-10 15:40:55 +02:00
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()
2021-05-07 11:22:59 +02:00
if __name__ == '__main__':
main()