Add basic windows control system. Needs VM functional to continue

This commit is contained in:
Cole Deck 2024-01-17 20:14:20 -06:00
parent 9ac8f95982
commit 0bbfa2d49c
4 changed files with 32 additions and 18 deletions

3
.gitignore vendored
View File

@ -1,4 +1,5 @@
venv
__pycache__
cables
.vscode
.vscode
output.log

View File

@ -2,7 +2,7 @@ core:
mode: winclient
serverip: 192.168.1.20
clientip: 192.168.1.21
server: Hyper-Vs
server: Hyper-V
arm:
ip: 192.168.1.145

View File

@ -8,6 +8,7 @@ git+https://github.com/Byeongdulee/python-urx.git
psycopg2
pyyaml
Flask
selenium
# Development
matplotlib

44
run.py
View File

@ -17,6 +17,7 @@ import signal
config = None
keeprunning = True
arm_ready = False
@ -90,39 +91,46 @@ def mainloop_server(pool):
killall()
counter = counter + 1
def run_loading_app():
from flask import Flask, render_template
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
app.run(debug=True, use_reloader=False)
def setup_client(pool, config):
def setup_client(pool):
# Windows client setup
global config
# Open loading wepage
def run_app():
from flask import Flask, render_template
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
app.run(debug=True, use_reloader=False)
p = Process(target=run_app)
p = Process(target=run_loading_app)
p.start()
firefox = webdriver.Firefox()
firefox.fullscreen_window()
firefox.get('http://localhost:5000')
# start Linux server VM
if config["core"]["server"] == "Hyper-V":
run_cmd("Start-VM -Name Jukebox*") # any and all VMs starting with "Jukebox"
# Wait for VM to start and be reachable over the network
#pool.apply_async(vm_control.init, callback=vm_start_callback)
wait_for(vm_ready, "VM Startup")
p.terminate()
firefox.get(config["core"]["serverip"])
return True
def mainloop_client(pool):
sleep(0.1)
# listen for & act on commands from VM, if needed
# mainly just shut down, possibly connect to wifi or something
"""class Logger(object):
def __init__(self, filename="output.log"):
self.log = open(filename, "a")
@ -149,6 +157,9 @@ def killall():
def killall_signal(a, b):
global config
if config["core"]["server"] == "Hyper-V":
run_cmd("Stop-VM -Name Jukebox*") # any and all VMs starting with "Jukebox"
killall()
def error(msg, *args):
@ -181,7 +192,7 @@ class LoggingPool(Pool):
if __name__ == "__main__":
#sys.stdout = Logger(filename="output.log")
#sys.stderr = Logger(filename="output.log")
log_to_stderr(logging.DEBUG)
#log_to_stderr(logging.DEBUG)
with open('config.yml', 'r') as fileread:
#global config
@ -193,7 +204,8 @@ if __name__ == "__main__":
killme = manager.Value('d', 0)
signal.signal(signal.SIGINT, killall_signal)
if config["core"]["mode"] == "winclient":
if setup_client(pool, config):
from selenium import webdriver
if setup_client(pool):
while(keeprunning):
mainloop_client(pool)