55from pathlib import Path
66from typing import Any , Dict , List , Optional , OrderedDict , Tuple
77
8- import requests
98import xmltodict
109
1110from murfey .client .context import Context , ProcessingParameter
1413 MurfeyID ,
1514 MurfeyInstanceEnvironment ,
1615)
17- from murfey .util .api import url_path_for
18- from murfey .util .client import (
19- authorised_requests ,
20- capture_get ,
21- capture_post ,
22- get_machine_config_client ,
23- )
16+ from murfey .util .client import capture_get , capture_post , get_machine_config_client
2417from murfey .util .spa_metadata import (
2518 foil_hole_data ,
2619 foil_hole_from_file ,
3124
3225logger = logging .getLogger ("murfey.client.contexts.spa" )
3326
34- requests .get , requests .post , requests .put , requests .delete = authorised_requests ()
35-
3627
3728def _file_transferred_to (
3829 environment : MurfeyInstanceEnvironment , source : Path , file_path : Path
@@ -235,7 +226,10 @@ def gather_metadata(
235226 binning_factor = 1
236227 if environment :
237228 server_config_response = capture_get (
238- f"{ str (environment .url .geturl ())} { url_path_for ('session_control.router' , 'machine_info_by_instrument' , instrument_name = environment .instrument_name )} "
229+ base_url = str (environment .url .geturl ()),
230+ router_name = "session_control.router" ,
231+ function_name = "machine_info_by_instrument" ,
232+ instrument_name = environment .instrument_name ,
239233 )
240234 if server_config_response is None :
241235 return None
@@ -304,8 +298,11 @@ def _position_analysis(
304298 Optional [float ],
305299 ] = (None , None , None , None , None , None , None )
306300 data_collection_group = (
307- requests .get (
308- f"{ environment .url .geturl ()} { url_path_for ('session_info.router' , 'get_dc_groups' , session_id = environment .murfey_session )} "
301+ capture_get (
302+ base_url = str (environment .url .geturl ()),
303+ router_name = "session_info.router" ,
304+ function_name = "get_dc_groups" ,
305+ session_id = environment .murfey_session ,
309306 )
310307 .json ()
311308 .get (str (source ), {})
@@ -327,7 +324,6 @@ def _position_analysis(
327324 local_atlas_path ,
328325 grid_square = str (grid_square ),
329326 )[str (grid_square )]
330- gs_url = f"{ str (environment .url .geturl ())} { url_path_for ('session_control.spa_router' , 'register_grid_square' , session_id = environment .murfey_session , gsid = grid_square )} "
331327 gs = grid_square_data (
332328 grid_square_metadata_file ,
333329 grid_square ,
@@ -348,8 +344,12 @@ def _position_analysis(
348344 else ""
349345 )
350346 capture_post (
351- gs_url ,
352- json = {
347+ base_url = str (environment .url .geturl ()),
348+ router_name = "session_control.spa_router" ,
349+ function_name = "register_grid_square" ,
350+ session_id = environment .murfey_session ,
351+ gsid = grid_square ,
352+ data = {
353353 "tag" : str (source ),
354354 "readout_area_x" : gs .readout_area_x ,
355355 "readout_area_y" : gs .readout_area_y ,
@@ -368,7 +368,6 @@ def _position_analysis(
368368 )
369369 foil_hole = foil_hole_from_file (transferred_file )
370370 if foil_hole not in self ._foil_holes [grid_square ]:
371- fh_url = f"{ str (environment .url .geturl ())} { url_path_for ('session_control.spa_router' , 'register_foil_hole' , session_id = environment .murfey_session , gs_name = grid_square )} "
372371 if environment .murfey_session is not None :
373372 fh = foil_hole_data (
374373 grid_square_metadata_file ,
@@ -391,8 +390,12 @@ def _position_analysis(
391390 else ""
392391 )
393392 capture_post (
394- fh_url ,
395- json = {
393+ base_url = str (environment .url .geturl ()),
394+ router_name = "session_control.spa_router" ,
395+ function_name = "register_foil_hole" ,
396+ session_id = environment .murfey_session ,
397+ gs_name = grid_square ,
398+ data = {
396399 "name" : foil_hole ,
397400 "x_location" : fh .x_location ,
398401 "y_location" : fh .y_location ,
@@ -410,8 +413,12 @@ def _position_analysis(
410413 )
411414 else :
412415 capture_post (
413- fh_url ,
414- json = {
416+ base_url = str (environment .url .geturl ()),
417+ router_name = "session_control.spa_router" ,
418+ function_name = "register_foil_hole" ,
419+ session_id = environment .murfey_session ,
420+ gs_name = grid_square ,
421+ data = {
415422 "name" : foil_hole ,
416423 "tag" : str (source ),
417424 },
@@ -467,7 +474,9 @@ def post_transfer(
467474 )
468475 if not environment .movie_counters .get (str (source )):
469476 movie_counts_get = capture_get (
470- f"{ environment .url .geturl ()} { url_path_for ('session_control.router' , 'count_number_of_movies' )} " ,
477+ base_url = str (environment .url .geturl ()),
478+ router_name = "session_control.router" ,
479+ function_name = "count_number_of_movies" ,
471480 )
472481 if movie_counts_get is not None :
473482 environment .movie_counters [str (source )] = count (
@@ -481,8 +490,12 @@ def post_transfer(
481490 eer_fractionation_file = None
482491 if file_transferred_to .suffix == ".eer" :
483492 response = capture_post (
484- f"{ str (environment .url .geturl ())} { url_path_for ('file_io_instrument.router' , 'write_eer_fractionation_file' , visit_name = environment .visit , session_id = environment .murfey_session )} " ,
485- json = {
493+ base_url = str (environment .url .geturl ()),
494+ router_name = "file_io_instrument.router" ,
495+ function_name = "write_eer_fractionation_file" ,
496+ visit_name = environment .visit ,
497+ session_id = environment .murfey_session ,
498+ data = {
486499 "eer_path" : str (file_transferred_to ),
487500 "fractionation" : self .data_collection_parameters [
488501 "eer_fractionation"
@@ -511,7 +524,6 @@ def post_transfer(
511524 )
512525 foil_hole = None
513526
514- preproc_url = f"{ str (environment .url .geturl ())} { url_path_for ('workflow.spa_router' , 'request_spa_preprocessing' , visit_name = environment .visit , session_id = environment .murfey_session )} "
515527 preproc_data = {
516528 "path" : str (file_transferred_to ),
517529 "description" : "" ,
@@ -537,8 +549,12 @@ def post_transfer(
537549 "foil_hole_id" : foil_hole ,
538550 }
539551 capture_post (
540- preproc_url ,
541- json = {
552+ base_url = str (environment .url .geturl ()),
553+ router_name = "workflow.spa_router" ,
554+ function_name = "request_spa_preprocessing" ,
555+ visit_name = environment .visit ,
556+ session_id = environment .murfey_session ,
557+ data = {
542558 k : None if v == "None" else v
543559 for k , v in preproc_data .items ()
544560 },
0 commit comments