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
2 changes: 1 addition & 1 deletion src/murfey/client/contexts/spa.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ def _position_analysis(
data_collection_group = (
capture_get(
base_url=str(environment.url.geturl()),
router_name="session_info.router",
router_name="session_control.router",
function_name="get_dc_groups",
token=self._token,
session_id=environment.murfey_session,
Expand Down
90 changes: 90 additions & 0 deletions src/murfey/client/destinations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
from __future__ import annotations

import logging
from pathlib import Path
from typing import Dict

from murfey.client.analyser import Analyser
from murfey.client.instance_environment import (
MurfeyInstanceEnvironment,
global_env_lock,
)
from murfey.util.client import capture_get, capture_post

logger = logging.getLogger("murfey.client.destinations")


def determine_default_destination(
visit: str,
source: Path,
destination: str,
environment: MurfeyInstanceEnvironment,
analysers: Dict[Path, Analyser],
token: str,
touch: bool = False,
extra_directory: str = "",
include_mid_path: bool = True,
use_suggested_path: bool = True,
) -> str:
machine_data = capture_get(
base_url=str(environment.url.geturl()),
router_name="session_control.router",
function_name="machine_info_by_instrument",
token=token,
instrument_name=environment.instrument_name,
).json()
_default = ""
if environment.processing_only_mode and environment.sources:
logger.info(f"Processing only mode with sources {environment.sources}")
_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.absolute() == Path(data_dir).absolute():
_default = f"{destination}/{visit}"
break
else:
try:
mid_path = source.absolute().relative_to(Path(data_dir).absolute())
if use_suggested_path:
with global_env_lock:
source_name = (
source.name
if source.name != "Images-Disc1"
else source.parent.name
)
if environment.destination_registry.get(source_name):
_default = environment.destination_registry[source_name]
else:
suggested_path_response = capture_post(
base_url=str(environment.url.geturl()),
router_name="file_io_instrument.router",
function_name="suggest_path",
token=token,
visit_name=visit,
session_id=environment.murfey_session,
data={
"base_path": f"{destination}/{visit}/{mid_path.parent if include_mid_path else ''}/raw",
"touch": touch,
"extra_directory": extra_directory,
},
)
if suggested_path_response is None:
raise RuntimeError("Murfey server is unreachable")
_default = suggested_path_response.json().get(
"suggested_path"
)
environment.destination_registry[source_name] = _default
else:
_default = f"{destination}/{visit}/{mid_path if include_mid_path else source.name}"
break
except (ValueError, KeyError):
_default = ""
else:
_default = ""
else:
_default = f"{destination}/{visit}"
return (
_default + f"/{extra_directory}"
if not _default.endswith("/")
else _default + f"{extra_directory}"
)
3 changes: 2 additions & 1 deletion src/murfey/client/multigrid_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
from murfey.client.analyser import Analyser
from murfey.client.contexts.spa import SPAModularContext
from murfey.client.contexts.tomo import TomographyContext
from murfey.client.destinations import determine_default_destination
from murfey.client.instance_environment import MurfeyInstanceEnvironment
from murfey.client.rsync import RSyncer, RSyncerUpdate, TransferResult
from murfey.client.tui.screens import determine_default_destination
from murfey.client.watchdir import DirWatcher
from murfey.util import posix_path
from murfey.util.client import (
Expand Down Expand Up @@ -267,6 +267,7 @@ def _start_rsyncer_multigrid(
self._environment.default_destinations[source],
self._environment,
self.analysers or {},
self.token,
touch=True,
extra_directory=extra_directory,
include_mid_path=include_mid_path,
Expand Down
3 changes: 2 additions & 1 deletion src/murfey/client/tui/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from murfey.client.analyser import Analyser
from murfey.client.contexts.spa import SPAModularContext
from murfey.client.contexts.tomo import TomographyContext
from murfey.client.destinations import determine_default_destination
from murfey.client.instance_environment import MurfeyInstanceEnvironment
from murfey.client.rsync import RSyncer, RSyncerUpdate, TransferResult
from murfey.client.tui.screens import (
Expand All @@ -27,7 +28,6 @@
VisitCreation,
VisitSelection,
WaitingScreen,
determine_default_destination,
)
from murfey.client.tui.status_bar import StatusBar
from murfey.client.watchdir import DirWatcher
Expand Down Expand Up @@ -177,6 +177,7 @@ def _start_rsyncer_multigrid(
self._default_destinations[source],
self._environment,
self.analysers,
token,
touch=True,
extra_directory=extra_directory,
include_mid_path=include_mid_path,
Expand Down
83 changes: 3 additions & 80 deletions src/murfey/client/tui/screens.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,10 @@
)
from werkzeug.utils import secure_filename

from murfey.client.analyser import Analyser
from murfey.client.contexts.spa import SPAModularContext
from murfey.client.contexts.tomo import TomographyContext
from murfey.client.destinations import determine_default_destination
from murfey.client.gain_ref import determine_gain_ref
from murfey.client.instance_environment import (
MurfeyInstanceEnvironment,
global_env_lock,
)
from murfey.client.rsync import RSyncer
from murfey.util import posix_path
from murfey.util.client import (
Expand All @@ -72,81 +68,6 @@
instrument_name = read_config()["Murfey"].get("instrument_name", "")


def determine_default_destination(
visit: str,
source: Path,
destination: str,
environment: MurfeyInstanceEnvironment,
analysers: Dict[Path, Analyser],
touch: bool = False,
extra_directory: str = "",
include_mid_path: bool = True,
use_suggested_path: bool = True,
) -> str:
machine_data = capture_get(
base_url=str(environment.url.geturl()),
router_name="session_control.router",
function_name="machine_info_by_instrument",
token=token,
instrument_name=environment.instrument_name,
).json()
_default = ""
if environment.processing_only_mode and environment.sources:
log.info(f"Processing only mode with sources {environment.sources}")
_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.absolute() == Path(data_dir).absolute():
_default = f"{destination}/{visit}"
break
else:
try:
mid_path = source.absolute().relative_to(Path(data_dir).absolute())
if use_suggested_path:
with global_env_lock:
source_name = (
source.name
if source.name != "Images-Disc1"
else source.parent.name
)
if environment.destination_registry.get(source_name):
_default = environment.destination_registry[source_name]
else:
suggested_path_response = capture_post(
base_url=str(environment.url.geturl()),
router_name="file_io_instrument.router",
function_name="suggest_path",
token=token,
visit_name=visit,
session_id=environment.murfey_session,
data={
"base_path": f"{destination}/{visit}/{mid_path.parent if include_mid_path else ''}/raw",
"touch": touch,
"extra_directory": extra_directory,
},
)
if suggested_path_response is None:
raise RuntimeError("Murfey server is unreachable")
_default = suggested_path_response.json().get(
"suggested_path"
)
environment.destination_registry[source_name] = _default
else:
_default = f"{destination}/{visit}/{mid_path if include_mid_path else source.name}"
break
except (ValueError, KeyError):
_default = ""
else:
_default = ""
else:
_default = f"{destination}/{visit}"
return (
_default + f"/{extra_directory}"
if not _default.endswith("/")
else _default + f"{extra_directory}"
)


class InputResponse(NamedTuple):
question: str
allowed_responses: List[str] | None = None
Expand Down Expand Up @@ -349,6 +270,7 @@ def on_button_pressed(self, event: Button.Pressed) -> None:
defd,
self.app._environment,
self.app.analysers,
token,
touch=True,
)
visit_path = defd + f"/{text}"
Expand Down Expand Up @@ -1077,6 +999,7 @@ def compose(self):
f"{datetime.now().year}",
self.app._environment,
self.app.analysers,
token,
touch=True,
)
if dest and dest in destinations:
Expand Down
20 changes: 17 additions & 3 deletions src/murfey/server/api/session_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,16 @@ def remove_session(session_id: MurfeySessionID, db=murfey_db):
remove_session_by_id(session_id, db)


@router.get("/sessions/{session_id}/data_collection_groups")
def get_dc_groups(
session_id: MurfeySessionID, db=murfey_db
) -> Dict[str, DataCollectionGroup]:
data_collection_groups = db.exec(
select(DataCollectionGroup).where(DataCollectionGroup.session_id == session_id)
).all()
return {dcg.tag: dcg for dcg in data_collection_groups}


@router.post("/sessions/{session_id}/successful_processing")
def register_processing_success_in_ispyb(
session_id: MurfeySessionID, db=ispyb_db, murfey_db=murfey_db
Expand Down Expand Up @@ -196,16 +206,20 @@ def count_number_of_movies(db=murfey_db) -> Dict[str, int]:


class PostInfo(BaseModel):
url: str
router_name: str
function_name: str
data: dict
kwargs: dict


@router.post("/instruments/{instrument_name}/failed_client_post")
def failed_client_post(instrument_name: str, post_info: PostInfo):
zocalo_message = {
"register": "failed_client_post",
"url": post_info.url,
"json": post_info.data,
"router_name": post_info.router_name,
"function_name": post_info.function_name,
"data": post_info.data,
"kwargs": post_info.kwargs,
}
if _transport_object:
_transport_object.send(_transport_object.feedback_queue, zocalo_message)
Expand Down
2 changes: 1 addition & 1 deletion src/murfey/server/api/session_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class VisitEndTime(BaseModel):
end_time: Optional[datetime] = None


@router.post("/instruments/{instrument_name}/visits/{visit}/session/{name}")
@router.post("/instruments/{instrument_name}/visits/{visit}/sessions/{name}")
def create_session(
instrument_name: MurfeyInstrumentName,
visit: str,
Expand Down
4 changes: 2 additions & 2 deletions src/murfey/server/demo_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ class SessionClients(BaseModel):
clients: List[ClientEnvironment]


@router.get("/session/{session_id}")
@router.get("/sessions/{session_id}")
async def get_session(session_id: MurfeySessionID, db=murfey_db) -> SessionClients:
session = db.exec(select(Session).where(Session.id == session_id)).one()
clients = db.exec(
Expand Down Expand Up @@ -996,7 +996,7 @@ async def get_tiff(visit_name: str, session_id: int, tiff_path: str, db=murfey_d
return FileResponse(path=test_path)


@router.post("/instruments/{instrument_name}/visits/{visit}/session/{name}")
@router.post("/instruments/{instrument_name}/visits/{visit}/sessions/{name}")
def create_session(instrument_name: str, visit: str, name: str, db=murfey_db) -> int:
s = Session(name=name, visit=visit, instrument_name=instrument_name)
db.add(s)
Expand Down
2 changes: 1 addition & 1 deletion src/murfey/util/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def capture_post(
response = requests.Response()
if response.status_code != 200:
logger.warning(
f"Response to post to {url} with data {json} had status code "
f"Response to post to {url} with data {data} had status code "
f"{response.status_code}. The reason given was {response.reason}"
)
client_config = read_config()
Expand Down
9 changes: 8 additions & 1 deletion src/murfey/util/route_manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,13 @@ murfey.server.api.session_control.router:
type: int
methods:
- DELETE
- path: /session_info/sessions/{session_id}/data_collection_groups
function: get_dc_groups
path_params:
- name: session_id
type: int
methods:
- GET
- path: /session_control/sessions/{session_id}/successful_processing
function: register_processing_success_in_ispyb
path_params:
Expand Down Expand Up @@ -1040,7 +1047,7 @@ murfey.server.api.session_info.router:
path_params: []
methods:
- GET
- path: /session_info/instruments/{instrument_name}/visits/{visit}/session/{name}
- path: /session_info/instruments/{instrument_name}/visits/{visit}/sessions/{name}
function: create_session
path_params:
- name: visit
Expand Down