From a174e914b2ef285f0a1f6e181667be2e7b454cce Mon Sep 17 00:00:00 2001 From: xianglic Date: Tue, 22 Oct 2024 18:29:20 +0000 Subject: [PATCH] supervisor: revising the dynamic import for the mission module and fixing the recursive download for the file structure --- onboard/python/supervisor.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/onboard/python/supervisor.py b/onboard/python/supervisor.py index b8b8ba3..2582038 100644 --- a/onboard/python/supervisor.py +++ b/onboard/python/supervisor.py @@ -109,8 +109,9 @@ def start_mission(self): self.stop_mission() # Start new task logger.debug('MS import') + module_prefix = self.drone_id if not self.reload: - module_prefix = self.drone_id + logger.info('first time...') importlib.import_module(f"{module_prefix}.mission") importlib.import_module(f"{module_prefix}.task_defs") importlib.import_module(f"{module_prefix}.transition_defs") @@ -118,11 +119,12 @@ def start_mission(self): logger.info('Reloading...') modules = sys.modules.copy() for module in modules.values(): - if module.__name__.startswith('mission') or module.__name__.startswith('task_defs') or module.__name__.startswith('transition_defs'): + if module.__name__.startswith(f'{module_prefix}.mission') or module.__name__.startswith(f'{module_prefix}.task_defs') or module.__name__.startswith('{module_prefix}.transition_defs'): importlib.reload(module) logger.debug('MC init') - from mission.MissionController import MissionController - self.mission = MissionController(self.drone, self.cloudlet) + #from mission.MissionController import MissionController + Mission = importlib.import_module(f"{module_prefix}.mission.MissionController") + self.mission = getattr(Mission, "MissionController")(self.drone, self.cloudlet) logger.debug('Running flight script!') self.missionTask = asyncio.create_task(self.mission.run()) self.reload = True @@ -145,7 +147,6 @@ def download(self, url: str): f.write(chunk) os.makedirs(self.drone_id, exist_ok=True) z = ZipFile(filename) - os.chdir(self.drone_id) sys.path.append(self.drone_id) try: subprocess.check_call(['rm', '-rf', './task_defs', './mission', './transition_defs'])