From 4e472a9a6adab51dfaa0597b5f6317a4d5edae80 Mon Sep 17 00:00:00 2001 From: x12sa Date: Tue, 30 Jun 2026 13:08:54 +0200 Subject: [PATCH] fix/get new tomo ID --- .../plugins/omny/omny_general_tools.py | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/csaxs_bec/bec_ipython_client/plugins/omny/omny_general_tools.py b/csaxs_bec/bec_ipython_client/plugins/omny/omny_general_tools.py index 7821f1a..1f9d276 100644 --- a/csaxs_bec/bec_ipython_client/plugins/omny/omny_general_tools.py +++ b/csaxs_bec/bec_ipython_client/plugins/omny/omny_general_tools.py @@ -253,7 +253,7 @@ class TomoIDManager: OMNY_URL = "https://v1p0zyg2w9n2k9c1.myfritz.net/samples/newmeasurement.php" OMNY_USER = "" OMNY_PASSWORD = "" - TMP_FILE = "/tmp/currsamplesnr.txt" + TMP_FILE = "~/currsamplesnr.txt" def register( self, @@ -295,9 +295,22 @@ class TomoIDManager: # shell=True, # ) #print(url) - subprocess.run( - f"wget -q -O {self.TMP_FILE} '{url}'", + tmp_file = os.path.expanduser(self.TMP_FILE) + result = subprocess.run( + f"wget -q -O {tmp_file} '{url}'", shell=True, ) - with open(self.TMP_FILE) as f: - return int(f.read()) \ No newline at end of file + if result.returncode != 0: + raise OMNYToolsError( + f"wget failed (exit code {result.returncode}) fetching tomo ID from {self.OMNY_URL}" + ) + try: + with open(tmp_file) as f: + content = f.read().strip() + return int(content) + except FileNotFoundError as exc: + raise OMNYToolsError(f"wget did not produce output file {tmp_file}") from exc + except ValueError as exc: + raise OMNYToolsError( + f"Unexpected response from tomo ID server, got: {content!r}" + ) from exc