Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions src/murfey/client/contexts/spa.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,12 +431,15 @@
grid_square_metadata_file,
grid_square,
)
metadata_source_as_str = (

Check warning on line 434 in src/murfey/client/contexts/spa.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/client/contexts/spa.py#L434

Added line #L434 was not covered by tests
"/".join(source.parts[:-2])
+ f"/{environment.visit}/"
+ source.parts[-2]
)
metadata_source = Path(
(
"/".join(source.parts[:-2])
+ f"/{environment.visit}/"
+ source.parts[-2]
)[1:]
metadata_source_as_str[1:]
if metadata_source_as_str.startswith("//")
else metadata_source_as_str
)
image_path = (
_file_transferred_to(environment, metadata_source, Path(gs.image))
Expand Down Expand Up @@ -471,12 +474,15 @@
foil_hole,
grid_square,
)
metadata_source_as_str = (

Check warning on line 477 in src/murfey/client/contexts/spa.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/client/contexts/spa.py#L477

Added line #L477 was not covered by tests
"/".join(source.parts[:-2])
+ f"/{environment.visit}/"
+ source.parts[-2]
)
metadata_source = Path(
(
"/".join(source.parts[:-2])
+ f"/{environment.visit}/"
+ source.parts[-2]
)[1:]
metadata_source_as_str[1:]
if metadata_source_as_str.startswith("//")
else metadata_source_as_str
)
image_path = (
_file_transferred_to(environment, metadata_source, Path(fh.image))
Expand Down
37 changes: 25 additions & 12 deletions src/murfey/client/contexts/spa_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
required_key = key
break
if not required_key:
logger.warning(f"Required key not found for {str(xml_path)}")
logger.info(f"Required key not found for {str(xml_path)}")

Check warning on line 47 in src/murfey/client/contexts/spa_metadata.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/client/contexts/spa_metadata.py#L47

Added line #L47 was not covered by tests
return {}
foil_holes = {}
for fh_block in serialization_array[required_key]:
Expand Down Expand Up @@ -163,10 +163,13 @@
atlas=Path(partial_path), sample=sample
)
url = f"{str(environment.url.geturl())}/visits/{environment.visit}/{environment.murfey_session}/register_data_collection_group"
dcg_search_dir = "/" + "/".join(
p
for p in transferred_file.parent.parts[1:]
if p != environment.visit
dcg_search_dir = "/".join(

Check warning on line 166 in src/murfey/client/contexts/spa_metadata.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/client/contexts/spa_metadata.py#L166

Added line #L166 was not covered by tests
p for p in transferred_file.parent.parts if p != environment.visit
)
dcg_search_dir = (

Check warning on line 169 in src/murfey/client/contexts/spa_metadata.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/client/contexts/spa_metadata.py#L169

Added line #L169 was not covered by tests
dcg_search_dir[1:]
if dcg_search_dir.startswith("//")
else dcg_search_dir
)
dcg_images_dirs = sorted(
Path(dcg_search_dir).glob("Images-Disc*"),
Expand Down Expand Up @@ -215,11 +218,16 @@
):
# Make sure we have a data collection group before trying to register grid square
url = f"{str(environment.url.geturl())}/visits/{environment.visit}/{environment.murfey_session}/register_data_collection_group"
dcg_search_dir = "/" + "/".join(
dcg_search_dir = "/".join(

Check warning on line 221 in src/murfey/client/contexts/spa_metadata.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/client/contexts/spa_metadata.py#L221

Added line #L221 was not covered by tests
p
for p in transferred_file.parent.parent.parts[1:]
for p in transferred_file.parent.parent.parts
if p != environment.visit
)
dcg_search_dir = (

Check warning on line 226 in src/murfey/client/contexts/spa_metadata.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/client/contexts/spa_metadata.py#L226

Added line #L226 was not covered by tests
dcg_search_dir[1:]
if dcg_search_dir.startswith("//")
else dcg_search_dir
)
dcg_images_dirs = sorted(
Path(dcg_search_dir).glob("Images-Disc*"),
key=lambda x: x.stat().st_ctime,
Expand All @@ -241,6 +249,8 @@
)
fh_positions = _foil_hole_positions(transferred_file, int(gs_name))
source = _get_source(transferred_file, environment=environment)
if source is None:
return None

Check warning on line 253 in src/murfey/client/contexts/spa_metadata.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/client/contexts/spa_metadata.py#L253

Added line #L253 was not covered by tests
visitless_source_search_dir = str(source).replace(
f"/{environment.visit}", ""
)
Expand All @@ -261,12 +271,15 @@
transferred_file,
int(gs_name),
)
metadata_source_as_str = (

Check warning on line 274 in src/murfey/client/contexts/spa_metadata.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/client/contexts/spa_metadata.py#L274

Added line #L274 was not covered by tests
"/".join(source.parts[:-2])
+ f"/{environment.visit}/"
+ source.parts[-2]
)
metadata_source = Path(
(
"/".join(Path(visitless_source).parts[:-2])
+ f"/{environment.visit}/"
+ Path(visitless_source).parts[-2]
)[1:]
metadata_source_as_str[1:]
if metadata_source_as_str.startswith("//")
else metadata_source_as_str
)
image_path = (
_file_transferred_to(
Expand Down
2 changes: 1 addition & 1 deletion src/murfey/client/multigrid_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def _start_rsyncer_multigrid(
source,
destination,
force_metadata=self.processing_enabled,
analyse=not extra_directory and use_suggested_path and analyse,
analyse=analyse,
remove_files=remove_files,
tag=tag,
limited=limited,
Expand Down
10 changes: 10 additions & 0 deletions src/murfey/instrument_server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from rich.logging import RichHandler

import murfey
from murfey.client import read_config
from murfey.client.customlogging import CustomHandler

Check warning on line 9 in src/murfey/instrument_server/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/instrument_server/__init__.py#L8-L9

Added lines #L8 - L9 were not covered by tests
from murfey.util import LogFilter

logger = logging.getLogger("murfey.instrument_server")
Expand Down Expand Up @@ -33,6 +35,14 @@
logging.getLogger("fastapi").addHandler(rich_handler)
logging.getLogger("uvicorn").addHandler(rich_handler)

ws = murfey.client.websocket.WSApp(

Check warning on line 38 in src/murfey/instrument_server/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/instrument_server/__init__.py#L38

Added line #L38 was not covered by tests
server=read_config()["Murfey"].get("server"),
id=0,
)

handler = CustomHandler(ws.send)
logging.getLogger().addHandler(handler)

Check warning on line 44 in src/murfey/instrument_server/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/instrument_server/__init__.py#L43-L44

Added lines #L43 - L44 were not covered by tests

logger.info(
f"Starting Murfey server version {murfey.__version__}, listening on {args.host}:{args.port}"
)
Expand Down
4 changes: 2 additions & 2 deletions src/murfey/instrument_server/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from murfey.client.multigrid_control import MultigridController
from murfey.client.rsync import RSyncer
from murfey.client.watchdir_multigrid import MultigridDirWatcher
from murfey.util import sanitise, sanitise_nonpath, secure_path
from murfey.util import posix_path, sanitise, sanitise_nonpath, secure_path

Check warning on line 24 in src/murfey/instrument_server/api.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/instrument_server/api.py#L24

Added line #L24 was not covered by tests
from murfey.util.instrument_models import MultigridWatcherSpec
from murfey.util.models import File, Token

Expand Down Expand Up @@ -291,7 +291,7 @@
).json()
cmd = [
"rsync",
safe_gain_path,
posix_path(Path(safe_gain_path)),
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)}",
]
gain_rsync = subprocess.run(cmd)
Expand Down
11 changes: 8 additions & 3 deletions src/murfey/util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,14 @@

def secure_path(in_path: Path, keep_spaces: bool = False) -> Path:
if keep_spaces:
secured_parts = [
secure_filename(p) if " " not in p else p for p in in_path.parts
]
secured_parts = []

Check warning on line 77 in src/murfey/util/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/util/__init__.py#L77

Added line #L77 was not covered by tests
for p, part in enumerate(in_path.parts):
if " " in part:
secured_parts.append(part)

Check warning on line 80 in src/murfey/util/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/util/__init__.py#L80

Added line #L80 was not covered by tests
elif ":" in part and not p:
secured_parts.append(secure_filename(part) + ":")

Check warning on line 82 in src/murfey/util/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/util/__init__.py#L82

Added line #L82 was not covered by tests
else:
secured_parts.append(secure_filename(part))

Check warning on line 84 in src/murfey/util/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/util/__init__.py#L84

Added line #L84 was not covered by tests
else:
secured_parts = [
(
Expand Down