LJ/configure.py

81 lines
2.8 KiB
Python
Raw Normal View History

2020-09-22 19:58:14 +00:00
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# -*- mode: Python -*-
'''
2020-09-24 00:54:55 +00:00
LJ
2020-09-22 19:58:14 +00:00
v0.1.0
A console friendly interface to change important parameters
LICENCE : CC
'''
import configparser
from libs3 import gstt
import ast
import numpy as np
import os, sys
import fileinput
from shutil import copyfile
ljpath = r'%s' % os.getcwd().replace('\\','/')
2020-09-22 19:58:14 +00:00
def updateJSConfig(config):
global ljpath
wwwip = config.get('General','wwwip')
wstype = config.get('General','wstype')
wsport = config.get('General','wsport')
# copy template
src = ljpath + "/templates/config.js"
dst = ljpath + "/www/config.js"
copyfile(src, dst)
# Interpolate variables
with fileinput.FileInput(dst, inplace=True) as file:
for line in file:
line = line.replace("%wstype%", wstype)
line = line.replace("%wsport%", wsport)
line = line.replace("%wwwip%", wwwip)
print(line, end='')
2020-09-22 19:58:14 +00:00
config = configparser.ConfigParser()
config.read(gstt.ConfigName)
qList = [
2023-06-03 12:43:53 +00:00
{"q":"The server IP address ","c":"General","k":"RediServerIP"},
{"q":"The IP address for webui ","c":"General","k":"wwwip"},
{"q":"Websocket type (ws or wss?) ","c":"General","k":"wstype"},
{"q":"Websocket port ","c":"General","k":"wsport"},
{"q":"How many lasers to use ","c":"General","k":"lasernumber"},
{"q":"Laser 0 IP address ","c":"laser0","k":"ip"},
{"q":"Laser 1 IP address ","c":"laser1","k":"ip"},
{"q":"Laser 2 IP address ","c":"laser2","k":"ip"},
{"q":"Laser 3 IP address ","c":"laser3","k":"ip"}
2020-09-22 19:58:14 +00:00
]
stop = False
while stop == False :
print( "------------------------------------------------------")
print( "Which part of the configuration do you wish to change?")
print( "------------------------------------------------------")
print( "Enter a numeric key or 'x' to stop")
for i in range(len(qList)):
item = qList[i]
question = item["q"]
category = item["c"]
key = item["k"]
val = config.get(category,key )
print( "-")
print( "Choice #"+str(i), "\t"+question+ "\tCurrent value:",val )
print( "......................................................")
name = input("Enter your choice: ")
if name == "x":
stop = True
break
print( "......................................................")
choice = qList[int(name)]
new_value = input("Please enter the new value:")
config.set(choice["c"],choice["k"],new_value)
config.write(open(gstt.ConfigName,'w'))
if choice["k"] in ["wwwip","wstype","wsport"] :
updateJSConfig(config)
print("*****************************\nUpdated the www configuration\n*****************************")
2020-09-22 19:58:14 +00:00