Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pycalibration
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Model registry
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
calibration
pycalibration
Commits
ca74aab2
Commit
ca74aab2
authored
11 months ago
by
Karim Ahmed
Committed by
Philipp Schmidt
11 months ago
Browse files
Options
Downloads
Patches
Plain Diff
catch CALCATAPIError and create exception classes for two cases in webservice
parent
21173e03
No related branches found
No related tags found
1 merge request
!993
[Webservice] Enable two runs detectors
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
webservice/messages.py
+10
-0
10 additions, 0 deletions
webservice/messages.py
webservice/webservice.py
+33
-12
33 additions, 12 deletions
webservice/webservice.py
with
43 additions
and
12 deletions
webservice/messages.py
+
10
−
0
View file @
ca74aab2
...
...
@@ -33,6 +33,16 @@ class MDC:
NOTHING_TO_DO
=
"
Nothing to calibrate for this run, copied raw data only
"
class
PDUsNotFoundError
(
Exception
):
"""
Exception raised when a detector cannot be found.
"""
pass
class
OperationModeNotFoundError
(
Exception
):
"""
Exception raised when an operation mode cannot be found for a given detector.
"""
pass
class
Success
:
UPLOADED_CONFIG
=
"
SUCCESS: Uploaded config for cycle {}, proposal {}
"
START_CORRECTION
=
"
SUCCESS: Started correction: proposal {}, run {}
"
...
...
This diff is collapsed.
Click to expand it.
webservice/webservice.py
+
33
−
12
View file @
ca74aab2
...
...
@@ -31,10 +31,17 @@ from metadata_client.metadata_client import MetadataClient
try
:
from
.config
import
webservice
as
config
from
.messages
import
MDC
,
Errors
,
MigrationError
,
Success
from
.messages
import
(
MDC
,
Errors
,
MigrationError
,
OperationModeNotFoundError
,
PDUsNotFoundError
,
Success
,
)
except
ImportError
:
from
config
import
webservice
as
config
from
messages
import
MDC
,
Errors
,
MigrationError
,
Success
from
messages
import
MDC
,
Errors
,
MigrationError
,
Success
,
PDUsNotFoundError
,
OperationModeNotFoundError
from
cal_tools.calcat_interface2
import
get_client
...
...
@@ -347,23 +354,37 @@ def get_number_of_characterization_runs(karabo_id, operation_mode):
"""
client
=
get_client
()
detector_id
=
client
.
detector_by_identifier
(
karabo_id
)[
'
id
'
]
pdus
=
client
.
get
(
'
physical_detector_units/get_all_by_detector?
'
f
'
detector_id=
{
detector_id
}
'
)
first_pdu_id
=
pdus
[
0
][
'
detector_type
'
][
'
id
'
]
operation_modes
=
client
.
get
(
'
operation_modes/get_all_by_detector_type?
'
f
'
detector_type_id=
{
first_pdu_id
}
'
)
try
:
pdus
=
client
.
get
(
'
physical_detector_units/get_all_by_detector?
'
f
'
detector_id=
{
detector_id
}
'
)
if
len
(
pdus
)
==
0
:
raise
PDUsNotFoundError
except
Exception
as
e
:
raise
PDUsNotFoundError
(
f
'
Failed to find physical detector units for
{
karabo_id
}
:
{
e
}
'
)
det_type
=
pdus
[
0
][
'
detector_type
'
]
try
:
operation_modes
=
client
.
get
(
'
operation_modes/get_all_by_detector_type?
'
f
'
detector_type_id=
{
det_type
[
"
id
"
]
}
'
)
if
len
(
operation_modes
)
==
0
:
raise
OperationModeNotFoundError
except
Exception
as
e
:
raise
OperationModeNotFoundError
(
f
'
Failed to find operation modes for
{
det_type
[
"
name
"
]
}
:
{
e
}
'
)
number_of_runs
=
next
(
(
mode
[
'
number_of_runs
'
]
for
mode
in
operation_modes
if
mode
[
'
identifier
'
]
==
operation_mode
),
None
)
if
number_of_runs
is
None
:
raise
ValueError
(
f
"
{
karabo_id
}
doesn
'
t have this operation mode
{
operation_mode
}
.
"
)
raise
OperationModeNotFoundError
(
f
'
{
karabo_id
}
does not have this operation mode
{
operation_mode
}
.
'
)
return
number_of_runs
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment