Skip to content

Commit

Permalink
Omnibus Launcher (#141)
Browse files Browse the repository at this point in the history
* Rewrote launcher to support macOS

* Fixed KeyError

* Added prompt menu and new profiles

* Terminate all processes when any of them exits

* Added stderr printing

* Updated stdout and stderr printing, changed how programs are terminated

* Added signal for Windows

* Potential fix for signal on Windows

* I hate Windows

* proof of concept works

* Misc WDR fixes

* dynamic text dash item, fix errors and dynamic sizing

* More fixes

* Limit title length

* Found better alternative than QTimer

now we listen to all can messages (acts as our interrupt function) and then check if the specified peiod has changed, in which case, send the can message.

* Update DAQ config

* Live fixes

* Add printing to replay log

* Fix parsley performance

* Remove CAN message table

* Clean up wdr nitpicks

* Clean up parsley source

* Fix unit tests, autopep8

* Add duplicate item button, optional filter on dynamic text and sorted item keys (#111)

* Update RLCS source

* RLCS source improvements

* Update parsley for live telemetry

* Update requirements.txt to fix imageitem

* Let RLCS control valves

* Add better dashboard error and reset handling

* Autocomplete dashitems

* add general board table item

* wip: use QItemDelegate to add dropdown instead

* improve copy pasting and add deleting to general boards widget

* finish new dropdown implementation and add save/restore support

* improve finding list of paths

* make table rows draggable

* rename general boards to table view

* prevent cell deletion when none is selected

* add store/restore header for table view and ctrl-x for cut

* add support for binary telemetry message

* wip: switch to new binary encoding for telemetry

* support for new binary encoding

* Add dynamic_text background colour change (#113)

* dynamic_text: Added button param to make new params

* dynamic_text: Add conditions to change background color

* dynamic_text: Made requested changes

* dynamic_text: Removed float casting to allow CAN messages

* dynamic_text: Casting condition param to str for comparison

* correct typo

* Format

---------

Co-authored-by: Kavin Satheeskumar <[email protected]>
Co-authored-by: Kavin <[email protected]>

* add support for binary telemetry message

* wip: switch to new binary encoding for telemetry

* support for new binary encoding

* fix some bugs

* Add the ability to select which parsley instance you want to send to

* omnibus to gpsd converter

* Revert "Add the ability to select which parsley instance you want to send to"

This reverts commit 923bcb4.

* Drive changes

Fixes a few bugs, light mode, adds parsley selection

* Fix parsley

* change parsely names to telemetry/none-telemetry; add keep alive bytes for telemetry

* increase table widget margin

* remove commented code project-wide (#117)

* Fix exception caused by empty series

* Fixed plot scaling issue (#119)

Fixed plot scaling issue, removed broken tests and downgraded parsley.

* Added and fixed clear button (#121)

Added a dashboard 'Clear' button

* Rewrote launcher to support macOS

* Fixed KeyError

* Added prompt menu and new profiles

* Terminate all processes when any of them exits

* Added stderr printing

* Updated stdout and stderr printing, changed how programs are terminated

* Added signal for Windows

* Potential fix for signal on Windows

* I hate Windows

* Rewrote launcher to dynamically get all sources and sinks

* Added comment

* Deal with 1920x1080 screen resolution on Wayland (#143)

* Another Wayland fix (for dynamic text) (#144)

* Deal with 1920x1080 screen resolution on Wayland

* Fix dynamic text for Wayland

* Added finally section to ensure all spawned process are killed no matter how the program exits

* Removed flakey replay_log unit test

* Ran format.sh to enforce autopep

* Python executable and signal changes for Windows

---------

Co-authored-by: Michael Li <[email protected]>
Co-authored-by: BluCodeGH <[email protected]>
Co-authored-by: DAQ Computer <[email protected]>
Co-authored-by: Michael <[email protected]>
Co-authored-by: Kavin Satheeskumar <[email protected]>
Co-authored-by: Robert Cai <[email protected]>
Co-authored-by: Rio Liu <[email protected]>
Co-authored-by: Rio <[email protected]>
Co-authored-by: Fayzulloh Ergashev <[email protected]>
Co-authored-by: Kavin <[email protected]>
Co-authored-by: Anthony Chen <[email protected]>
Co-authored-by: MaisimZaman <[email protected]>
  • Loading branch information
13 people authored Oct 24, 2023
1 parent 5aa6533 commit c922213
Showing 1 changed file with 75 additions and 27 deletions.
102 changes: 75 additions & 27 deletions launcher.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,85 @@
import os
import signal
import subprocess
import sys
from subprocess import Popen, CREATE_NEW_CONSOLE
import time

# Some specific commands are needed for Windows vs macOS/Linux
if sys.platform == "win32":
from subprocess import CREATE_NEW_PROCESS_GROUP
python_executable = "venv/Scripts/python"
else:
python_executable = "python"

profiles = {
"test": ['python -m omnibus',
'python sinks/plot/main.py',
'python sources/ni/main.py'],
"texas": ['python sources/parsley/main.py $arg',
'python sources/ni/main.py',
'python -m omnibus']
# Add other profiles in here
# If any commands require arguments to be passed in, write $arg in its place
# Parse folders for sources and sinks
modules = {"sources" : os.listdir('sources'), "sinks" : os.listdir('sinks')}

}
# Remove dot files
for module in modules.keys():
for item in modules[module]:
if item.startswith("."):
modules[module].remove(item)

for module in modules.keys():
print(f"{module.capitalize()}:")
for i, item in enumerate(modules[module]):
print(f"\t{i+1}. {item.capitalize()}")

try:
if sys.argv[1] == "_wrap":
p = Popen(sys.argv[2])
if p.wait() != 0:
input('Press enter to quit')
# Construct CLI commands to start Omnibus
source_selection = input(f"\nPlease enter your Source choice [1-{len(modules['sources'])}]: ")
sink_selection = input(f"Please enter your Sink choice [1-{len(modules['sinks'])}]: ")
omnibus = [python_executable, "-m", "omnibus"]
source = [python_executable, f"sources/{modules['sources'][int(source_selection) - 1]}/main.py"]
sink = [python_executable, f"sinks/{modules['sinks'][int(sink_selection) - 1]}/main.py"]

commands = [omnibus, source, sink]
processes = []
print("Launching... ", end="")

# Execute commands as subprocesses
for command in commands:
if sys.platform == "win32":
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
creationflags=CREATE_NEW_PROCESS_GROUP)
else:
selection = sys.argv[1]
processes = profiles[selection]
args = sys.argv[2:]
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

time.sleep(0.5)
processes.append(process)

print("Done!")

# Blank exception just for processes to throw
class Finished(Exception):
pass

# If any file exits or the user presses control + c,
# terminate all other files that are running
try:
while True:
for process in processes:
while '$arg' in process:
process = process.replace('$arg', args[0], 1)
args.pop(0)
Popen(f'python launcher.py _wrap "{process}"', creationflags=CREATE_NEW_CONSOLE)

except (KeyError, IndexError):
print('Please enter a single valid profile selection (ex. python launcher.py texas)')
print('Ensure that you have entered the correct amount of args required for each script in the right order')
if process.poll() != None:
raise Finished
except (Finished, KeyboardInterrupt, Exception):
for process in processes:
if sys.platform == "win32":
os.kill(process.pid, signal.CTRL_BREAK_EVENT)
else:
process.send_signal(signal.SIGINT)

# Dump output and error (if exists) from every
# process to the shell
output, err = process.communicate()
output, err = output.decode(), err.decode()
print(f"\nOutput from {process.args}:")
print(output)

if err and "KeyboardInterrupt" not in err:
print(f"\nError from {process.args}:")
print(err)
finally:
for process in processes:
if sys.platform == "win32":
os.kill(process.pid, signal.CTRL_BREAK_EVENT)
else:
process.send_signal(signal.SIGINT)

0 comments on commit c922213

Please sign in to comment.