-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.py
More file actions
60 lines (39 loc) · 2.03 KB
/
run.py
File metadata and controls
60 lines (39 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import os
import webbrowser
import yaml
import sys
from http.server import HTTPServer, CGIHTTPRequestHandler
from pathlib import Path
current_directory = os.path.dirname(os.path.realpath(__file__))
config_file = ''
try:
config_file = open("config.yaml")
except:
sys.exit("Unable to open configuration file. Make sure that the config.yaml is avalible at the .exe directory")
config = yaml.load(config_file, Loader=yaml.FullLoader)
# Validate Config.yaml
if config["httpserver"]["port"] is None:
print("Server port not configured, assuming default port: 8080")
config["httpserver"]["port"] = 8080
if config["httpserver"]["directory"] is None:
print("Server Directory not configured, assuming default directory: " + current_directory)
config["httpserver"]["directory"] = current_directory
if config["webbrowser"]["open_url_after_launch"] is None:
print("'Open URL After Launch' not configured, assuming default: True")
config["webbrowser"]["open_url_after_launch"] = True
if config["webbrowser"]["window"] is None:
print("'Browser tab configuration' not epecified, assuming default: 1 - A New Browser Windows is opned is possible")
config["webbrowser"]["window"] = 1
if config["webbrowser"]["autoraise"] is None:
print("'Browser windows autoraise' not epecified, assuming default: True")
config["webbrowser"]["autoraise"] = True
if config["webbrowser"]["url"] is None:
print("'Browser URL' not epecified, assuming default: http://localhost")
config["webbrowser"]["url"] = 'http://localhost:' + str(config["httpserver"]["port"])
os.chdir(config["httpserver"]["directory"])
# Create server object
server_object = HTTPServer(server_address=('', config["httpserver"]["port"]), RequestHandlerClass=CGIHTTPRequestHandler)
if config["webbrowser"]["open_url_after_launch"]:
# Open Web Page on Default Browser if Possible
webbrowser.open(config["webbrowser"]["url"], new=config["webbrowser"]["window"], autoraise=config["webbrowser"]["autoraise"])
server_object.serve_forever()