From 59ef19b6f3e33740d01cbaf0ea550a87be883799 Mon Sep 17 00:00:00 2001 From: gnthibault Date: Tue, 22 Aug 2023 23:28:14 +0200 Subject: [PATCH] Add support for stop remote driver --- helper/IndiWebManagerClient.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/helper/IndiWebManagerClient.py b/helper/IndiWebManagerClient.py index 3a02906..3bc31ca 100644 --- a/helper/IndiWebManagerClient.py +++ b/helper/IndiWebManagerClient.py @@ -102,16 +102,21 @@ def start_server(self, device_name=None): raise RuntimeError(msg) def stop_server(self, device_name=None): + try: + if self.master_host and self.master_port and device_name: + self.logger.debug( + f"We are also going to stop driver on master server {self.master_host}:{self.master_port}") + self.stop_driver(driver_name=self.build_remote_driver_name(device_name), master=True) + except Exception as e: + msg = f"Cannot stop driver for device {device_name} on master server {self.master_host}:" \ + f"{self.master_port}. But still going to proceed with actual server stop. Error: {e}" + self.logger.error(msg) try: base_url = f"http://{self.host}:{self.port}" req = f"{base_url}/api/server/stop" response = requests.post(req) self.logger.debug(f"stop_server - url {req} - code {response.status_code} - response:{response.text}") assert response.status_code in [200, 500] # It's ok to stop an already stopped server - if self.master_host and self.master_port and device_name: - self.logger.debug( - f"We are also going to stop driver on master server {self.master_host}:{self.master_port}") - self.stop_driver(driver_name=self.build_remote_driver_name(device_name), master=True) except Exception as e: msg = f"Cannot start server: {e}" self.logger.error(msg) @@ -233,7 +238,10 @@ def stop_driver(self, driver_name, master=False): # if driver_name not in ["ZWO CCD"]: #"Shelyak SPOX", "Arduino telescope controller", "ASI EAF", "Altair", "ZWO CCD" # return base_url = f"http://{host}:{port}" - req = f"{base_url}/api/drivers/stop/{urllib.parse.quote(driver_name)}" + if master: + req = f"{base_url}/api/drivers/stop_remote/{urllib.parse.quote(driver_name)}" + else: + req = f"{base_url}/api/drivers/stop/{urllib.parse.quote(driver_name)}" # self.logger.setLevel("DEBUG") # self.logger.warning(f"stop_driver {driver_name} DISABLED for now as it was randomly breaking indiserver") response = requests.post(req)