Skip to content

Commit 5a57ddf

Browse files
committed
Merged recent changes from 'main'
2 parents 78dbf9f + f3e1b83 commit 5a57ddf

3 files changed

Lines changed: 59 additions & 4 deletions

File tree

src/murfey/server/api/file_io_frontend.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
from logging import getLogger
2+
from pathlib import Path
23

34
from fastapi import APIRouter, Depends
5+
from pydantic import BaseModel
6+
from sqlmodel import Session, select
47

58
from murfey.server.api.auth import (
69
MurfeySessionIDFrontend as MurfeySessionID,
@@ -11,6 +14,7 @@
1114
process_gain as _process_gain,
1215
)
1316
from murfey.server.murfey_db import murfey_db
17+
from murfey.util.config import get_machine_config
1418

1519
logger = getLogger("murfey.server.api.file_io_frontend")
1620

@@ -28,3 +32,27 @@ async def process_gain(
2832
):
2933
result = await _process_gain(session_id, gain_reference_params, db)
3034
return result
35+
36+
37+
class SymlinkParameters(BaseModel):
38+
target: Path # these are the paths without the rsync basepath as that is what the frontend has access to
39+
symlink: Path
40+
override: bool = False
41+
42+
43+
@router.post("/sessions/{session_id}/symlink")
44+
async def create_symlink(
45+
session_id: MurfeySessionID, symlink_params: SymlinkParameters, db=murfey_db
46+
) -> str:
47+
murfey_session = db.exec(select(Session).where(Session.id == session_id)).one()
48+
instrument_name = murfey_session.instrument_name
49+
machine_config = get_machine_config(instrument_name=instrument_name)[
50+
instrument_name
51+
]
52+
symlink_full_path = machine_config.rsync_basepath / symlink_params.symlink
53+
if symlink_full_path.is_symlink() and symlink_params.override:
54+
symlink_full_path.unlink()
55+
if symlink_full_path.exists():
56+
return ""
57+
symlink_full_path.symlink_to(symlink_params.target)
58+
return str(symlink_params.symlink)

src/murfey/server/feedback.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,8 @@ def _2d_class_murfey_ids(particles_file: str, app_id: int, _db) -> Dict[str, int
241241
db.Class2D.particles_file == particles_file and db.Class2D.pj_id == pj_id
242242
)
243243
).all()
244+
if not classes:
245+
raise ValueError(f"No 2D classification IDs found for {particles_file}")
244246
return {str(cl.class_number): cl.murfey_id for cl in classes}
245247

246248

@@ -256,6 +258,8 @@ def _3d_class_murfey_ids(particles_file: str, app_id: int, _db) -> Dict[str, int
256258
and db.Class3D.pj_id == pj_id
257259
)
258260
).all()
261+
if not classes:
262+
raise ValueError(f"No 3D classification IDs found for {particles_file}")
259263
return {str(cl.class_number): cl.murfey_id for cl in classes}
260264

261265

@@ -623,7 +627,9 @@ def _register_incomplete_2d_batch(message: dict, _db, demo: bool = False):
623627
)
624628
_db.add(class2d_params)
625629
_db.commit()
626-
murfey_ids = _murfey_id(message["program_id"], _db, number=50)
630+
murfey_ids = _murfey_id(
631+
message["program_id"], _db, number=default_spa_parameters.nr_classes_2d
632+
)
627633
_murfey_class2ds(
628634
murfey_ids, class2d_message["particles_file"], message["program_id"], _db
629635
)
@@ -747,7 +753,9 @@ def _register_complete_2d_batch(message: dict, _db, demo: bool = False):
747753
_db.add(class2d_params)
748754
_db.commit()
749755
_db.close()
750-
murfey_ids = _murfey_id(_app_id(pj_id, _db), _db, number=50)
756+
murfey_ids = _murfey_id(
757+
_app_id(pj_id, _db), _db, number=default_spa_parameters.nr_classes_2d
758+
)
751759
_murfey_class2ds(
752760
murfey_ids, class2d_message["particles_file"], _app_id(pj_id, _db), _db
753761
)
@@ -796,7 +804,13 @@ def _register_complete_2d_batch(message: dict, _db, demo: bool = False):
796804
else:
797805
class_uuids = {
798806
str(i + 1): m
799-
for i, m in enumerate(_murfey_id(_app_id(pj_id, _db), _db, number=50))
807+
for i, m in enumerate(
808+
_murfey_id(
809+
_app_id(pj_id, _db),
810+
_db,
811+
number=default_spa_parameters.nr_classes_2d,
812+
)
813+
)
800814
}
801815
class2d_grp_uuid = _murfey_id(_app_id(pj_id, _db), _db)[0]
802816
zocalo_message: dict = {
@@ -865,7 +879,13 @@ def _register_complete_2d_batch(message: dict, _db, demo: bool = False):
865879
else:
866880
class_uuids = {
867881
str(i + 1): m
868-
for i, m in enumerate(_murfey_id(_app_id(pj_id, _db), _db, number=50))
882+
for i, m in enumerate(
883+
_murfey_id(
884+
_app_id(pj_id, _db),
885+
_db,
886+
number=default_spa_parameters.nr_classes_2d,
887+
)
888+
)
869889
}
870890
class2d_grp_uuid = _murfey_id(_app_id(pj_id, _db), _db)[0]
871891
zocalo_message = {

src/murfey/util/route_manifest.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,13 @@ murfey.server.api.file_io_frontend.router:
477477
type: int
478478
methods:
479479
- POST
480+
- path: /file_io/frontend/sessions/{session_id}/symlink
481+
function: create_symlink
482+
path_params:
483+
- name: session_id
484+
type: int
485+
methods:
486+
- POST
480487
murfey.server.api.file_io_instrument.router:
481488
- path: /file_io/instrument/visits/{visit_name}/sessions/{session_id}/suggested_path
482489
function: suggest_path

0 commit comments

Comments
 (0)