55
66import logging
77from pathlib import Path
8- from typing import Dict , Generator , List , Optional
8+ from typing import Generator
99from xml .etree import ElementTree as ET
1010
1111from defusedxml .ElementTree import parse
@@ -23,7 +23,7 @@ def _file_transferred_to(
2323 source : Path ,
2424 file_path : Path ,
2525 rsync_basepath : Path ,
26- ) -> Optional [ Path ] :
26+ ):
2727 """
2828 Returns the Path of the transferred file on the DLS file system.
2929 """
@@ -36,9 +36,7 @@ def _file_transferred_to(
3636 return destination
3737
3838
39- def _get_source (
40- file_path : Path , environment : MurfeyInstanceEnvironment
41- ) -> Optional [Path ]:
39+ def _get_source (file_path : Path , environment : MurfeyInstanceEnvironment ):
4240 """
4341 Returns the Path of the file on the client PC.
4442 """
@@ -48,7 +46,7 @@ def _get_source(
4846 return None
4947
5048
51- def _get_image_elements (root : ET .Element ) -> List [ET .Element ]:
49+ def _get_image_elements (root : ET .Element ) -> list [ET .Element ]:
5250 """
5351 Searches the XML metadata recursively to find the nodes tagged as "Element" that
5452 have image-related tags. Some LIF datasets have layers of nested elements, so a
@@ -93,14 +91,14 @@ def __init__(
9391 self ._basepath = basepath
9492 self ._machine_config = machine_config
9593 # CLEM contexts for "auto-save" acquisition mode
96- self ._tiff_series : Dict [str , List [str ]] = {} # {Series name : TIFF path list}
97- self ._series_metadata : Dict [str , str ] = {} # {Series name : Metadata file path}
98- self ._files_in_series : Dict [str , int ] = {} # {Series name : Total TIFFs}
94+ self ._tiff_series : dict [str , list [str ]] = {} # {Series name : TIFF path list}
95+ self ._series_metadata : dict [str , str ] = {} # {Series name : Metadata file path}
96+ self ._files_in_series : dict [str , int ] = {} # {Series name : Total TIFFs}
9997
10098 def post_transfer (
10199 self ,
102100 transferred_file : Path ,
103- environment : Optional [ MurfeyInstanceEnvironment ] = None ,
101+ environment : MurfeyInstanceEnvironment | None = None ,
104102 ** kwargs ,
105103 ) -> bool :
106104 super ().post_transfer (transferred_file , environment = environment , ** kwargs )
@@ -180,11 +178,6 @@ def post_transfer(
180178 f"File { transferred_file .name !r} added to series { series_name !r} "
181179 )
182180
183- # Register the TIFF file in the database
184- post_result = self .register_tiff_file (destination_file , environment )
185- if post_result is False :
186- return False
187-
188181 # Process XLIF files
189182 if transferred_file .suffix == ".xlif" :
190183 # Skip processing of "_histo" histogram XLIF files
@@ -311,12 +304,6 @@ def post_transfer(
311304 )
312305 return False
313306
314- # Post URL to register LIF file in database
315- post_result = self .register_lif_file (destination_file , environment )
316- if post_result is False :
317- return False
318- logger .info (f"Registered { destination_file .name !r} in the database" )
319-
320307 # Post URL to trigger job and convert LIF file into image stacks
321308 post_result = self .process_lif_file (destination_file , environment )
322309 if post_result is False :
@@ -326,31 +313,6 @@ def post_transfer(
326313 # Function has completed as expected
327314 return True
328315
329- def register_lif_file (
330- self ,
331- lif_file : Path ,
332- environment : MurfeyInstanceEnvironment ,
333- ):
334- """
335- Constructs the URL and dictionary to be posted to the server, which will then
336- register the LIF file in the database correctly as part of the CLEM workflow.
337- """
338- try :
339- capture_post (
340- base_url = str (environment .url .geturl ()),
341- router_name = "clem.router" ,
342- function_name = "register_lif_file" ,
343- token = self ._token ,
344- session_id = environment .murfey_session ,
345- data = {"lif_file" : str (lif_file )},
346- )
347- return True
348- except Exception as e :
349- logger .error (
350- f"Error encountered when registering the LIF file in the database: { e } "
351- )
352- return False
353-
354316 def process_lif_file (
355317 self ,
356318 lif_file : Path ,
@@ -375,32 +337,6 @@ def process_lif_file(
375337 logger .error (f"Error encountered processing LIF file: { e } " )
376338 return False
377339
378- def register_tiff_file (
379- self ,
380- tiff_file : Path ,
381- environment : MurfeyInstanceEnvironment ,
382- ):
383- """
384- Constructs the URL and dictionary to be posted to the server, which will then
385- register the TIFF file in the database correctly as part of the CLEM workflow.
386- """
387-
388- try :
389- capture_post (
390- base_url = str (environment .url .geturl ()),
391- router_name = "clem.router" ,
392- function_name = "register_tiff_file" ,
393- token = self ._token ,
394- session_id = environment .murfey_session ,
395- data = {"tiff_file" : str (tiff_file )},
396- )
397- return True
398- except Exception as e :
399- logger .error (
400- f"Error encountered when registering the TIFF file in the database: { e } "
401- )
402- return False
403-
404340 def process_tiff_series (
405341 self ,
406342 tiff_dataset : dict ,
0 commit comments