diff --git a/.gitignore b/.gitignore index e2ebfc2..06df7ba 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ .*swp* +*__pycache__ +www/config.js diff --git a/LJ_template..conf b/LJ_template..conf index f6456f0..3d5cc3d 100644 --- a/LJ_template..conf +++ b/LJ_template..conf @@ -6,6 +6,8 @@ wwwip = 192.168.2.43 nozoscip = 127.0.0.1 bhoroscip = 127.0.0.1 autostart = artnet +wstype = ws +wsport = 9001 [laser0] color = -1 diff --git a/configure.py b/configure.py index 84126c2..a18e6ac 100644 --- a/configure.py +++ b/configure.py @@ -7,7 +7,6 @@ v0.1.0 A console friendly interface to change important parameters - LICENCE : CC ''' @@ -15,20 +14,41 @@ import configparser from libs3 import gstt import ast import numpy as np -import updateUI +import os, sys +import fileinput +from shutil import copyfile +ljpath = r'%s' % os.getcwd().replace('\\','/') +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='') config = configparser.ConfigParser() config.read(gstt.ConfigName) qList = [ - {"q":"The server IP address ","c":"General","k":"ljayserverip"}, - {"q":"The IP address for webui","c":"General","k":"wwwip"}, - {"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"} + {"q":"The server IP address ","c":"General","k":"ljayserverip"}, + {"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"} ] stop = False while stop == False : @@ -54,7 +74,7 @@ while stop == False : new_value = input("Please enter the new value:") config.set(choice["c"],choice["k"],new_value) config.write(open(gstt.ConfigName,'w')) - print(choice["c"],choice["k"]) - if choice["k"] == "wwwip": - updateUI.www(new_value) + if choice["k"] in ["wwwip","wstype","wsport"] : + updateJSConfig(config) + print("*****************************\nUpdated the www configuration\n*****************************") diff --git a/templates/config.js b/templates/config.js new file mode 100644 index 0000000..ab5d429 --- /dev/null +++ b/templates/config.js @@ -0,0 +1 @@ +websocket_uri = "%wstype%://%wwwip%:%wsport%/" diff --git a/updateUI.py b/updateUI.py index ee985dd..eda3f01 100644 --- a/updateUI.py +++ b/updateUI.py @@ -1,67 +1,31 @@ -#!/usr/bin/python2.7 +#!/usr/bin/python3 # -*- coding: utf-8 -*- # -*- mode: Python -*- ''' -LJ UI IP updater v0.8.1 +LJ UI IP updater v0.9.0 + +MUST be called from configure.py ''' -#wwwIP = "192.168.2.78" -#wwwIP = "aurora.teamlaser.fr" -wwwIP = "192.168.1.48" import os, sys +import fileinput +from shutil import copyfile ljpath = r'%s' % os.getcwd().replace('\\','/') -python2 = (2, 6) <= sys.version_info < (3, 0) - -def Updatepage(file_name): - - print("updating", file_name) - f=open(file_name,"r+") - a=f.readlines() - #print a - - for line in a: - - if python2 == True: - - # python2 - if "var LJ = " in line > -1: - p=a.index(line) - #so now we have the position of the line which to be modified - a[p]=" var LJ = 'ws://"+wwwIP+":9001/'\n" - #print(p, line, a[p]) - - else: - - # python3 - IPline = ("var LJ = " in line) - if IPline == True: - - p=a.index(line) - #so now we have the position of the line which to be modified - a[p]=" var LJ = 'ws://"+wwwIP+":9001/'\n" - #print(p, line, a[p]) - - f.seek(0) - f.truncate() #ersing all data from the file - f.close() - #so now we have an empty file and we will write the modified content now in the file - o=open(file_name,"w") - for i in a: - o.write(i) - o.close() - #now the modification is done in the file - -def www(wwwip): - global wwwIP - - wwwIP = wwwip - print("Updating www files to use", wwwIP) - Updatepage(ljpath+"/www/LJ.js") - Updatepage(ljpath+"/www/trckr/trckrcam1.html") - Updatepage(ljpath+"/www/trckr/trckr.html") - Updatepage(ljpath+"/www/simu.html") - Updatepage(ljpath+"/www/align.html") - Updatepage(ljpath+"/www/auralls.html") - Updatepage(ljpath+"/www/index.html") +def www(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='') diff --git a/www/LJ.js b/www/LJ.js index 6d6dee4..743e289 100644 --- a/www/LJ.js +++ b/www/LJ.js @@ -4,7 +4,7 @@ // LJ websocket address. IP will be updated at LJ startup according to LJ.conf wwwIP - var LJ = 'ws://192.168.2.43:9001/' + var LJ = websocket_uri // diff --git a/www/align.html b/www/align.html index 3441aed..6a6d427 100644 --- a/www/align.html +++ b/www/align.html @@ -19,6 +19,7 @@ + + + +