|
45 | 45 | ) |
46 | 46 | from werkzeug.utils import secure_filename |
47 | 47 |
|
48 | | -from murfey.client.analyser import Analyser |
49 | 48 | from murfey.client.contexts.spa import SPAModularContext |
50 | 49 | from murfey.client.contexts.tomo import TomographyContext |
| 50 | +from murfey.client.destinations import determine_default_destination |
51 | 51 | from murfey.client.gain_ref import determine_gain_ref |
52 | | -from murfey.client.instance_environment import ( |
53 | | - MurfeyInstanceEnvironment, |
54 | | - global_env_lock, |
55 | | -) |
56 | 52 | from murfey.client.rsync import RSyncer |
57 | 53 | from murfey.util import posix_path |
58 | 54 | from murfey.util.client import ( |
|
72 | 68 | instrument_name = read_config()["Murfey"].get("instrument_name", "") |
73 | 69 |
|
74 | 70 |
|
75 | | -def determine_default_destination( |
76 | | - visit: str, |
77 | | - source: Path, |
78 | | - destination: str, |
79 | | - environment: MurfeyInstanceEnvironment, |
80 | | - analysers: Dict[Path, Analyser], |
81 | | - touch: bool = False, |
82 | | - extra_directory: str = "", |
83 | | - include_mid_path: bool = True, |
84 | | - use_suggested_path: bool = True, |
85 | | -) -> str: |
86 | | - machine_data = capture_get( |
87 | | - base_url=str(environment.url.geturl()), |
88 | | - router_name="session_control.router", |
89 | | - function_name="machine_info_by_instrument", |
90 | | - token=token, |
91 | | - instrument_name=environment.instrument_name, |
92 | | - ).json() |
93 | | - _default = "" |
94 | | - if environment.processing_only_mode and environment.sources: |
95 | | - log.info(f"Processing only mode with sources {environment.sources}") |
96 | | - _default = str(environment.sources[0].absolute()) or str(Path.cwd()) |
97 | | - elif machine_data.get("data_directories"): |
98 | | - for data_dir in machine_data["data_directories"]: |
99 | | - if source.absolute() == Path(data_dir).absolute(): |
100 | | - _default = f"{destination}/{visit}" |
101 | | - break |
102 | | - else: |
103 | | - try: |
104 | | - mid_path = source.absolute().relative_to(Path(data_dir).absolute()) |
105 | | - if use_suggested_path: |
106 | | - with global_env_lock: |
107 | | - source_name = ( |
108 | | - source.name |
109 | | - if source.name != "Images-Disc1" |
110 | | - else source.parent.name |
111 | | - ) |
112 | | - if environment.destination_registry.get(source_name): |
113 | | - _default = environment.destination_registry[source_name] |
114 | | - else: |
115 | | - suggested_path_response = capture_post( |
116 | | - base_url=str(environment.url.geturl()), |
117 | | - router_name="file_io_instrument.router", |
118 | | - function_name="suggest_path", |
119 | | - token=token, |
120 | | - visit_name=visit, |
121 | | - session_id=environment.murfey_session, |
122 | | - data={ |
123 | | - "base_path": f"{destination}/{visit}/{mid_path.parent if include_mid_path else ''}/raw", |
124 | | - "touch": touch, |
125 | | - "extra_directory": extra_directory, |
126 | | - }, |
127 | | - ) |
128 | | - if suggested_path_response is None: |
129 | | - raise RuntimeError("Murfey server is unreachable") |
130 | | - _default = suggested_path_response.json().get( |
131 | | - "suggested_path" |
132 | | - ) |
133 | | - environment.destination_registry[source_name] = _default |
134 | | - else: |
135 | | - _default = f"{destination}/{visit}/{mid_path if include_mid_path else source.name}" |
136 | | - break |
137 | | - except (ValueError, KeyError): |
138 | | - _default = "" |
139 | | - else: |
140 | | - _default = "" |
141 | | - else: |
142 | | - _default = f"{destination}/{visit}" |
143 | | - return ( |
144 | | - _default + f"/{extra_directory}" |
145 | | - if not _default.endswith("/") |
146 | | - else _default + f"{extra_directory}" |
147 | | - ) |
148 | | - |
149 | | - |
150 | 71 | class InputResponse(NamedTuple): |
151 | 72 | question: str |
152 | 73 | allowed_responses: List[str] | None = None |
@@ -349,6 +270,7 @@ def on_button_pressed(self, event: Button.Pressed) -> None: |
349 | 270 | defd, |
350 | 271 | self.app._environment, |
351 | 272 | self.app.analysers, |
| 273 | + token, |
352 | 274 | touch=True, |
353 | 275 | ) |
354 | 276 | visit_path = defd + f"/{text}" |
@@ -1077,6 +999,7 @@ def compose(self): |
1077 | 999 | f"{datetime.now().year}", |
1078 | 1000 | self.app._environment, |
1079 | 1001 | self.app.analysers, |
| 1002 | + token, |
1080 | 1003 | touch=True, |
1081 | 1004 | ) |
1082 | 1005 | if dest and dest in destinations: |
|
0 commit comments