Skip to content

Commit 6b07927

Browse files
committed
If MachineConfig.rsync_basepath or MachineConfig.default_model is None, default to 'Path().resolve()'
1 parent d19a40f commit 6b07927

File tree

8 files changed

+42
-27
lines changed

8 files changed

+42
-27
lines changed

src/murfey/server/api/clem.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def validate_and_sanitise(
8383
machine_config = get_machine_config(instrument_name=instrument_name)[
8484
instrument_name
8585
]
86-
rsync_basepath = machine_config.rsync_basepath.resolve()
86+
rsync_basepath = (machine_config.rsync_basepath or Path("")).resolve()
8787

8888
# Check that full file path doesn't contain unallowed characters
8989
# Currently allows only:

src/murfey/server/api/file_io_frontend.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,11 @@ async def create_symlink(
5050
machine_config = get_machine_config(instrument_name=instrument_name)[
5151
instrument_name
5252
]
53-
symlink_full_path = machine_config.rsync_basepath / symlink_params.symlink
53+
rsync_basepath = (machine_config.rsync_basepath or Path("")).resolve()
54+
symlink_full_path = rsync_basepath / symlink_params.symlink
5455
if symlink_full_path.is_symlink() and symlink_params.override:
5556
symlink_full_path.unlink()
5657
if symlink_full_path.exists():
5758
return ""
58-
symlink_full_path.symlink_to(machine_config.rsync_basepath / symlink_params.target)
59+
symlink_full_path.symlink_to(rsync_basepath / symlink_params.target)
5960
return str(symlink_params.symlink)

src/murfey/server/api/file_io_instrument.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ def suggest_path(
5757
)
5858

5959
# Construct the full path to where the dataset is to be saved
60-
check_path = machine_config.rsync_basepath / base_path
60+
rsync_basepath = (machine_config.rsync_basepath or Path("")).resolve()
61+
check_path = rsync_basepath / base_path
6162

6263
# Check previous year to account for the year rolling over during data collection
6364
if not check_path.parent.exists():
@@ -69,7 +70,7 @@ def suggest_path(
6970
base_path_parts[year_idx] = str(int(part) - 1)
7071
base_path = "/".join(base_path_parts)
7172
check_path_prev = check_path
72-
check_path = machine_config.rsync_basepath / base_path
73+
check_path = rsync_basepath / base_path
7374

7475
# If it's not in the previous year either, it's a genuine error
7576
if not check_path.parent.exists():
@@ -88,7 +89,7 @@ def suggest_path(
8889
check_path.mkdir(mode=0o750)
8990
if params.extra_directory:
9091
(check_path / secure_filename(params.extra_directory)).mkdir(mode=0o750)
91-
return {"suggested_path": check_path.relative_to(machine_config.rsync_basepath)}
92+
return {"suggested_path": check_path.relative_to(rsync_basepath)}
9293

9394

9495
class Dest(BaseModel):
@@ -107,7 +108,9 @@ def make_rsyncer_destination(session_id: int, destination: Dest, db=murfey_db):
107108
]
108109
if not machine_config:
109110
raise ValueError("No machine configuration set when making rsyncer destination")
110-
full_destination_path = machine_config.rsync_basepath / destination_path
111+
full_destination_path = (
112+
machine_config.rsync_basepath or Path("")
113+
).resolve() / destination_path
111114
for parent_path in full_destination_path.parents:
112115
parent_path.mkdir(mode=0o750, exist_ok=True)
113116
return destination
@@ -151,7 +154,7 @@ async def write_eer_fractionation_file(
151154
) / secure_filename(fractionation_params.fractionation_file_name)
152155
else:
153156
file_path = (
154-
Path(machine_config.rsync_basepath)
157+
(machine_config.rsync_basepath or Path("")).resolve()
155158
/ str(datetime.now().year)
156159
/ secure_filename(visit_name)
157160
/ machine_config.gain_directory_name

src/murfey/server/api/file_io_shared.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ async def process_gain(
3737
executables = machine_config.external_executables
3838
env = machine_config.external_environment
3939
safe_path_name = secure_filename(gain_reference_params.gain_ref.name)
40+
rsync_basepath = machine_config.rsync_basepath or Path("")
4041
filepath = (
41-
Path(machine_config.rsync_basepath)
42+
rsync_basepath
4243
/ str(datetime.now().year)
4344
/ secure_filename(visit_name)
4445
/ machine_config.gain_directory_name
@@ -48,7 +49,7 @@ async def process_gain(
4849
if not filepath.exists():
4950
filepath_prev = filepath
5051
filepath = (
51-
Path(machine_config.rsync_basepath)
52+
rsync_basepath
5253
/ str(datetime.now().year - 1)
5354
/ secure_filename(visit_name)
5455
/ machine_config.gain_directory_name
@@ -80,14 +81,12 @@ async def process_gain(
8081
)
8182
if new_gain_ref and new_gain_ref_superres:
8283
return {
83-
"gain_ref": new_gain_ref.relative_to(Path(machine_config.rsync_basepath)),
84-
"gain_ref_superres": new_gain_ref_superres.relative_to(
85-
Path(machine_config.rsync_basepath)
86-
),
84+
"gain_ref": new_gain_ref.relative_to(rsync_basepath),
85+
"gain_ref_superres": new_gain_ref_superres.relative_to(rsync_basepath),
8786
}
8887
elif new_gain_ref:
8988
return {
90-
"gain_ref": new_gain_ref.relative_to(Path(machine_config.rsync_basepath)),
89+
"gain_ref": new_gain_ref.relative_to(rsync_basepath),
9190
"gain_ref_superres": None,
9291
}
9392
else:

src/murfey/server/api/workflow.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -214,15 +214,14 @@ def start_dc(
214214
machine_config = get_machine_config(instrument_name=instrument_name)[
215215
instrument_name
216216
]
217+
rsync_basepath = (machine_config.rsync_basepath or Path("")).resolve()
217218
logger.info(
218219
f"Starting data collection on microscope {instrument_name!r} "
219-
f"with basepath {sanitise(str(machine_config.rsync_basepath))} and directory {sanitise(dc_params.image_directory)}"
220+
f"with basepath {sanitise(str(rsync_basepath))} and directory {sanitise(dc_params.image_directory)}"
220221
)
221222
dc_parameters = {
222223
"visit": visit_name,
223-
"image_directory": str(
224-
machine_config.rsync_basepath / dc_params.image_directory
225-
),
224+
"image_directory": str(rsync_basepath / dc_params.image_directory),
226225
"start_time": str(datetime.now()),
227226
"voltage": dc_params.voltage,
228227
"pixel_size": str(float(dc_params.pixel_size_on_image) * 1e9),
@@ -713,7 +712,10 @@ async def request_tomography_preprocessing(
713712
"fm_dose": proc_file.dose_per_frame,
714713
"frame_count": proc_file.frame_count,
715714
"gain_ref": (
716-
str(machine_config.rsync_basepath / proc_file.gain_ref)
715+
str(
716+
(machine_config.rsync_basepath or Path("")).resolve()
717+
/ proc_file.gain_ref
718+
)
717719
if proc_file.gain_ref and machine_config.data_transfer_enabled
718720
else proc_file.gain_ref
719721
),
@@ -1029,7 +1031,7 @@ async def make_gif(
10291031
instrument_name
10301032
]
10311033
output_dir = (
1032-
Path(machine_config.rsync_basepath)
1034+
(machine_config.rsync_basepath or Path("")).resolve()
10331035
/ secure_filename(year)
10341036
/ secure_filename(visit_name)
10351037
/ "processed"

src/murfey/server/feedback.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,7 +1100,9 @@ def _register_class_selection(message: dict, _db, demo: bool = False):
11001100
def _find_initial_model(visit: str, machine_config: MachineConfig) -> Path | None:
11011101
if machine_config.initial_model_search_directory:
11021102
visit_directory = (
1103-
machine_config.rsync_basepath / str(datetime.now().year) / visit
1103+
(machine_config.rsync_basepath or Path("")).resolve()
1104+
/ str(datetime.now().year)
1105+
/ visit
11041106
)
11051107
possible_models = [
11061108
p
@@ -1512,7 +1514,10 @@ def _flush_tomography_preprocessing(message: dict, _db):
15121514
"fm_dose": proc_params.dose_per_frame,
15131515
"frame_count": proc_params.frame_count,
15141516
"gain_ref": (
1515-
str(machine_config.rsync_basepath / proc_params.gain_ref)
1517+
str(
1518+
(machine_config.rsync_basepath or Path("")).resolve()
1519+
/ proc_params.gain_ref
1520+
)
15161521
if proc_params.gain_ref
15171522
else proc_params.gain_ref
15181523
),
@@ -2042,7 +2047,10 @@ def feedback_callback(header: dict, message: dict, _db=murfey_db) -> None:
20422047
angpix=float(message["pixel_size_on_image"]) * 1e10,
20432048
dose_per_frame=message["dose_per_frame"],
20442049
gain_ref=(
2045-
str(machine_config.rsync_basepath / message["gain_ref"])
2050+
str(
2051+
(machine_config.rsync_basepath or Path("")).resolve()
2052+
/ message["gain_ref"]
2053+
)
20462054
if message["gain_ref"] and machine_config.data_transfer_enabled
20472055
else message["gain_ref"]
20482056
),

src/murfey/util/processing_params.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ def cryolo_model_path(visit: str, instrument_name: str) -> Path:
4242
]
4343
if machine_config.picking_model_search_directory:
4444
visit_directory = (
45-
machine_config.rsync_basepath / str(datetime.now().year) / visit
45+
(machine_config.rsync_basepath or Path("")).resolve()
46+
/ str(datetime.now().year)
47+
/ visit
4648
)
4749
possible_models = list(
4850
(visit_directory / machine_config.picking_model_search_directory).glob(
@@ -51,7 +53,7 @@ def cryolo_model_path(visit: str, instrument_name: str) -> Path:
5153
)
5254
if possible_models:
5355
return sorted(possible_models, key=lambda x: x.stat().st_ctime)[-1]
54-
return machine_config.default_model
56+
return (machine_config.default_model or Path("")).resolve()
5557

5658

5759
class CLEMProcessingParameters(BaseModel):

src/murfey/workflows/clem/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def _validate_and_sanitise(
6464
machine_config = get_machine_config(instrument_name=instrument_name)[
6565
instrument_name
6666
]
67-
rsync_basepath = machine_config.rsync_basepath.resolve()
67+
rsync_basepath = (machine_config.rsync_basepath or Path("")).resolve()
6868

6969
# Check that full file path doesn't contain unallowed characters
7070
# Currently allows only:

0 commit comments

Comments
 (0)