Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from robotics_application_manager import LogManager



class LauncherO3de(ILauncher):
running: bool = False
threads: List[Any] = []
Expand Down
57 changes: 37 additions & 20 deletions robotics_application_manager/manager/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -686,13 +686,13 @@ def on_change_style(self, event):
lxde_conf_dir = os.path.expanduser("~/.config/lxsession/LXDE")
lxde_conf_path = os.path.join(lxde_conf_dir, "desktop.conf")
os.makedirs(lxde_conf_dir, exist_ok=True)

# Read existing or create new
conf_lines = []
if os.path.exists(lxde_conf_path):
with open(lxde_conf_path, "r") as f:
conf_lines = f.readlines()

# Ensure GTK section exists and update theme name
gtk_section_found = False
for i, line in enumerate(conf_lines):
Expand All @@ -705,20 +705,23 @@ def on_change_style(self, event):
if not gtk_section_found:
conf_lines.append("[GTK]\\n")
conf_lines.append(f"sNet/ThemeName={gtk_theme}\\n")

with open(lxde_conf_path, "w") as f:
f.writelines(conf_lines)

# Reload window manager (Openbox) and LXPanel
subprocess.run(
["bash", "-c", "export DISPLAY=:1; lxpanelctl restart; openbox --reconfigure"],
[
"bash",
"-c",
"export DISPLAY=:1; lxpanelctl restart; openbox --reconfigure",
],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL
stderr=subprocess.DEVNULL,
)
except Exception as e:
LogManager.logger.exception(f"Error refreshing GTK applications: {e}")


def on_run_application(self, event):
"""
Handle the 'run_application' event.
Expand Down Expand Up @@ -763,7 +766,7 @@ def on_run_application(self, event):

_, file_extension = os.path.splitext(entrypoint)

if file_extension == ".cpp":
if file_extension == ".cpp" or entrypoint.endswith(".launch.py"):
fds = os.listdir("/dev/pts/")
console_fd = str(max(map(int, fds[:-1])))

Expand All @@ -780,23 +783,37 @@ def on_run_application(self, event):
executable="/bin/bash",
)
returncode = compile_process.wait()
print(returncode)
if returncode != 0:
raise Exception("Failed to compile")

self.unpause_sim()
self.application_process = subprocess.Popen(
[
"source /workspace/code/install/setup.bash && ros2 run academy academyCode"
],
stdin=open("/dev/pts/" + console_fd, "r"),
stdout=open("/dev/pts/" + console_fd, "w"),
stderr=sys.stdout,
bufsize=1024,
universal_newlines=True,
shell=True,
executable="/bin/bash",
)
if entrypoint.endswith(".launch.py"):
self.application_process = subprocess.Popen(
[
f"source /workspace/code/install/setup.bash && ros2 launch {entrypoint}"
],
stdin=open("/dev/pts/" + console_fd, "r"),
stdout=open("/dev/pts/" + console_fd, "w"),
stderr=sys.stdout,
bufsize=1024,
universal_newlines=True,
shell=True,
executable="/bin/bash",
)
else:

self.application_process = subprocess.Popen(
[
"source /workspace/code/install/setup.bash && ros2 run academy academyCode"
],
stdin=open("/dev/pts/" + console_fd, "r"),
stdout=open("/dev/pts/" + console_fd, "w"),
stderr=sys.stdout,
bufsize=1024,
universal_newlines=True,
shell=True,
executable="/bin/bash",
)
return

# Pass the linter
Expand Down
23 changes: 17 additions & 6 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,13 @@ def stop(self):
def manager(monkeypatch):
"""Fixture to provide a Manager instance with patched dependencies for testing."""

monkeypatch.setattr("robotics_application_manager.comms.websocket_server.WebsocketServer", DummyServer)
monkeypatch.setattr("robotics_application_manager.manager.manager.ManagerConsumer", DummyConsumer)
monkeypatch.setattr(
"robotics_application_manager.comms.websocket_server.WebsocketServer",
DummyServer,
)
monkeypatch.setattr(
"robotics_application_manager.manager.manager.ManagerConsumer", DummyConsumer
)

# Patch subprocess.check_output for ROS_DISTRO and IMAGE_TAG
def fake_check_output(cmd, *a, **k):
Expand All @@ -91,14 +96,16 @@ def fake_check_output(cmd, *a, **k):

# Patch check_gpu_acceleration where it is used
monkeypatch.setattr(
"robotics_application_manager.manager.manager.check_gpu_acceleration", lambda x=None: "OFF"
"robotics_application_manager.manager.manager.check_gpu_acceleration",
lambda x=None: "OFF",
)

def dummy_run(self, start_pose=None):
print("run around")

monkeypatch.setattr(
"robotics_application_manager.manager.launcher.launcher_robot.LauncherRobot.run", dummy_run
"robotics_application_manager.manager.launcher.launcher_robot.LauncherRobot.run",
dummy_run,
)

# Patch os.makedirs and os.path.isdir to avoid real FS operations
Expand All @@ -121,7 +128,9 @@ def run(self):
def terminate(self):
pass

monkeypatch.setattr("robotics_application_manager.manager.manager.LauncherWorld", DummyLauncherWorld)
monkeypatch.setattr(
"robotics_application_manager.manager.manager.LauncherWorld", DummyLauncherWorld
)

class DummyFileWatchdog:
def __init__(self, path, update_callback):
Expand All @@ -146,7 +155,9 @@ def run(self, consumer):
def terminate(self):
pass

monkeypatch.setattr("robotics_application_manager.manager.manager.LauncherTools", DummyToolsLauncher)
monkeypatch.setattr(
"robotics_application_manager.manager.manager.LauncherTools", DummyToolsLauncher
)
# Deprecated
# monkeypatch.setattr("robotics_application_manager.manager.manager.Server", DummyServer)
# monkeypatch.setattr("robotics_application_manager.manager.manager.FileWatchdog", DummyFileWatchdog)
Expand Down
4 changes: 1 addition & 3 deletions test/test_terminate_transitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,7 @@ def test_terminate_tools_invalid_machine_error(manager, monkeypatch):

Ensure that the transition raises an error when executed from an invalid state.
"""
monkeypatch.setattr(
"robotics_application_manager.libs.server.Server", DummyServer
)
monkeypatch.setattr("robotics_application_manager.libs.server.Server", DummyServer)
# Ensure the manager is in a state where it can stop
setup_manager_to_application_running(manager, monkeypatch)

Expand Down
7 changes: 5 additions & 2 deletions test/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ def run(self, consumer=None):
def terminate(self):
pass

monkeypatch.setattr("robotics_application_manager.manager.manager.LauncherTools", DummyToolsLauncher)
monkeypatch.setattr(
"robotics_application_manager.manager.manager.LauncherTools", DummyToolsLauncher
)

# Trigger visualization ready state
manager.trigger(
Expand Down Expand Up @@ -129,7 +131,8 @@ def fake_open(file, mode="r", *args, **kwargs):
)
monkeypatch.setattr("base64.b64decode", lambda s: b"print('hello')")
monkeypatch.setattr(
"robotics_application_manager.manager.manager.Manager.unpause_sim", lambda self: None
"robotics_application_manager.manager.manager.Manager.unpause_sim",
lambda self: None,
)
# Mock linter to return no errors
manager.linter.evaluate_code = lambda code, ros_version: ""
Expand Down
Loading