processview 0.1.0b0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- home/payno/.local/share/virtualenvs/tomwer_venv/lib/python3.7/site-packages/processview/__init__.py +0 -0
- home/payno/.local/share/virtualenvs/tomwer_venv/lib/python3.7/site-packages/processview/__pycache__/__init__.cpython-37.pyc +0 -0
- home/payno/.local/share/virtualenvs/tomwer_venv/lib/python3.7/site-packages/processview/__pycache__/setup.cpython-37.pyc +0 -0
- home/payno/.local/share/virtualenvs/tomwer_venv/lib/python3.7/site-packages/processview/__pycache__/version.cpython-37.pyc +0 -0
- home/payno/.local/share/virtualenvs/tomwer_venv/lib/python3.7/site-packages/processview/core/__init__.py +0 -0
- home/payno/.local/share/virtualenvs/tomwer_venv/lib/python3.7/site-packages/processview/core/__pycache__/__init__.cpython-37.pyc +0 -0
- home/payno/.local/share/virtualenvs/tomwer_venv/lib/python3.7/site-packages/processview/core/__pycache__/dataset.cpython-37.pyc +0 -0
- home/payno/.local/share/virtualenvs/tomwer_venv/lib/python3.7/site-packages/processview/core/__pycache__/setup.cpython-37.pyc +0 -0
- home/payno/.local/share/virtualenvs/tomwer_venv/lib/python3.7/site-packages/processview/core/__pycache__/superviseprocess.cpython-37.pyc +0 -0
- home/payno/.local/share/virtualenvs/tomwer_venv/lib/python3.7/site-packages/processview/core/dataset.py +40 -0
- home/payno/.local/share/virtualenvs/tomwer_venv/lib/python3.7/site-packages/processview/core/manager/__init__.py +1 -0
- home/payno/.local/share/virtualenvs/tomwer_venv/lib/python3.7/site-packages/processview/core/manager/__pycache__/__init__.cpython-37.pyc +0 -0
- home/payno/.local/share/virtualenvs/tomwer_venv/lib/python3.7/site-packages/processview/core/manager/__pycache__/manager.cpython-37.pyc +0 -0
- home/payno/.local/share/virtualenvs/tomwer_venv/lib/python3.7/site-packages/processview/core/manager/manager.py +316 -0
- home/payno/.local/share/virtualenvs/tomwer_venv/lib/python3.7/site-packages/processview/core/manager/test/__init__.py +39 -0
- home/payno/.local/share/virtualenvs/tomwer_venv/lib/python3.7/site-packages/processview/core/manager/test/__pycache__/__init__.cpython-37.pyc +0 -0
- home/payno/.local/share/virtualenvs/tomwer_venv/lib/python3.7/site-packages/processview/core/manager/test/__pycache__/test_manager.cpython-37.pyc +0 -0
- home/payno/.local/share/virtualenvs/tomwer_venv/lib/python3.7/site-packages/processview/core/manager/test/test_manager.py +121 -0
- home/payno/.local/share/virtualenvs/tomwer_venv/lib/python3.7/site-packages/processview/core/setup.py +44 -0
- home/payno/.local/share/virtualenvs/tomwer_venv/lib/python3.7/site-packages/processview/core/superviseprocess.py +116 -0
- home/payno/.local/share/virtualenvs/tomwer_venv/lib/python3.7/site-packages/processview/core/test/__init__.py +38 -0
- home/payno/.local/share/virtualenvs/tomwer_venv/lib/python3.7/site-packages/processview/core/test/__pycache__/__init__.cpython-37.pyc +0 -0
- home/payno/.local/share/virtualenvs/tomwer_venv/lib/python3.7/site-packages/processview/gui/__init__.py +0 -0
- home/payno/.local/share/virtualenvs/tomwer_venv/lib/python3.7/site-packages/processview/gui/__pycache__/__init__.cpython-37.pyc +0 -0
- home/payno/.local/share/virtualenvs/tomwer_venv/lib/python3.7/site-packages/processview/gui/__pycache__/icons.cpython-37.pyc +0 -0
- home/payno/.local/share/virtualenvs/tomwer_venv/lib/python3.7/site-packages/processview/gui/__pycache__/processmanager.cpython-37.pyc +0 -0
- home/payno/.local/share/virtualenvs/tomwer_venv/lib/python3.7/site-packages/processview/gui/icons.py +404 -0
- home/payno/.local/share/virtualenvs/tomwer_venv/lib/python3.7/site-packages/processview/gui/processmanager.py +457 -0
- home/payno/.local/share/virtualenvs/tomwer_venv/lib/python3.7/site-packages/processview/resources/__init__.py +0 -0
- home/payno/.local/share/virtualenvs/tomwer_venv/lib/python3.7/site-packages/processview/resources/__pycache__/__init__.cpython-37.pyc +0 -0
- home/payno/.local/share/virtualenvs/tomwer_venv/lib/python3.7/site-packages/processview/resources/gui/icons/advancement.png +0 -0
- home/payno/.local/share/virtualenvs/tomwer_venv/lib/python3.7/site-packages/processview/resources/gui/icons/advancement.svg +193 -0
- home/payno/.local/share/virtualenvs/tomwer_venv/lib/python3.7/site-packages/processview/resources/gui/icons/magnifying_glass.png +0 -0
- home/payno/.local/share/virtualenvs/tomwer_venv/lib/python3.7/site-packages/processview/resources/gui/icons/magnifying_glass.svg +168 -0
- home/payno/.local/share/virtualenvs/tomwer_venv/lib/python3.7/site-packages/processview/setup.py +47 -0
- home/payno/.local/share/virtualenvs/tomwer_venv/lib/python3.7/site-packages/processview/test/__init__.py +43 -0
- home/payno/.local/share/virtualenvs/tomwer_venv/lib/python3.7/site-packages/processview/test/__pycache__/__init__.cpython-37.pyc +0 -0
- home/payno/.local/share/virtualenvs/tomwer_venv/lib/python3.7/site-packages/processview/utils/__init__.py +69 -0
- home/payno/.local/share/virtualenvs/tomwer_venv/lib/python3.7/site-packages/processview/utils/__pycache__/__init__.cpython-37.pyc +0 -0
- home/payno/.local/share/virtualenvs/tomwer_venv/lib/python3.7/site-packages/processview/utils/__pycache__/singleton.cpython-37.pyc +0 -0
- home/payno/.local/share/virtualenvs/tomwer_venv/lib/python3.7/site-packages/processview/utils/singleton.py +36 -0
- home/payno/.local/share/virtualenvs/tomwer_venv/lib/python3.7/site-packages/processview/version.py +132 -0
- home/payno/.local/share/virtualenvs/tomwer_venv/lib/python3.7/site-packages/processview-0.1.0b0-py3.7.egg-info/PKG-INFO +37 -0
- home/payno/.local/share/virtualenvs/tomwer_venv/lib/python3.7/site-packages/processview-0.1.0b0-py3.7.egg-info/SOURCES.txt +31 -0
- home/payno/.local/share/virtualenvs/tomwer_venv/lib/python3.7/site-packages/processview-0.1.0b0-py3.7.egg-info/dependency_links.txt +1 -0
- home/payno/.local/share/virtualenvs/tomwer_venv/lib/python3.7/site-packages/processview-0.1.0b0-py3.7.egg-info/not-zip-safe +1 -0
- home/payno/.local/share/virtualenvs/tomwer_venv/lib/python3.7/site-packages/processview-0.1.0b0-py3.7.egg-info/requires.txt +4 -0
- home/payno/.local/share/virtualenvs/tomwer_venv/lib/python3.7/site-packages/processview-0.1.0b0-py3.7.egg-info/top_level.txt +1 -0
home/payno/.local/share/virtualenvs/tomwer_venv/lib/python3.7/site-packages/processview/__init__.py
ADDED
|
File without changes
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
File without changes
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
# /*##########################################################################
|
|
3
|
+
#
|
|
4
|
+
# Copyright (c) 2016-2017 European Synchrotron Radiation Facility
|
|
5
|
+
#
|
|
6
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
# of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
# in the Software without restriction, including without limitation the rights
|
|
9
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
# copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
# furnished to do so, subject to the following conditions:
|
|
12
|
+
#
|
|
13
|
+
# The above copyright notice and this permission notice shall be included in
|
|
14
|
+
# all copies or substantial portions of the Software.
|
|
15
|
+
#
|
|
16
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
22
|
+
# THE SOFTWARE.
|
|
23
|
+
#
|
|
24
|
+
# ###########################################################################*/
|
|
25
|
+
|
|
26
|
+
__authors__ = ["H. Payno"]
|
|
27
|
+
__license__ = "MIT"
|
|
28
|
+
__date__ = "29/01/2021"
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class Dataset:
|
|
32
|
+
"""Base class that class processes should inherit"""
|
|
33
|
+
|
|
34
|
+
def short_str(self):
|
|
35
|
+
"""short string description"""
|
|
36
|
+
raise NotImplementedError()
|
|
37
|
+
|
|
38
|
+
def __str__(self):
|
|
39
|
+
"""string representation"""
|
|
40
|
+
raise NotImplementedError()
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .manager import *
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
# /*##########################################################################
|
|
3
|
+
#
|
|
4
|
+
# Copyright (c) 2016-2017 European Synchrotron Radiation Facility
|
|
5
|
+
#
|
|
6
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
# of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
# in the Software without restriction, including without limitation the rights
|
|
9
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
# copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
# furnished to do so, subject to the following conditions:
|
|
12
|
+
#
|
|
13
|
+
# The above copyright notice and this permission notice shall be included in
|
|
14
|
+
# all copies or substantial portions of the Software.
|
|
15
|
+
#
|
|
16
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
22
|
+
# THE SOFTWARE.
|
|
23
|
+
#
|
|
24
|
+
# ###########################################################################*/
|
|
25
|
+
|
|
26
|
+
__authors__ = ["H. Payno"]
|
|
27
|
+
__license__ = "MIT"
|
|
28
|
+
__date__ = "03/11/2020"
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
from processview.utils.singleton import singleton
|
|
32
|
+
from processview.core.dataset import Dataset
|
|
33
|
+
from collections import OrderedDict
|
|
34
|
+
from silx.utils.enum import Enum as _Enum
|
|
35
|
+
import threading
|
|
36
|
+
from typing import Union
|
|
37
|
+
from datetime import datetime
|
|
38
|
+
import weakref
|
|
39
|
+
import logging
|
|
40
|
+
|
|
41
|
+
_logger = logging.getLogger(__name__)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
class DatasetState(_Enum):
|
|
45
|
+
"""possible dataset status relatif to a Process"""
|
|
46
|
+
|
|
47
|
+
ON_GOING = "on going"
|
|
48
|
+
SUCCEED = "succeed"
|
|
49
|
+
FAILED = "failed"
|
|
50
|
+
PENDING = "pending"
|
|
51
|
+
SKIPPED = "skipped"
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
@singleton
|
|
55
|
+
class ProcessManager:
|
|
56
|
+
"""
|
|
57
|
+
Manager to register and observe `SuperviseProcess`.
|
|
58
|
+
"""
|
|
59
|
+
|
|
60
|
+
def __init__(self):
|
|
61
|
+
self._processes = {}
|
|
62
|
+
self._dataset_process_states = {}
|
|
63
|
+
"""key is Dataset.short_str. Value is a tuple of
|
|
64
|
+
(dataset state, details)"""
|
|
65
|
+
self._processID = 0
|
|
66
|
+
self._updateCallback = set()
|
|
67
|
+
"""list of callback to trigger when an update is generated"""
|
|
68
|
+
self._newProcessCallback = set()
|
|
69
|
+
"""list of callback to trigger when a process is added"""
|
|
70
|
+
self.lock = threading.Lock()
|
|
71
|
+
|
|
72
|
+
def register(self, process) -> int:
|
|
73
|
+
"""
|
|
74
|
+
Register a process to the manager
|
|
75
|
+
|
|
76
|
+
:param BaseProcess process:
|
|
77
|
+
"""
|
|
78
|
+
process_id = self._processID
|
|
79
|
+
self._processID += 1
|
|
80
|
+
self._processes[process_id] = weakref.ref(process)
|
|
81
|
+
process._set_process_id(process_id)
|
|
82
|
+
|
|
83
|
+
for callback in self._newProcessCallback:
|
|
84
|
+
callback()
|
|
85
|
+
|
|
86
|
+
return process_id
|
|
87
|
+
|
|
88
|
+
def _find_dataset(self, data):
|
|
89
|
+
if isinstance(data, Dataset):
|
|
90
|
+
return data
|
|
91
|
+
elif isinstance(data, str):
|
|
92
|
+
for s in self.get_datasets():
|
|
93
|
+
if s == data:
|
|
94
|
+
return data
|
|
95
|
+
else:
|
|
96
|
+
raise TypeError(
|
|
97
|
+
"dataset should be an instance of Dataset or "
|
|
98
|
+
"str. Get {} instead".format(type(data))
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
def _find_process(self, process):
|
|
102
|
+
from processview.core.superviseprocess import SuperviseProcess
|
|
103
|
+
|
|
104
|
+
if isinstance(process, SuperviseProcess):
|
|
105
|
+
return process
|
|
106
|
+
elif isinstance(process, str):
|
|
107
|
+
for p in self.get_processes():
|
|
108
|
+
if p.name == process:
|
|
109
|
+
return process
|
|
110
|
+
else:
|
|
111
|
+
raise TypeError(
|
|
112
|
+
"process should be an instance of SuperviseProcess or"
|
|
113
|
+
" str. Get {} instead".format(type(process))
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
def unregister(self, process):
|
|
117
|
+
"""
|
|
118
|
+
Unregister a process to the manager
|
|
119
|
+
|
|
120
|
+
:param BaseProcess process:
|
|
121
|
+
"""
|
|
122
|
+
if process.process_id in self._processes:
|
|
123
|
+
del self._processes[process.process_id]
|
|
124
|
+
|
|
125
|
+
def get_processes(self) -> tuple:
|
|
126
|
+
"""
|
|
127
|
+
|
|
128
|
+
:return: tuple of processes currently registered
|
|
129
|
+
:rtype: tuple
|
|
130
|
+
"""
|
|
131
|
+
processes = []
|
|
132
|
+
for _, p in self._processes.items():
|
|
133
|
+
if p() is not None:
|
|
134
|
+
processes.append(p())
|
|
135
|
+
return tuple(processes)
|
|
136
|
+
|
|
137
|
+
def get_datasets(self) -> tuple:
|
|
138
|
+
"""
|
|
139
|
+
|
|
140
|
+
:return: tuple of datasets
|
|
141
|
+
"""
|
|
142
|
+
res = set()
|
|
143
|
+
for _, dataset_states in self._dataset_process_states.items():
|
|
144
|
+
[res.add(dataset) for dataset in dataset_states]
|
|
145
|
+
return tuple(res)
|
|
146
|
+
|
|
147
|
+
def notify_dataset_state(self, dataset, process, state, details=None) -> None:
|
|
148
|
+
"""
|
|
149
|
+
Update dataset state
|
|
150
|
+
|
|
151
|
+
:param Dataset dataset: dataset which state is updated
|
|
152
|
+
:param BaseProcess process: Process concern by the new state
|
|
153
|
+
:param DatasetState state: current State
|
|
154
|
+
:param str info: details about the error or success
|
|
155
|
+
:return:
|
|
156
|
+
"""
|
|
157
|
+
if process.process_id not in self._processes:
|
|
158
|
+
self.register(process)
|
|
159
|
+
if process.process_id not in self._dataset_process_states:
|
|
160
|
+
self._dataset_process_states[process.process_id] = OrderedDict()
|
|
161
|
+
if details is None:
|
|
162
|
+
details = ""
|
|
163
|
+
self._dataset_process_states[process.process_id][dataset.short_str()] = (
|
|
164
|
+
state,
|
|
165
|
+
datetime.now(),
|
|
166
|
+
details,
|
|
167
|
+
)
|
|
168
|
+
self.updated()
|
|
169
|
+
|
|
170
|
+
def get_dataset_state(self, dataset, process) -> Union[None, DatasetState]:
|
|
171
|
+
"""
|
|
172
|
+
|
|
173
|
+
:param Dataset dataset:
|
|
174
|
+
:param BaseProcess process:
|
|
175
|
+
:return: DatasetState relative to provided process if know
|
|
176
|
+
:rtype: Union[None, DatasetState]
|
|
177
|
+
"""
|
|
178
|
+
dataset = self._find_dataset(dataset)
|
|
179
|
+
process = self._find_process(process)
|
|
180
|
+
if process is None:
|
|
181
|
+
_logger.warning("process {} is no more supervised".format(process))
|
|
182
|
+
return
|
|
183
|
+
if dataset is None:
|
|
184
|
+
_logger.warning("dataset {} is no more supervised".format(dataset))
|
|
185
|
+
if process.process_id in self._dataset_process_states:
|
|
186
|
+
if dataset.short_str() in self._dataset_process_states[process.process_id]:
|
|
187
|
+
return self._dataset_process_states[process.process_id][
|
|
188
|
+
dataset.short_str()
|
|
189
|
+
][0]
|
|
190
|
+
return None
|
|
191
|
+
|
|
192
|
+
def get_dataset_details(self, dataset, process) -> Union[None, str]:
|
|
193
|
+
"""
|
|
194
|
+
|
|
195
|
+
:param Dataset dataset:
|
|
196
|
+
:param BaseProcess process:
|
|
197
|
+
:return: DatasetState relative to provided process if know
|
|
198
|
+
:rtype: Union[None, DatasetState]
|
|
199
|
+
"""
|
|
200
|
+
dataset = self._find_dataset(dataset)
|
|
201
|
+
process = self._find_process(process)
|
|
202
|
+
if process is None:
|
|
203
|
+
_logger.warning("process {} is no more supervised".format(process))
|
|
204
|
+
return
|
|
205
|
+
if dataset is None:
|
|
206
|
+
_logger.warning("dataset {} is no more supervised".format(dataset))
|
|
207
|
+
if process.process_id in self._dataset_process_states:
|
|
208
|
+
if dataset.short_str() in self._dataset_process_states[process.process_id]:
|
|
209
|
+
return self._dataset_process_states[process.process_id][
|
|
210
|
+
dataset.short_str()
|
|
211
|
+
][2]
|
|
212
|
+
return None
|
|
213
|
+
|
|
214
|
+
def get_dataset_time_stamp(self, dataset, process) -> Union[None, str]:
|
|
215
|
+
"""
|
|
216
|
+
|
|
217
|
+
:param Dataset dataset:
|
|
218
|
+
:param BaseProcess process:
|
|
219
|
+
:return: DatasetState relative to provided process if know
|
|
220
|
+
:rtype: Union[None, DatasetState]
|
|
221
|
+
"""
|
|
222
|
+
dataset = self._find_dataset(dataset)
|
|
223
|
+
process = self._find_process(process)
|
|
224
|
+
if process is None:
|
|
225
|
+
_logger.warning("process {} is no more supervised".format(process))
|
|
226
|
+
return
|
|
227
|
+
if dataset is None:
|
|
228
|
+
_logger.warning("dataset {} is no more supervised".format(dataset))
|
|
229
|
+
if process.process_id in self._dataset_process_states:
|
|
230
|
+
if dataset.short_str() in self._dataset_process_states[process.process_id]:
|
|
231
|
+
return self._dataset_process_states[process.process_id][
|
|
232
|
+
dataset.short_str()
|
|
233
|
+
][1]
|
|
234
|
+
return None
|
|
235
|
+
|
|
236
|
+
def get_dataset_stream(self, dataset, time_stamp=False) -> tuple:
|
|
237
|
+
"""
|
|
238
|
+
|
|
239
|
+
:param Dataset dataset: dataset the stream is focus on
|
|
240
|
+
:param bool time_stamp: if True then return timestamp in the list of
|
|
241
|
+
elements
|
|
242
|
+
:return: stream of (process ID, DatasetState) for a given dataset
|
|
243
|
+
:rtype: tuple of (process ID, DatasetState, [timestamp])
|
|
244
|
+
"""
|
|
245
|
+
stream = []
|
|
246
|
+
for process_id, dataset_states in self._dataset_process_states.items():
|
|
247
|
+
if dataset.short_str() in dataset_states:
|
|
248
|
+
state, _timestamp, _ = dataset_states[dataset.short_str()]
|
|
249
|
+
stream.append((process_id, state, _timestamp))
|
|
250
|
+
# order the stream
|
|
251
|
+
stream = sorted(stream, key=lambda elmt: elmt[2])
|
|
252
|
+
if not time_stamp:
|
|
253
|
+
stream = [s[:-1] for s in stream]
|
|
254
|
+
return tuple(stream)
|
|
255
|
+
|
|
256
|
+
def get_process_history(self, process, time_stamp=False) -> tuple:
|
|
257
|
+
"""
|
|
258
|
+
Return the know history of the process.
|
|
259
|
+
|
|
260
|
+
:param BaseProcess process:
|
|
261
|
+
:param bool time_stamp: if True then return timestamp in the list of
|
|
262
|
+
elements
|
|
263
|
+
:return: tuple of (dataset id, state, [timestamp])
|
|
264
|
+
:rtype: tuple
|
|
265
|
+
"""
|
|
266
|
+
history = []
|
|
267
|
+
if process.process_id in self._dataset_process_states:
|
|
268
|
+
dataset_states = self._dataset_process_states[process.process_id]
|
|
269
|
+
for dataset_id, info in dataset_states.items():
|
|
270
|
+
state, _timestamp, details = info
|
|
271
|
+
history.append((dataset_id, state, _timestamp))
|
|
272
|
+
|
|
273
|
+
history = sorted(history, key=lambda elmt: elmt[2])
|
|
274
|
+
if not time_stamp:
|
|
275
|
+
history = [s[:-1] for s in history]
|
|
276
|
+
return tuple(history)
|
|
277
|
+
|
|
278
|
+
def updated(self):
|
|
279
|
+
"""Function 'open' for monckey patch"""
|
|
280
|
+
with self.lock:
|
|
281
|
+
for callback in self._updateCallback:
|
|
282
|
+
callback()
|
|
283
|
+
|
|
284
|
+
def add_update_callback(self, callback) -> None:
|
|
285
|
+
"""
|
|
286
|
+
|
|
287
|
+
:param callback: add a callback to be trigger when dataset state change
|
|
288
|
+
"""
|
|
289
|
+
with self.lock:
|
|
290
|
+
self._updateCallback.add(callback)
|
|
291
|
+
|
|
292
|
+
def remove_update_callback(self, callback) -> None:
|
|
293
|
+
"""
|
|
294
|
+
|
|
295
|
+
:param callback: remove a callback from the stack of callback to be
|
|
296
|
+
call when dataset state change
|
|
297
|
+
"""
|
|
298
|
+
with self.lock:
|
|
299
|
+
if callback in self._updateCallback:
|
|
300
|
+
self._updateCallback.remove(callback)
|
|
301
|
+
|
|
302
|
+
def add_new_process_callback(self, callback):
|
|
303
|
+
self._newProcessCallback.add(callback)
|
|
304
|
+
|
|
305
|
+
def remove_new_process_callback(self, callback):
|
|
306
|
+
if callback in self._newProcessCallback:
|
|
307
|
+
self._newProcessCallback.remove(callback)
|
|
308
|
+
|
|
309
|
+
def clear(self):
|
|
310
|
+
"""
|
|
311
|
+
clear registered processes and dataset states
|
|
312
|
+
|
|
313
|
+
:return:
|
|
314
|
+
"""
|
|
315
|
+
self._processes = {}
|
|
316
|
+
self._dataset_process_states = {}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
# /*##########################################################################
|
|
3
|
+
#
|
|
4
|
+
# Copyright (c) 2017 European Synchrotron Radiation Facility
|
|
5
|
+
#
|
|
6
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
# of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
# in the Software without restriction, including without limitation the rights
|
|
9
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
# copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
# furnished to do so, subject to the following conditions:
|
|
12
|
+
#
|
|
13
|
+
# The above copyright notice and this permission notice shall be included in
|
|
14
|
+
# all copies or substantial portions of the Software.
|
|
15
|
+
#
|
|
16
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
22
|
+
# THE SOFTWARE.
|
|
23
|
+
#
|
|
24
|
+
# ###########################################################################*/
|
|
25
|
+
|
|
26
|
+
__authors__ = ["H.Payno"]
|
|
27
|
+
__license__ = "MIT"
|
|
28
|
+
__date__ = "02/11/2020"
|
|
29
|
+
|
|
30
|
+
import unittest
|
|
31
|
+
|
|
32
|
+
from . import test_manager
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def suite():
|
|
36
|
+
test_suite = unittest.TestSuite()
|
|
37
|
+
test_suite.addTest(test_manager.suite())
|
|
38
|
+
|
|
39
|
+
return test_suite
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
# /*##########################################################################
|
|
3
|
+
#
|
|
4
|
+
# Copyright (c) 2016-2017 European Synchrotron Radiation Facility
|
|
5
|
+
#
|
|
6
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
# of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
# in the Software without restriction, including without limitation the rights
|
|
9
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
# copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
# furnished to do so, subject to the following conditions:
|
|
12
|
+
#
|
|
13
|
+
# The above copyright notice and this permission notice shall be included in
|
|
14
|
+
# all copies or substantial portions of the Software.
|
|
15
|
+
#
|
|
16
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
22
|
+
# THE SOFTWARE.
|
|
23
|
+
#
|
|
24
|
+
# ###########################################################################*/
|
|
25
|
+
|
|
26
|
+
__authors__ = ["H. Payno"]
|
|
27
|
+
__license__ = "MIT"
|
|
28
|
+
__date__ = "02/11/2020"
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
import unittest
|
|
32
|
+
from processview.core.superviseprocess import SuperviseProcess
|
|
33
|
+
from processview.core.manager import ProcessManager
|
|
34
|
+
from processview.core.manager import DatasetState
|
|
35
|
+
from processview.core.dataset import Dataset
|
|
36
|
+
import gc
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class TestProcessManager(unittest.TestCase):
|
|
40
|
+
"""
|
|
41
|
+
test ProcessManager
|
|
42
|
+
"""
|
|
43
|
+
|
|
44
|
+
def testRegisterProcess(self):
|
|
45
|
+
"""insure registration and unregistration are working"""
|
|
46
|
+
manager = ProcessManager()
|
|
47
|
+
manager.clear()
|
|
48
|
+
self.assertEqual(len(manager.get_processes()), 0)
|
|
49
|
+
p1 = SuperviseProcess()
|
|
50
|
+
self.assertEqual(len(manager.get_processes()), 1)
|
|
51
|
+
p1 = None
|
|
52
|
+
gc.collect()
|
|
53
|
+
self.assertEqual(len(manager.get_processes()), 0)
|
|
54
|
+
p1 = SuperviseProcess()
|
|
55
|
+
p2 = SuperviseProcess()
|
|
56
|
+
self.assertEqual(len(manager.get_processes()), 2)
|
|
57
|
+
self.assertEqual(len(ProcessManager().get_processes()), 2)
|
|
58
|
+
self.assertTrue(p1 in manager.get_processes())
|
|
59
|
+
self.assertTrue(p2 in manager.get_processes())
|
|
60
|
+
p1 = None
|
|
61
|
+
p2 = None
|
|
62
|
+
gc.collect()
|
|
63
|
+
self.assertEqual(len(manager.get_processes()), 0)
|
|
64
|
+
|
|
65
|
+
def testProcessStatesUpdate(self):
|
|
66
|
+
"""insure providing states works well"""
|
|
67
|
+
p1 = SuperviseProcess(name="sp1")
|
|
68
|
+
p2 = SuperviseProcess(name="sp1")
|
|
69
|
+
manager = ProcessManager()
|
|
70
|
+
manager.clear()
|
|
71
|
+
scan_1 = _DummyScan("scan1")
|
|
72
|
+
scan_2 = _DummyScan("scan2")
|
|
73
|
+
manager.notify_dataset_state(
|
|
74
|
+
dataset=scan_1, state=DatasetState.PENDING, process=p1
|
|
75
|
+
)
|
|
76
|
+
manager.notify_dataset_state(
|
|
77
|
+
dataset=scan_2, state=DatasetState.SUCCEED, process=p1
|
|
78
|
+
)
|
|
79
|
+
manager.notify_dataset_state(
|
|
80
|
+
dataset=scan_2, state=DatasetState.FAILED, process=p2
|
|
81
|
+
)
|
|
82
|
+
# test 'getScanState'
|
|
83
|
+
self.assertEqual(
|
|
84
|
+
manager.get_dataset_state(dataset=scan_2, process=p2), DatasetState.FAILED
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
self.assertEqual(manager.get_dataset_state(dataset=scan_1, process=p2), None)
|
|
88
|
+
|
|
89
|
+
# test 'getScanStream'
|
|
90
|
+
self.assertEqual(
|
|
91
|
+
manager.get_dataset_stream(dataset=scan_2, time_stamp=False),
|
|
92
|
+
(
|
|
93
|
+
(p1.process_id, DatasetState.SUCCEED),
|
|
94
|
+
(p2.process_id, DatasetState.FAILED),
|
|
95
|
+
),
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
# test 'getProcessHistory'
|
|
99
|
+
self.assertEqual(
|
|
100
|
+
manager.get_process_history(process=p1),
|
|
101
|
+
((str(scan_1), DatasetState.PENDING), (str(scan_2), DatasetState.SUCCEED)),
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
class _DummyScan(Dataset):
|
|
106
|
+
def __init__(self, name):
|
|
107
|
+
super().__init__()
|
|
108
|
+
self.name = name
|
|
109
|
+
|
|
110
|
+
def __str__(self) -> str:
|
|
111
|
+
return self.name
|
|
112
|
+
|
|
113
|
+
def short_str(self):
|
|
114
|
+
return self.name
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def suite():
|
|
118
|
+
test_suite = unittest.TestSuite()
|
|
119
|
+
for ui in (TestProcessManager,):
|
|
120
|
+
test_suite.addTest(unittest.defaultTestLoader.loadTestsFromTestCase(ui))
|
|
121
|
+
return test_suite
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
# /*##########################################################################
|
|
3
|
+
#
|
|
4
|
+
# Copyright (c) 2016-2018 European Synchrotron Radiation Facility
|
|
5
|
+
#
|
|
6
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
# of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
# in the Software without restriction, including without limitation the rights
|
|
9
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
# copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
# furnished to do so, subject to the following conditions:
|
|
12
|
+
#
|
|
13
|
+
# The above copyright notice and this permission notice shall be included in
|
|
14
|
+
# all copies or substantial portions of the Software.
|
|
15
|
+
#
|
|
16
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
22
|
+
# THE SOFTWARE.
|
|
23
|
+
#
|
|
24
|
+
# ###########################################################################*/
|
|
25
|
+
|
|
26
|
+
__authors__ = ["H. Payno"]
|
|
27
|
+
__license__ = "MIT"
|
|
28
|
+
__date__ = "29/01/2021"
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
from numpy.distutils.misc_util import Configuration
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def configuration(parent_package="", top_path=None):
|
|
35
|
+
config = Configuration("core", parent_package, top_path)
|
|
36
|
+
config.add_subpackage("manager")
|
|
37
|
+
config.add_subpackage("test")
|
|
38
|
+
return config
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
if __name__ == "__main__":
|
|
42
|
+
from numpy.distutils.core import setup
|
|
43
|
+
|
|
44
|
+
setup(configuration=configuration)
|