Skip to content

Commit c309316

Browse files
committed
Make port reassignable
1 parent e38f79d commit c309316

File tree

4 files changed

+48
-6
lines changed

4 files changed

+48
-6
lines changed

WebPageProcessor/webPageProcessor.py

-5
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@ class WebPageProcessor:
1616

1717
def __init__(self, data):
1818
self.data = data
19-
print("opening browser")
20-
webbrowser.open_new_tab("http://localhost:5000")
21-
host_name = socket.gethostname()
22-
host_ip = socket.gethostbyname(host_name)
23-
self.data.hostAddress = host_ip+":5000"
2419

2520
def createWebPage(self, pageID, isMobile, args):
2621
# returns a page and a bool specifying whether the user has to click close to exit modal

config/config.py

+17
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,23 @@ def __init__(self):
102102
self.settings, outfile, sort_keys=True, indent=4, ensure_ascii=False
103103
)
104104

105+
def checkForTouchedPort(self):
106+
home = self.home
107+
path = home+"/.WebControl/webcontrol-*.port"
108+
print(path)
109+
try:
110+
for filename in glob.glob(path):
111+
print(filename)
112+
port = filename.split("-")
113+
port = port[1].split(".port")
114+
print(port[0])
115+
self.data.config.setValue("WebControl Settings", "webPort", port[0])
116+
os.remove(filename)
117+
except Exception as e:
118+
print(e)
119+
return False
120+
return True
121+
105122
def getHome(self):
106123
return self.home
107124

defaultwebcontrol.json

+9
Original file line numberDiff line numberDiff line change
@@ -982,6 +982,15 @@
982982
"title": "Enable 3D Display",
983983
"type": "bool",
984984
"value": "0"
985+
},
986+
{
987+
"default": 5000,
988+
"desc": "Web interface Port Number used to access WebControl from browser. Requires restart to change.\ndefault setting: 5000",
989+
"key": "webPort",
990+
"section": "WebControl Settings",
991+
"title": "Web Port Number",
992+
"type": "int",
993+
"value": 5000
985994
}
986995
],
987996
"Camera Settings": [

main.py

+22-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from app import app, socketio
33
from gevent import monkey
44
import webbrowser
5+
import socket
56

67
monkey.patch_all()
78

@@ -617,5 +618,25 @@ def default_error_handler(e):
617618
if __name__ == "__main__":
618619
app.debug = False
619620
app.config["SECRET_KEY"] = "secret!"
620-
socketio.run(app, use_reloader=False, host="0.0.0.0")
621+
#look for touched file
622+
app.data.config.checkForTouchedPort()
623+
webPort = app.data.config.getValue("WebControl Settings", "webPort")
624+
webPortInt = 5000
625+
try:
626+
webPortInt = int(webPort)
627+
if webPortInt < 0 or webPortInt > 65535:
628+
webPortInt = 5000
629+
except Exception as e:
630+
app.data.console_queue.put(e)
631+
app.data.console_queue.put("Invalid port assignment found in webcontrol.json")
632+
633+
print("opening browser")
634+
webPortStr = str(webPortInt)
635+
webbrowser.open_new_tab("http://localhost:"+webPortStr)
636+
host_name = socket.gethostname()
637+
host_ip = socket.gethostbyname(host_name)
638+
app.data.hostAddress = host_ip + ":" + webPortStr
639+
640+
socketio.run(app, use_reloader=False, host="0.0.0.0", port=webPortInt)
621641
# socketio.run(app, host='0.0.0.0')
642+

0 commit comments

Comments
 (0)