Skip to content

Commit 2a9f533

Browse files
authored
Fixes for MSys2 style paths (#518)
1 parent c8f62ce commit 2a9f533

File tree

6 files changed

+62
-28
lines changed

6 files changed

+62
-28
lines changed

src/murfey/client/contexts/spa.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -431,12 +431,15 @@ def _position_analysis(
431431
grid_square_metadata_file,
432432
grid_square,
433433
)
434+
metadata_source_as_str = (
435+
"/".join(source.parts[:-2])
436+
+ f"/{environment.visit}/"
437+
+ source.parts[-2]
438+
)
434439
metadata_source = Path(
435-
(
436-
"/".join(source.parts[:-2])
437-
+ f"/{environment.visit}/"
438-
+ source.parts[-2]
439-
)[1:]
440+
metadata_source_as_str[1:]
441+
if metadata_source_as_str.startswith("//")
442+
else metadata_source_as_str
440443
)
441444
image_path = (
442445
_file_transferred_to(environment, metadata_source, Path(gs.image))
@@ -471,12 +474,15 @@ def _position_analysis(
471474
foil_hole,
472475
grid_square,
473476
)
477+
metadata_source_as_str = (
478+
"/".join(source.parts[:-2])
479+
+ f"/{environment.visit}/"
480+
+ source.parts[-2]
481+
)
474482
metadata_source = Path(
475-
(
476-
"/".join(source.parts[:-2])
477-
+ f"/{environment.visit}/"
478-
+ source.parts[-2]
479-
)[1:]
483+
metadata_source_as_str[1:]
484+
if metadata_source_as_str.startswith("//")
485+
else metadata_source_as_str
480486
)
481487
image_path = (
482488
_file_transferred_to(environment, metadata_source, Path(fh.image))

src/murfey/client/contexts/spa_metadata.py

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def _foil_hole_positions(xml_path: Path, grid_square: int) -> Dict[str, FoilHole
4444
required_key = key
4545
break
4646
if not required_key:
47-
logger.warning(f"Required key not found for {str(xml_path)}")
47+
logger.info(f"Required key not found for {str(xml_path)}")
4848
return {}
4949
foil_holes = {}
5050
for fh_block in serialization_array[required_key]:
@@ -163,10 +163,13 @@ def post_transfer(
163163
atlas=Path(partial_path), sample=sample
164164
)
165165
url = f"{str(environment.url.geturl())}/visits/{environment.visit}/{environment.murfey_session}/register_data_collection_group"
166-
dcg_search_dir = "/" + "/".join(
167-
p
168-
for p in transferred_file.parent.parts[1:]
169-
if p != environment.visit
166+
dcg_search_dir = "/".join(
167+
p for p in transferred_file.parent.parts if p != environment.visit
168+
)
169+
dcg_search_dir = (
170+
dcg_search_dir[1:]
171+
if dcg_search_dir.startswith("//")
172+
else dcg_search_dir
170173
)
171174
dcg_images_dirs = sorted(
172175
Path(dcg_search_dir).glob("Images-Disc*"),
@@ -215,11 +218,16 @@ def post_transfer(
215218
):
216219
# Make sure we have a data collection group before trying to register grid square
217220
url = f"{str(environment.url.geturl())}/visits/{environment.visit}/{environment.murfey_session}/register_data_collection_group"
218-
dcg_search_dir = "/" + "/".join(
221+
dcg_search_dir = "/".join(
219222
p
220-
for p in transferred_file.parent.parent.parts[1:]
223+
for p in transferred_file.parent.parent.parts
221224
if p != environment.visit
222225
)
226+
dcg_search_dir = (
227+
dcg_search_dir[1:]
228+
if dcg_search_dir.startswith("//")
229+
else dcg_search_dir
230+
)
223231
dcg_images_dirs = sorted(
224232
Path(dcg_search_dir).glob("Images-Disc*"),
225233
key=lambda x: x.stat().st_ctime,
@@ -241,6 +249,8 @@ def post_transfer(
241249
)
242250
fh_positions = _foil_hole_positions(transferred_file, int(gs_name))
243251
source = _get_source(transferred_file, environment=environment)
252+
if source is None:
253+
return None
244254
visitless_source_search_dir = str(source).replace(
245255
f"/{environment.visit}", ""
246256
)
@@ -261,12 +271,15 @@ def post_transfer(
261271
transferred_file,
262272
int(gs_name),
263273
)
274+
metadata_source_as_str = (
275+
"/".join(source.parts[:-2])
276+
+ f"/{environment.visit}/"
277+
+ source.parts[-2]
278+
)
264279
metadata_source = Path(
265-
(
266-
"/".join(Path(visitless_source).parts[:-2])
267-
+ f"/{environment.visit}/"
268-
+ Path(visitless_source).parts[-2]
269-
)[1:]
280+
metadata_source_as_str[1:]
281+
if metadata_source_as_str.startswith("//")
282+
else metadata_source_as_str
270283
)
271284
image_path = (
272285
_file_transferred_to(

src/murfey/client/multigrid_control.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def _start_rsyncer_multigrid(
143143
source,
144144
destination,
145145
force_metadata=self.processing_enabled,
146-
analyse=not extra_directory and use_suggested_path and analyse,
146+
analyse=analyse,
147147
remove_files=remove_files,
148148
tag=tag,
149149
limited=limited,

src/murfey/instrument_server/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
from rich.logging import RichHandler
66

77
import murfey
8+
from murfey.client import read_config
9+
from murfey.client.customlogging import CustomHandler
810
from murfey.util import LogFilter
911

1012
logger = logging.getLogger("murfey.instrument_server")
@@ -33,6 +35,14 @@ def run():
3335
logging.getLogger("fastapi").addHandler(rich_handler)
3436
logging.getLogger("uvicorn").addHandler(rich_handler)
3537

38+
ws = murfey.client.websocket.WSApp(
39+
server=read_config()["Murfey"].get("server"),
40+
id=0,
41+
)
42+
43+
handler = CustomHandler(ws.send)
44+
logging.getLogger().addHandler(handler)
45+
3646
logger.info(
3747
f"Starting Murfey server version {murfey.__version__}, listening on {args.host}:{args.port}"
3848
)

src/murfey/instrument_server/api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from murfey.client.multigrid_control import MultigridController
2222
from murfey.client.rsync import RSyncer
2323
from murfey.client.watchdir_multigrid import MultigridDirWatcher
24-
from murfey.util import sanitise, sanitise_nonpath, secure_path
24+
from murfey.util import posix_path, sanitise, sanitise_nonpath, secure_path
2525
from murfey.util.instrument_models import MultigridWatcherSpec
2626
from murfey.util.models import File, Token
2727

@@ -291,7 +291,7 @@ def upload_gain_reference(
291291
).json()
292292
cmd = [
293293
"rsync",
294-
safe_gain_path,
294+
posix_path(Path(safe_gain_path)),
295295
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)}",
296296
]
297297
gain_rsync = subprocess.run(cmd)

src/murfey/util/__init__.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,14 @@ def sanitise_nonpath(in_string: str) -> str:
7474

7575
def secure_path(in_path: Path, keep_spaces: bool = False) -> Path:
7676
if keep_spaces:
77-
secured_parts = [
78-
secure_filename(p) if " " not in p else p for p in in_path.parts
79-
]
77+
secured_parts = []
78+
for p, part in enumerate(in_path.parts):
79+
if " " in part:
80+
secured_parts.append(part)
81+
elif ":" in part and not p:
82+
secured_parts.append(secure_filename(part) + ":")
83+
else:
84+
secured_parts.append(secure_filename(part))
8085
else:
8186
secured_parts = [
8287
(

0 commit comments

Comments
 (0)