From 0bbfa2d49c0d603d324410e2b8bfe9223af31081 Mon Sep 17 00:00:00 2001 From: Cole Deck Date: Wed, 17 Jan 2024 20:14:20 -0600 Subject: [PATCH] Add basic windows control system. Needs VM functional to continue --- .gitignore | 3 ++- config.yml | 2 +- requirements.txt | 1 + run.py | 44 ++++++++++++++++++++++++++++---------------- 4 files changed, 32 insertions(+), 18 deletions(-) diff --git a/.gitignore b/.gitignore index 12529b9..47adc1a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ venv __pycache__ cables -.vscode \ No newline at end of file +.vscode +output.log \ No newline at end of file diff --git a/config.yml b/config.yml index e44fbf7..1ceadd5 100644 --- a/config.yml +++ b/config.yml @@ -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 diff --git a/requirements.txt b/requirements.txt index 5827b32..062c68c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,6 +8,7 @@ git+https://github.com/Byeongdulee/python-urx.git psycopg2 pyyaml Flask +selenium # Development matplotlib diff --git a/run.py b/run.py index 86978fb..0705f65 100755 --- a/run.py +++ b/run.py @@ -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)