22
33import logging
44from pathlib import Path
5- from typing import Dict
65
7- from murfey .client .analyser import Analyser
86from murfey .client .instance_environment import (
97 MurfeyInstanceEnvironment ,
108 global_env_lock ,
@@ -19,7 +17,6 @@ def determine_default_destination(
1917 source : Path ,
2018 destination : str ,
2119 environment : MurfeyInstanceEnvironment ,
22- analysers : Dict [Path , Analyser ],
2320 token : str ,
2421 touch : bool = False ,
2522 extra_directory : str = "" ,
@@ -33,57 +30,44 @@ def determine_default_destination(
3330 token = token ,
3431 instrument_name = environment .instrument_name ,
3532 ).json ()
36- _default = ""
37- if environment .processing_only_mode and environment .sources :
38- logger .info (f"Processing only mode with sources { environment .sources } " )
39- _default = str (environment .sources [0 ].absolute ()) or str (Path .cwd ())
40- elif machine_data .get ("data_directories" ):
41- for data_dir in machine_data ["data_directories" ]:
42- if source .absolute () == Path (data_dir ).absolute ():
43- _default = f"{ destination } /{ visit } "
44- break
45- else :
46- try :
47- mid_path = source .absolute ().relative_to (Path (data_dir ).absolute ())
48- if use_suggested_path :
49- with global_env_lock :
50- if source .name == "Images-Disc1" :
51- source_name = source .parent .name
52- elif source .name .startswith ("Sample" ):
53- source_name = f"{ source .parent .name } _{ source .name } "
54- else :
55- source_name = source .name
56- if environment .destination_registry .get (source_name ):
57- _default = environment .destination_registry [source_name ]
58- else :
59- suggested_path_response = capture_post (
60- base_url = str (environment .url .geturl ()),
61- router_name = "file_io_instrument.router" ,
62- function_name = "suggest_path" ,
63- token = token ,
64- visit_name = visit ,
65- session_id = environment .murfey_session ,
66- data = {
67- "base_path" : f"{ destination } /{ visit } /{ mid_path .parent if include_mid_path else '' } /raw" ,
68- "touch" : touch ,
69- "extra_directory" : extra_directory ,
70- },
71- )
72- if suggested_path_response is None :
73- raise RuntimeError ("Murfey server is unreachable" )
74- _default = suggested_path_response .json ().get (
75- "suggested_path"
76- )
77- environment .destination_registry [source_name ] = _default
78- else :
79- _default = f"{ destination } /{ visit } /{ mid_path if include_mid_path else source .name } "
80- break
81- except (ValueError , KeyError ):
82- _default = ""
33+ _default = f"{ destination } /{ visit } "
34+ for data_dir in machine_data .get ("data_directories" , []):
35+ if source .absolute () == Path (data_dir ).absolute ():
36+ _default = f"{ destination } /{ visit } "
37+ break
8338 else :
84- _default = ""
85- else :
86- _default = f"{ destination } /{ visit } "
39+ mid_path = source .absolute ().relative_to (Path (data_dir ).absolute ())
40+ if use_suggested_path :
41+ with global_env_lock :
42+ if source .name == "Images-Disc1" :
43+ source_name = source .parent .name
44+ elif source .name .startswith ("Sample" ):
45+ source_name = f"{ source .parent .name } _{ source .name } "
46+ else :
47+ source_name = source .name
48+ if environment .destination_registry .get (source_name ):
49+ _default = environment .destination_registry [source_name ]
50+ else :
51+ suggested_path_response = capture_post (
52+ base_url = str (environment .url .geturl ()),
53+ router_name = "file_io_instrument.router" ,
54+ function_name = "suggest_path" ,
55+ token = token ,
56+ visit_name = visit ,
57+ session_id = environment .murfey_session ,
58+ data = {
59+ "base_path" : f"{ destination } /{ visit } /{ mid_path .parent if include_mid_path else '' } /raw" ,
60+ "touch" : touch ,
61+ "extra_directory" : extra_directory ,
62+ },
63+ )
64+ if suggested_path_response is None :
65+ raise RuntimeError ("Murfey server is unreachable" )
66+ _default = suggested_path_response .json ().get ("suggested_path" )
67+ environment .destination_registry [source_name ] = _default
68+ else :
69+ _default = f"{ destination } /{ visit } /{ mid_path if include_mid_path else source .name } "
70+ break
8771 return (
8872 _default + f"/{ extra_directory } "
8973 if not _default .endswith ("/" )
0 commit comments