Skip to content

Commit ee4680e

Browse files
committed
Make directories on starting rsyncers
1 parent bc3cb4f commit ee4680e

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

src/murfey/client/multigrid_control.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,12 @@ def _start_rsyncer(
186186
restarted: bool = False,
187187
):
188188
log.info(f"starting rsyncer: {source}")
189+
if transfer:
190+
# Always make sure the destination directory exists
191+
make_directory_url = (
192+
f"{self.murfey_url}/sessions/{self.session_id}/make_rsyncer_destination"
193+
)
194+
capture_post(make_directory_url, json={"destination": destination})
189195
if self._environment:
190196
self._environment.default_destinations[source] = destination
191197
if self._environment.gain_ref and visit_path:

src/murfey/client/tui/app.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,10 @@ def _start_rsyncer(
203203
rsync_url: str = "",
204204
):
205205
log.info(f"starting rsyncer: {source}")
206+
if transfer:
207+
# Always make sure the destination directory exists
208+
make_directory_url = f"{str(self._url.geturl())}/sessions/{str(self._environment.murfey_session)}/make_rsyncer_destination"
209+
capture_post(make_directory_url, json={"destination": destination})
206210
if self._environment:
207211
self._environment.default_destinations[source] = destination
208212
if self._environment.gain_ref and visit_path:

src/murfey/server/api/__init__.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,6 +1297,24 @@ def suggest_path(
12971297
return {"suggested_path": check_path.relative_to(machine_config.rsync_basepath)}
12981298

12991299

1300+
@router.post("/{session_id}/make_rsyncer_destination")
1301+
def make_rsyncer_destination(session_id: int, destination: Path, db=murfey_db):
1302+
secure_path_parts = [secure_filename(p) for p in destination.parts]
1303+
destination_path = "/".join(secure_path_parts)
1304+
instrument_name = (
1305+
db.exec(select(Session).where(Session.id == session_id)).one().instrument_name
1306+
)
1307+
machine_config = get_machine_config(instrument_name=instrument_name)[
1308+
instrument_name
1309+
]
1310+
if not machine_config:
1311+
raise ValueError("No machine configuration set when making rsyncer destination")
1312+
full_destination_path = machine_config.rsync_basepath / destination_path
1313+
for parent_path in full_destination_path.parents:
1314+
parent_path.mkdir(mode=0o750, exist_ok=True)
1315+
return destination
1316+
1317+
13001318
@router.get("/sessions/{session_id}/data_collection_groups")
13011319
def get_dc_groups(
13021320
session_id: MurfeySessionID, db=murfey_db

0 commit comments

Comments
 (0)