From 89be320573694e6443e2266794ff7ab7e8b1c854 Mon Sep 17 00:00:00 2001 From: Eu-Pin Tien Date: Tue, 18 Mar 2025 17:33:29 +0000 Subject: [PATCH 1/2] Replaced Path().resolve() with Path().absolute() in client-side modules --- src/murfey/client/__init__.py | 2 +- src/murfey/client/analyser.py | 2 +- src/murfey/client/rsync.py | 2 +- src/murfey/client/tui/screens.py | 28 +++++++++++++++------------- 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/murfey/client/__init__.py b/src/murfey/client/__init__.py index ce194ea04..52a866c50 100644 --- a/src/murfey/client/__init__.py +++ b/src/murfey/client/__init__.py @@ -239,7 +239,7 @@ def run(): if args.remove_files: remove_prompt = Confirm.ask( - f"Are you sure you want to remove files from {args.source or Path('.').resolve()}?" + f"Are you sure you want to remove files from {args.source or Path('.').absolute()}?" ) if not remove_prompt: exit("Exiting") diff --git a/src/murfey/client/analyser.py b/src/murfey/client/analyser.py index 9e7a37d1d..8522d2a76 100644 --- a/src/murfey/client/analyser.py +++ b/src/murfey/client/analyser.py @@ -415,7 +415,7 @@ def _xml_file(self, data_file: Path) -> Path: def enqueue(self, rsyncer: RSyncerUpdate): if not self._stopping and rsyncer.outcome == TransferResult.SUCCESS: - absolute_path = (self._basepath / rsyncer.file_path).resolve() + absolute_path = (self._basepath / rsyncer.file_path).absolute() self.queue.put(absolute_path) def start(self): diff --git a/src/murfey/client/rsync.py b/src/murfey/client/rsync.py index d67274c8b..e3caee849 100644 --- a/src/murfey/client/rsync.py +++ b/src/murfey/client/rsync.py @@ -199,7 +199,7 @@ def finalise(self, thread: bool = True): def enqueue(self, file_path: Path): if not self._stopping: - absolute_path = (self._basepath / file_path).resolve() + absolute_path = self._basepath / file_path self.queue.put(absolute_path) def _process(self): diff --git a/src/murfey/client/tui/screens.py b/src/murfey/client/tui/screens.py index 419ec0b10..0ba3c30a8 100644 --- a/src/murfey/client/tui/screens.py +++ b/src/murfey/client/tui/screens.py @@ -88,15 +88,15 @@ def determine_default_destination( _default = "" if environment.processing_only_mode and environment.sources: log.info(f"Processing only mode with sources {environment.sources}") - _default = str(environment.sources[0].resolve()) or str(Path.cwd()) + _default = str(environment.sources[0].absolute()) or str(Path.cwd()) elif machine_data.get("data_directories"): for data_dir in machine_data["data_directories"]: - if source.resolve() == Path(data_dir): + if source.absolute() == Path(data_dir).absolute(): _default = f"{destination}/{visit}" break else: try: - mid_path = source.resolve().relative_to(data_dir) + mid_path = source.absolute().relative_to(Path(data_dir).absolute()) if use_suggested_path: with global_env_lock: source_name = ( @@ -221,7 +221,7 @@ def on_tree_node_selected(self, event: Tree.NodeSelected) -> None: self.valid_selection = True return for d in self._data_directories: - if Path(self._selected_path).resolve().is_relative_to(d): + if Path(self._selected_path).absolute().is_relative_to(d.absolute()): self.valid_selection = True break else: @@ -282,7 +282,9 @@ def compose(self): btn_disabled = True for d in machine_data.get("data_directories", []): if ( - Path(self._dir_tree._selected_path).resolve().is_relative_to(d) + Path(self._dir_tree._selected_path) + .absolute() + .is_relative_to(Path(d).absolute()) or self.app._environment.processing_only_mode ): btn_disabled = False @@ -306,7 +308,7 @@ def _check_valid_selection(self, valid: bool): self._add_btn.disabled = True def _add_directory(self, directory: str, add_destination: bool = True): - source = Path(self._dir_tree.path).resolve() / directory + source = Path(self._dir_tree.path).absolute() / directory if add_destination: for s in self.app._environment.sources: if source.is_relative_to(s): @@ -705,9 +707,9 @@ def on_button_pressed(self, event: Button.Pressed): self.app.install_screen( DirectorySelection( [ - p - for p in machine_data.get("data_directories", []) - if Path(p).exists() + path + for path in machine_data.get("data_directories", []) + if Path(path).exists() ] ), "directory-select", @@ -771,9 +773,9 @@ def on_button_pressed(self, event: Button.Pressed): self.app.install_screen( DirectorySelection( [ - p - for p in machine_data.get("data_directories", []) - if Path(p).exists() + path + for path in machine_data.get("data_directories", []) + if Path(path).exists() ] ), "directory-select", @@ -941,7 +943,7 @@ def __init__(self, directories: List[str], *args, **kwargs): def on_button_pressed(self, event: Button.Pressed): self.app._multigrid = self._switch_status - visit_dir = Path(str(event.button.label)) / self.app._visit + visit_dir = Path(str(event.button.label)).absolute() / self.app._visit visit_dir.mkdir(exist_ok=True) self.app._set_default_acquisition_directories(visit_dir) machine_config = get_machine_config_client( From a5e9e3594b46a6b99d56d1f6be755241329bf141 Mon Sep 17 00:00:00 2001 From: Eu-Pin Tien Date: Thu, 20 Mar 2025 12:20:52 +0000 Subject: [PATCH 2/2] Fixed path logic in '_xml_file' function and '_grid_square_metadata_file'; added catch to _analyse for ValueError --- src/murfey/client/analyser.py | 8 ++++++-- src/murfey/client/contexts/spa.py | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/murfey/client/analyser.py b/src/murfey/client/analyser.py index 8522d2a76..3fefb158b 100644 --- a/src/murfey/client/analyser.py +++ b/src/murfey/client/analyser.py @@ -302,6 +302,10 @@ def _analyse(self): f"Metadata gathering failed with a key error for key: {e.args[0]}" ) raise e + except ValueError as e: + logger.error( + f"Metadata gathering failed with a value error: {e}" + ) if not dc_metadata or not self._force_mdoc_metadata: self._unseen_xml.append(transferred_file) else: @@ -406,8 +410,8 @@ def _xml_file(self, data_file: Path) -> Path: data_directories = self._murfey_config.get("data_directories", []) for dd in data_directories: if str(data_file).startswith(dd): - base_dir = Path(dd) - mid_dir = data_file.relative_to(dd).parent + base_dir = Path(dd).absolute() + mid_dir = data_file.relative_to(base_dir).parent break else: return data_file.with_suffix(".xml") diff --git a/src/murfey/client/contexts/spa.py b/src/murfey/client/contexts/spa.py index 17db68027..49d27f864 100644 --- a/src/murfey/client/contexts/spa.py +++ b/src/murfey/client/contexts/spa.py @@ -61,8 +61,8 @@ def _grid_square_metadata_file( ) -> Path: for dd in data_directories: if str(f).startswith(str(dd)): - base_dir = dd - mid_dir = f.relative_to(dd).parent + base_dir = dd.absolute() + mid_dir = f.relative_to(base_dir).parent break else: raise ValueError(f"Could not determine grid square metadata path for {f}")