Skip to content

Commit fd89f54

Browse files
committed
Added logic to look for rsync URL before defaulting to Murfey's URL when transferring gain reference
1 parent 3de1b99 commit fd89f54

File tree

1 file changed

+21
-5
lines changed
  • src/murfey/instrument_server

1 file changed

+21
-5
lines changed

src/murfey/instrument_server/api.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from functools import partial
88
from logging import getLogger
99
from pathlib import Path
10-
from typing import Annotated, Dict, List, Optional, Union
10+
from typing import Annotated, Any, Dict, List, Optional, Union
1111
from urllib.parse import urlparse
1212

1313
import requests
@@ -328,19 +328,35 @@ def upload_gain_reference(
328328
safe_gain_path = sanitise(str(gain_reference.gain_path))
329329
safe_visit_path = sanitise(gain_reference.visit_path)
330330
safe_destination_dir = sanitise(gain_reference.gain_destination_dir)
331-
machine_config = requests.get(
331+
332+
# Load machine config and other needed properties
333+
machine_config: dict[str, Any] = requests.get(
332334
f"{_get_murfey_url()}/instruments/{sanitise_nonpath(instrument_name)}/machine",
333335
headers={"Authorization": f"Bearer {tokens[session_id]}"},
334336
).json()
337+
338+
# Return the rsync URL if set, otherwise assume you are syncing via Murfey
339+
rsync_url = urlparse(str(machine_config.get("rsync_url", _get_murfey_url())))
340+
rsync_module = machine_config.get("rsync_module", "data")
341+
rsync_path = f"{rsync_url.hostname}::{rsync_module}/{safe_visit_path}/{safe_destination_dir}/{secure_filename(gain_reference.gain_path.name)}"
342+
343+
# Run rsync subprocess to transfer gain reference
335344
cmd = [
336345
"rsync",
337346
posix_path(Path(safe_gain_path)),
338-
f"{urlparse(_get_murfey_url(), allow_fragments=False).hostname}::{machine_config.get('rsync_module', 'data')}/{safe_visit_path}/{safe_destination_dir}/{secure_filename(gain_reference.gain_path.name)}",
347+
rsync_path,
339348
]
340-
gain_rsync = subprocess.run(cmd)
349+
gain_rsync = subprocess.run(
350+
cmd,
351+
capture_output=True,
352+
text=True,
353+
)
341354
if gain_rsync.returncode:
342355
logger.warning(
343-
f"Gain reference file {safe_gain_path} was not successfully transferred to {safe_visit_path}/processing"
356+
f"Failed to transfer gain reference file {safe_gain_path!r} to {f'{safe_visit_path}/processing'!r} \n"
357+
f"Executed the following command: {' '.join(cmd)!r} \n"
358+
f"Returned the following error: \n"
359+
f"{gain_rsync.stderr}"
344360
)
345361
return {"success": False}
346362
return {"success": True}

0 commit comments

Comments
 (0)