Skip to content

Commit cdc9ceb

Browse files
committed
Directly put the rsync module in to the paths used in rsync commands
1 parent 82c7a93 commit cdc9ceb

File tree

6 files changed

+29
-10
lines changed

6 files changed

+29
-10
lines changed

src/murfey/client/multigrid_control.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class MultigridController:
3232
session_id: int
3333
murfey_url: str = "http://localhost:8000"
3434
rsync_url: str = ""
35+
rsync_module: str = "data"
3536
demo: bool = False
3637
processing_enabled: bool = True
3738
do_transfer: bool = True
@@ -59,6 +60,7 @@ def __post_init__(self):
5960
f"{self.murfey_url}/instruments/{self.instrument_name}/machine"
6061
).json()
6162
self.rsync_url = machine_data.get("rsync_url", "")
63+
self.rsync_module = machine_data.get("rsync_module", "data")
6264
self._environment = MurfeyInstanceEnvironment(
6365
url=urlparse(self.murfey_url, allow_fragments=False),
6466
client_id=0,
@@ -200,7 +202,7 @@ def _start_rsyncer(
200202
rsync_cmd = [
201203
"rsync",
202204
f"{posix_path(self._environment.gain_ref)!r}", # '!r' will print strings in ''
203-
f"{self._environment.url.hostname}::{visit_path}/processing",
205+
f"{self._environment.url.hostname}::{self.rsync_module}/{visit_path}/processing",
204206
]
205207
# Wrap in bash shell
206208
cmd = [
@@ -218,6 +220,7 @@ def _start_rsyncer(
218220
self.rsync_processes[source] = RSyncer(
219221
source,
220222
basepath_remote=Path(destination),
223+
rsync_module=self.rsync_module,
221224
server_url=(
222225
urlparse(self.rsync_url)
223226
if self.rsync_url

src/murfey/client/rsync.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def __init__(
5454
self,
5555
basepath_local: Path,
5656
basepath_remote: Path,
57+
rsync_module: str,
5758
server_url: ParseResult,
5859
stop_callback: Callable = lambda *args, **kwargs: None,
5960
local: bool = False,
@@ -66,6 +67,7 @@ def __init__(
6667
super().__init__()
6768
self._basepath = basepath_local.absolute()
6869
self._basepath_remote = basepath_remote
70+
self._rsync_module = rsync_module
6971
self._do_transfer = do_transfer
7072
self._remove_files = remove_files
7173
self._required_substrings_for_removal = required_substrings_for_removal
@@ -76,7 +78,9 @@ def __init__(
7678
if local:
7779
self._remote = str(basepath_remote)
7880
else:
79-
self._remote = f"{server_url.hostname}::{basepath_remote}/"
81+
self._remote = (
82+
f"{server_url.hostname}::{self._rsync_module}/{basepath_remote}/"
83+
)
8084
# For local tests you can use something along the lines of
8185
# self._remote = f"wra62962@ws133:/dls/tmp/wra62962/junk/{basepath_remote}"
8286
# to avoid having to set up an rsync daemon
@@ -116,6 +120,7 @@ def from_rsyncer(cls, rsyncer: RSyncer, **kwargs):
116120
return cls(
117121
rsyncer._basepath,
118122
rsyncer._basepath_remote,
123+
rsyncer._rsync_module,
119124
rsyncer._server_url,
120125
local=kwarguments_from_rsyncer["local"],
121126
status_bar=kwarguments_from_rsyncer["status_bar"],
@@ -190,7 +195,6 @@ def finalise(self, thread: bool = True):
190195

191196
def enqueue(self, file_path: Path):
192197
if not self._stopping:
193-
file_path = Path("/".join(file_path.parts[1:]))
194198
absolute_path = (self._basepath / file_path).resolve()
195199
self.queue.put(absolute_path)
196200

src/murfey/client/tui/app.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ def _start_rsyncer(
214214
rsync_cmd = [
215215
"rsync",
216216
f"{posix_path(self._environment.gain_ref)!r}",
217-
f"{self._url.hostname}::{visit_path}/processing",
217+
f"{self._url.hostname}::{self._machine_config.get('rsync_module', 'data')}/{visit_path}/processing",
218218
]
219219
# Encase in bash shell
220220
cmd = [
@@ -232,6 +232,7 @@ def _start_rsyncer(
232232
self.rsync_processes[source] = RSyncer(
233233
source,
234234
basepath_remote=Path(destination),
235+
rsync_module=self._machine_config.get("rsync_module", "data"),
235236
server_url=urlparse(rsync_url) if rsync_url else self._url,
236237
# local=self._environment.demo,
237238
status_bar=self._statusbar,

src/murfey/client/tui/screens.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,10 @@ def determine_default_destination(
9191
elif machine_data.get("data_directories"):
9292
for data_dir in machine_data["data_directories"]:
9393
if source.resolve() == Path(data_dir):
94-
_default = destination + f"/{visit}"
94+
_default = (
95+
destination
96+
+ f"{machine_data.get('rsync_module') or 'data'}/{visit}"
97+
)
9598
break
9699
else:
97100
try:
@@ -884,7 +887,7 @@ def on_button_pressed(self, event):
884887
rsync_cmd = [
885888
"rsync",
886889
f"{posix_path(self._dir_tree._gain_reference)!r}",
887-
f"{self.app._environment.url.hostname}::{visit_path}/processing/{secure_filename(self._dir_tree._gain_reference.name)}",
890+
f"{self.app._environment.url.hostname}::{self.app._machine_config.get('rsync_module', 'data')}/{visit_path}/processing/{secure_filename(self._dir_tree._gain_reference.name)}",
888891
]
889892
# Encase in bash shell
890893
cmd = ["bash", "-c", " ".join(rsync_cmd)]

src/murfey/instrument_server/api.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,15 +276,23 @@ class GainReference(BaseModel):
276276
gain_destination_dir: str = "processing"
277277

278278

279-
@router.post("/sessions/{session_id}/upload_gain_reference")
280-
def upload_gain_reference(session_id: MurfeySessionID, gain_reference: GainReference):
279+
@router.post(
280+
"/instruments/{instrument_name}/sessions/{session_id}/upload_gain_reference"
281+
)
282+
def upload_gain_reference(
283+
instrument_name: str, session_id: MurfeySessionID, gain_reference: GainReference
284+
):
281285
safe_gain_path = sanitise(str(gain_reference.gain_path))
282286
safe_visit_path = sanitise(gain_reference.visit_path)
283287
safe_destination_dir = sanitise(gain_reference.gain_destination_dir)
288+
machine_config = requests.get(
289+
f"{_get_murfey_url()}/instruments/{instrument_name}/machine",
290+
headers={"Authorization": f"Bearer {tokens[session_id]}"},
291+
).json()
284292
cmd = [
285293
"rsync",
286294
safe_gain_path,
287-
f"{urlparse(_get_murfey_url(), allow_fragments=False).hostname}::{safe_visit_path}/{safe_destination_dir}/{secure_filename(gain_reference.gain_path.name)}",
295+
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)}",
288296
]
289297
gain_rsync = subprocess.run(cmd)
290298
if gain_rsync.returncode:

src/murfey/server/api/instrument.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ async def request_gain_reference_upload(
239239
if machine_config.instrument_server_url:
240240
async with aiohttp.ClientSession() as session:
241241
async with session.post(
242-
f"{machine_config.instrument_server_url}/sessions/{session_id}/upload_gain_reference",
242+
f"{machine_config.instrument_server_url}/instruments/{instrument_name}/sessions/{session_id}/upload_gain_reference",
243243
json={
244244
"gain_path": str(gain_reference_request.gain_path),
245245
"visit_path": visit_path,

0 commit comments

Comments
 (0)