Skip to content

Commit

Permalink
supervisor: revising the dynamic import for the mission module and fi…
Browse files Browse the repository at this point in the history
…xing the recursive download for the file structure
  • Loading branch information
xianglic committed Oct 22, 2024
1 parent 35a03a4 commit a174e91
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions onboard/python/supervisor.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,20 +109,22 @@ 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")
else:
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
Expand All @@ -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'])
Expand Down

0 comments on commit a174e91

Please sign in to comment.