Skip to content

Commit 71eba84

Browse files
committed
Corrected and standardised all occurrences of rsync subprocesses in murfey/client/*
1 parent 4464faa commit 71eba84

File tree

4 files changed

+53
-32
lines changed

4 files changed

+53
-32
lines changed

src/murfey/client/multigrid_control.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import json
22
import logging
3+
import subprocess
34
import threading
45
from dataclasses import dataclass, field
56
from datetime import datetime
@@ -8,10 +9,10 @@
89
from typing import Dict, List, Optional
910
from urllib.parse import urlparse
1011

11-
import procrunner
1212
import requests
1313

1414
import murfey.client.websocket
15+
from murfey.client import posix_path
1516
from murfey.client.analyser import Analyser
1617
from murfey.client.contexts.spa import SPAContext, SPAModularContext
1718
from murfey.client.contexts.tomo import TomographyContext
@@ -178,16 +179,23 @@ def _start_rsyncer(
178179
if self._environment:
179180
self._environment.default_destinations[source] = destination
180181
if self._environment.gain_ref and visit_path:
181-
gain_rsync = procrunner.run(
182-
[
183-
"rsync",
184-
str(self._environment.gain_ref),
185-
f"{self._environment.url.hostname}::{visit_path}/processing",
186-
]
187-
)
182+
# Set up rsync command
183+
rsync_cmd = [
184+
"rsync",
185+
f"{posix_path(self._environment.gain_ref)!r}", # '!r' will print strings in ''
186+
f"{self._environment.url.hostname}::{visit_path}/processing",
187+
]
188+
# Wrap in bash shell
189+
cmd = [
190+
"bash",
191+
"-c",
192+
" ".join(rsync_cmd),
193+
]
194+
# Run rsync subprocess
195+
gain_rsync = subprocess.run(cmd)
188196
if gain_rsync.returncode:
189197
log.warning(
190-
f"Gain reference file {self._environment.gain_ref} was not successfully transferred to {visit_path}/processing"
198+
f"Gain reference file {posix_path(self._environment.gain_ref)!r} was not successfully transferred to {visit_path}/processing"
191199
)
192200
self.rsync_processes[source] = RSyncer(
193201
source,

src/murfey/client/rsync.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -440,46 +440,46 @@ def parse_stderr(line: str):
440440
success = True
441441
if rsync_stdin:
442442
# Wrap rsync command in a bash command
443-
bash_cmd = [
443+
cmd = [
444444
"bash",
445445
"-c",
446446
# rsync command passed in as a single string
447447
" ".join(rsync_cmd),
448448
]
449449
result = subprocess.run(
450-
bash_cmd,
450+
cmd,
451451
cwd=self._basepath, # As-is Path is fine
452452
capture_output=True,
453453
input=rsync_stdin,
454454
)
455455
# Parse outputs
456-
for line in result.stdout.decode("utf8", "replace").split("\n"):
456+
for line in result.stdout.decode("utf-8", "replace").split("\n"):
457457
parse_stdout(line)
458-
for line in result.stderr.decode("utf8", "replace").split("\n"):
458+
for line in result.stderr.decode("utf-8", "replace").split("\n"):
459459
parse_stderr(line)
460460
success = result.returncode == 0
461461

462462
# Remove files from source
463463
if rsync_stdin_remove:
464-
# Insert flag file removal flag before locations
464+
# Insert file removal flag before locations
465465
rsync_cmd.insert(-2, "--remove-source-files")
466466
# Wrap rsync command in a bash command
467-
bash_cmd = [
467+
cmd = [
468468
"bash",
469469
"-c",
470470
# Pass rsync command as single string
471471
" ".join(rsync_cmd),
472472
]
473473
result = subprocess.run(
474-
bash_cmd,
474+
cmd,
475475
cwd=self._basepath,
476476
capture_output=True,
477477
input=rsync_stdin_remove,
478478
)
479479
# Parse outputs
480-
for line in result.stdout.decode("utf8", "replace").split("\n"):
480+
for line in result.stdout.decode("utf-8", "replace").split("\n"):
481481
parse_stdout(line)
482-
for line in result.stderr.decode("utf8", "replace").split("\n"):
482+
for line in result.stderr.decode("utf-8", "replace").split("\n"):
483483
parse_stderr(line)
484484
# Leave it as a failure if the previous rsync subprocess failed
485485
if success:

src/murfey/client/tui/app.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
from __future__ import annotations
22

33
import logging
4+
import subprocess
45
from datetime import datetime
56
from functools import partial
67
from pathlib import Path
78
from queue import Queue
89
from typing import Awaitable, Callable, Dict, List, OrderedDict, TypeVar
910
from urllib.parse import urlparse
1011

11-
import procrunner
1212
import requests
1313
from textual.app import App
1414
from textual.reactive import reactive
1515
from textual.widgets import Button, Input
1616

17+
from murfey.client import posix_path
1718
from murfey.client.analyser import Analyser
1819
from murfey.client.contexts.spa import SPAContext, SPAModularContext
1920
from murfey.client.contexts.tomo import TomographyContext
@@ -203,16 +204,23 @@ def _start_rsyncer(
203204
if self._environment:
204205
self._environment.default_destinations[source] = destination
205206
if self._environment.gain_ref and visit_path:
206-
gain_rsync = procrunner.run(
207-
[
208-
"rsync",
209-
str(self._environment.gain_ref),
210-
f"{self._url.hostname}::{visit_path}/processing",
211-
]
212-
)
207+
# Set up rsync command
208+
rsync_cmd = [
209+
"rsync",
210+
f"{posix_path(self._environment.gain_ref)!r}",
211+
f"{self._url.hostname}::{visit_path}/processing",
212+
]
213+
# Encase in bash shell
214+
cmd = [
215+
"bash",
216+
"-c",
217+
" ".join(rsync_cmd),
218+
]
219+
# Run rsync subprocess
220+
gain_rsync = subprocess.run(cmd)
213221
if gain_rsync.returncode:
214222
log.warning(
215-
f"Gain reference file {self._environment.gain_ref} was not successfully transferred to {visit_path}/processing"
223+
f"Gain reference file {posix_path(self._environment.gain_ref)!r} was not successfully transferred to {visit_path}/processing"
216224
)
217225
self.rsync_processes[source] = RSyncer(
218226
source,

src/murfey/client/tui/screens.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
# import contextlib
44
import logging
5+
import subprocess
56
from datetime import datetime
67
from functools import partial
78
from pathlib import Path
@@ -17,7 +18,6 @@
1718
TypeVar,
1819
)
1920

20-
import procrunner
2121
import requests
2222
from pydantic import BaseModel, ValidationError
2323
from rich.box import SQUARE
@@ -46,6 +46,7 @@
4646
)
4747
from werkzeug.utils import secure_filename
4848

49+
from murfey.client import posix_path
4950
from murfey.client.analyser import Analyser, spa_form_dependencies
5051
from murfey.client.contexts.spa import SPAContext, SPAModularContext
5152
from murfey.client.contexts.tomo import TomographyContext
@@ -838,18 +839,22 @@ def on_button_pressed(self, event):
838839
if event.button.id == "suggested-gain-ref":
839840
self._dir_tree._gain_reference = self._gain_reference
840841
visit_path = f"data/{datetime.now().year}/{self.app._environment.visit}"
841-
cmd = [
842+
# Set up rsync command
843+
rsync_cmd = [
842844
"rsync",
843-
str(self._dir_tree._gain_reference),
845+
f"{posix_path(self._dir_tree._gain_reference)!r}",
844846
f"{self.app._environment.url.hostname}::{visit_path}/processing/{secure_filename(self._dir_tree._gain_reference.name)}",
845847
]
848+
# Encase in bash shell
849+
cmd = ["bash", "-c" " ".join(rsync_cmd)]
846850
if self.app._environment.demo:
847851
log.info(f"Would perform {' '.join(cmd)}")
848852
else:
849-
gain_rsync = procrunner.run(cmd)
853+
# Run rsync subprocess
854+
gain_rsync = subprocess.run(cmd)
850855
if gain_rsync.returncode:
851856
log.warning(
852-
f"Gain reference file {self._dir_tree._gain_reference} was not successfully transferred to {visit_path}/processing"
857+
f"Gain reference file {posix_path(self._dir_tree._gain_reference)!r} was not successfully transferred to {visit_path}/processing"
853858
)
854859
process_gain_response = requests.post(
855860
url=f"{str(self.app._environment.url.geturl())}/sessions/{self.app._environment.murfey_session}/process_gain",

0 commit comments

Comments
 (0)