karabo.native 2.21.3__py3-none-any.whl

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.
Files changed (167) hide show
  1. karabo/__init__.py +1 -0
  2. karabo/_version.py +1 -0
  3. karabo/common/__init__.py +15 -0
  4. karabo/common/alarm_conditions.py +120 -0
  5. karabo/common/api.py +73 -0
  6. karabo/common/const.py +374 -0
  7. karabo/common/decorators.py +95 -0
  8. karabo/common/display_types.py +31 -0
  9. karabo/common/enums.py +53 -0
  10. karabo/common/module.py +37 -0
  11. karabo/common/packaging/__init__.py +15 -0
  12. karabo/common/packaging/tests/__init__.py +15 -0
  13. karabo/common/packaging/tests/test_utils.py +33 -0
  14. karabo/common/packaging/utils.py +48 -0
  15. karabo/common/project/__init__.py +15 -0
  16. karabo/common/project/api.py +32 -0
  17. karabo/common/project/bases.py +66 -0
  18. karabo/common/project/cache.py +145 -0
  19. karabo/common/project/const.py +27 -0
  20. karabo/common/project/device.py +185 -0
  21. karabo/common/project/device_config.py +35 -0
  22. karabo/common/project/lazy.py +74 -0
  23. karabo/common/project/macro.py +64 -0
  24. karabo/common/project/model.py +42 -0
  25. karabo/common/project/server.py +110 -0
  26. karabo/common/project/tests/__init__.py +15 -0
  27. karabo/common/project/tests/test_base.py +47 -0
  28. karabo/common/project/tests/test_cache.py +31 -0
  29. karabo/common/project/tests/test_device.py +155 -0
  30. karabo/common/project/tests/test_macro.py +27 -0
  31. karabo/common/project/tests/test_model.py +35 -0
  32. karabo/common/project/tests/test_server.py +234 -0
  33. karabo/common/project/tests/test_utils.py +246 -0
  34. karabo/common/project/utils.py +220 -0
  35. karabo/common/sanity_check.py +200 -0
  36. karabo/common/savable.py +177 -0
  37. karabo/common/scenemodel/__init__.py +15 -0
  38. karabo/common/scenemodel/api.py +78 -0
  39. karabo/common/scenemodel/bases.py +136 -0
  40. karabo/common/scenemodel/const.py +101 -0
  41. karabo/common/scenemodel/exceptions.py +21 -0
  42. karabo/common/scenemodel/generic_scenes.py +198 -0
  43. karabo/common/scenemodel/io_utils.py +161 -0
  44. karabo/common/scenemodel/layouts.py +216 -0
  45. karabo/common/scenemodel/model.py +189 -0
  46. karabo/common/scenemodel/modelio.py +57 -0
  47. karabo/common/scenemodel/registry.py +180 -0
  48. karabo/common/scenemodel/shapes.py +312 -0
  49. karabo/common/scenemodel/tests/__init__.py +15 -0
  50. karabo/common/scenemodel/tests/data/all.svg +234 -0
  51. karabo/common/scenemodel/tests/data/all2.svg +1 -0
  52. karabo/common/scenemodel/tests/data/inkscape/all.svg +725 -0
  53. karabo/common/scenemodel/tests/data/inkscape/drawing.svg +234 -0
  54. karabo/common/scenemodel/tests/data/inkscape/funny_mix.svg +157 -0
  55. karabo/common/scenemodel/tests/data/inkscape/shapes.svg +103 -0
  56. karabo/common/scenemodel/tests/data/legacy/icon-widgets.svg +1 -0
  57. karabo/common/scenemodel/tests/data/legacy/icon_data/flag.svg +32 -0
  58. karabo/common/scenemodel/tests/data/version_one_0.svg +76 -0
  59. karabo/common/scenemodel/tests/data/version_one_1.svg +62 -0
  60. karabo/common/scenemodel/tests/data/version_one_2.svg +42 -0
  61. karabo/common/scenemodel/tests/data/version_one_3.svg +12 -0
  62. karabo/common/scenemodel/tests/data/version_one_4.svg +22 -0
  63. karabo/common/scenemodel/tests/data/version_one_5.svg +18 -0
  64. karabo/common/scenemodel/tests/test_data_model_structure.py +95 -0
  65. karabo/common/scenemodel/tests/test_graph_images.py +105 -0
  66. karabo/common/scenemodel/tests/test_graph_plots.py +170 -0
  67. karabo/common/scenemodel/tests/test_io.py +370 -0
  68. karabo/common/scenemodel/tests/test_registry.py +80 -0
  69. karabo/common/scenemodel/tests/test_shapes.py +193 -0
  70. karabo/common/scenemodel/tests/test_unknown_widget_model.py +56 -0
  71. karabo/common/scenemodel/tests/test_widgets_complex.py +194 -0
  72. karabo/common/scenemodel/tests/test_widgets_icon.py +120 -0
  73. karabo/common/scenemodel/tests/test_widgets_image.py +72 -0
  74. karabo/common/scenemodel/tests/test_widgets_links.py +98 -0
  75. karabo/common/scenemodel/tests/test_widgets_plot.py +82 -0
  76. karabo/common/scenemodel/tests/test_widgets_simple.py +310 -0
  77. karabo/common/scenemodel/tests/test_widgets_statefulicon.py +31 -0
  78. karabo/common/scenemodel/tests/test_widgets_tools.py +27 -0
  79. karabo/common/scenemodel/tests/test_widgets_vacuum.py +30 -0
  80. karabo/common/scenemodel/tests/utils.py +57 -0
  81. karabo/common/scenemodel/widgets/__init__.py +15 -0
  82. karabo/common/scenemodel/widgets/complex.py +394 -0
  83. karabo/common/scenemodel/widgets/graph_image.py +213 -0
  84. karabo/common/scenemodel/widgets/graph_plots.py +451 -0
  85. karabo/common/scenemodel/widgets/graph_utils.py +304 -0
  86. karabo/common/scenemodel/widgets/icon.py +232 -0
  87. karabo/common/scenemodel/widgets/links.py +134 -0
  88. karabo/common/scenemodel/widgets/plot.py +61 -0
  89. karabo/common/scenemodel/widgets/simple.py +589 -0
  90. karabo/common/scenemodel/widgets/statefulicon.py +51 -0
  91. karabo/common/scenemodel/widgets/tools.py +91 -0
  92. karabo/common/scenemodel/widgets/vacuum.py +79 -0
  93. karabo/common/services.py +28 -0
  94. karabo/common/states.py +310 -0
  95. karabo/common/tests/__init__.py +15 -0
  96. karabo/common/tests/test_alarm_condition.py +52 -0
  97. karabo/common/tests/test_const.py +160 -0
  98. karabo/common/tests/test_decorators.py +69 -0
  99. karabo/common/tests/test_macro_sanity_check.py +258 -0
  100. karabo/common/tests/test_module.py +42 -0
  101. karabo/common/tests/test_savable.py +137 -0
  102. karabo/common/tests/test_services.py +20 -0
  103. karabo/common/tests/test_states.py +239 -0
  104. karabo/common/tests/test_traits.py +59 -0
  105. karabo/common/tests/test_util.py +36 -0
  106. karabo/common/utils.py +107 -0
  107. karabo/native/__init__.py +25 -0
  108. karabo/native/data/__init__.py +38 -0
  109. karabo/native/data/bin_reader.py +201 -0
  110. karabo/native/data/bin_writer.py +171 -0
  111. karabo/native/data/compare.py +120 -0
  112. karabo/native/data/enums.py +283 -0
  113. karabo/native/data/hash.py +745 -0
  114. karabo/native/data/str_converter.py +247 -0
  115. karabo/native/data/tests/__init__.py +15 -0
  116. karabo/native/data/tests/test_compare.py +120 -0
  117. karabo/native/data/tests/test_converters.py +161 -0
  118. karabo/native/data/tests/test_hash.py +643 -0
  119. karabo/native/data/tests/test_schema.py +167 -0
  120. karabo/native/data/tests/test_serializers.py +326 -0
  121. karabo/native/data/tests/test_timestamp.py +123 -0
  122. karabo/native/data/tests/test_utils.py +284 -0
  123. karabo/native/data/timestamp.py +178 -0
  124. karabo/native/data/typenums.py +98 -0
  125. karabo/native/data/utils.py +236 -0
  126. karabo/native/data/xml_reader.py +284 -0
  127. karabo/native/data/xml_writer.py +164 -0
  128. karabo/native/exceptions.py +27 -0
  129. karabo/native/project/__init__.py +20 -0
  130. karabo/native/project/api.py +19 -0
  131. karabo/native/project/convert.py +98 -0
  132. karabo/native/project/io.py +323 -0
  133. karabo/native/project/old.py +375 -0
  134. karabo/native/project/tests/__init__.py +15 -0
  135. karabo/native/project/tests/test_io.py +270 -0
  136. karabo/native/schema/__init__.py +32 -0
  137. karabo/native/schema/basetypes.py +911 -0
  138. karabo/native/schema/configurable.py +490 -0
  139. karabo/native/schema/descriptors.py +1361 -0
  140. karabo/native/schema/image_data.py +282 -0
  141. karabo/native/schema/jsonencoder.py +54 -0
  142. karabo/native/schema/ndarray.py +162 -0
  143. karabo/native/schema/tests/__init__.py +15 -0
  144. karabo/native/schema/tests/basetypes_test.py +820 -0
  145. karabo/native/schema/tests/cast_test.py +254 -0
  146. karabo/native/schema/tests/configurable_test.py +1826 -0
  147. karabo/native/schema/tests/descriptor_test.py +1321 -0
  148. karabo/native/schema/tests/json_test.py +57 -0
  149. karabo/native/schema/tests/ufunc_test.py +2106 -0
  150. karabo/native/schema/tests/utils.py +29 -0
  151. karabo/native/schema/tests/utils_test.py +270 -0
  152. karabo/native/schema/utils.py +217 -0
  153. karabo/native/tests/__init__.py +15 -0
  154. karabo/native/tests/time_mixin_test.py +89 -0
  155. karabo/native/tests/weak_test.py +58 -0
  156. karabo/native/time_mixin.py +109 -0
  157. karabo/native/weak.py +53 -0
  158. karabo/testing/__init__.py +15 -0
  159. karabo/testing/import_checker.py +91 -0
  160. karabo/testing/resources/reference.krb +0 -0
  161. karabo/testing/utils.py +127 -0
  162. karabo/version.py +1 -0
  163. karabo_native-2.21.3.dist-info/METADATA +46 -0
  164. karabo_native-2.21.3.dist-info/RECORD +167 -0
  165. karabo_native-2.21.3.dist-info/WHEEL +5 -0
  166. karabo_native-2.21.3.dist-info/licenses/LICENSE.md +355 -0
  167. karabo_native-2.21.3.dist-info/top_level.txt +1 -0
karabo/__init__.py ADDED
@@ -0,0 +1 @@
1
+ __version__ = '2.21.3'
karabo/_version.py ADDED
@@ -0,0 +1 @@
1
+ version = '2.21.3'
@@ -0,0 +1,15 @@
1
+ # This file is part of Karabo.
2
+ #
3
+ # http://www.karabo.eu
4
+ #
5
+ # Copyright (C) European XFEL GmbH Schenefeld. All rights reserved.
6
+ #
7
+ # Karabo is free software: you can redistribute it and/or modify it under
8
+ # the terms of the MPL-2 Mozilla Public License.
9
+ #
10
+ # You should have received a copy of the MPL-2 Public License along with
11
+ # Karabo. If not, see <https://www.mozilla.org/en-US/MPL/2.0/>.
12
+ #
13
+ # Karabo is distributed in the hope that it will be useful, but WITHOUT ANY
14
+ # WARRANTY; without even the implied warranty of MERCHANTABILITY or
15
+ # FITNESS FOR A PARTICULAR PURPOSE.
@@ -0,0 +1,120 @@
1
+ # This file is part of Karabo.
2
+ #
3
+ # http://www.karabo.eu
4
+ #
5
+ # Copyright (C) European XFEL GmbH Schenefeld. All rights reserved.
6
+ #
7
+ # Karabo is free software: you can redistribute it and/or modify it under
8
+ # the terms of the MPL-2 Mozilla Public License.
9
+ #
10
+ # You should have received a copy of the MPL-2 Public License along with
11
+ # Karabo. If not, see <https://www.mozilla.org/en-US/MPL/2.0/>.
12
+ #
13
+ # Karabo is distributed in the hope that it will be useful, but WITHOUT ANY
14
+ # WARRANTY; without even the implied warranty of MERCHANTABILITY or
15
+ # FITNESS FOR A PARTICULAR PURPOSE.
16
+ from enum import Enum
17
+ from functools import total_ordering
18
+
19
+
20
+ @total_ordering
21
+ class AlarmCondition(Enum):
22
+ """A class for unified alarm conditions.
23
+
24
+ Alarms are categorized by severity, which can either be none, warn, alarm
25
+ or interlock. Interlock is the most severe condition.
26
+ """
27
+
28
+ NONE = "none"
29
+ WARN = "warn"
30
+ WARN_LOW = "warnLow"
31
+ WARN_HIGH = "warnHigh"
32
+ WARN_VARIANCE_LOW = "warnVarianceLow"
33
+ WARN_VARIANCE_HIGH = "warnVarianceHigh"
34
+ ALARM = "alarm"
35
+ ALARM_LOW = "alarmLow"
36
+ ALARM_HIGH = "alarmHigh"
37
+ ALARM_VARIANCE_LOW = "alarmVarianceLow"
38
+ ALARM_VARIANCE_HIGH = "alarmVarianceHigh"
39
+ INTERLOCK = "interlock"
40
+
41
+ @staticmethod
42
+ def criticalityList():
43
+ """Return the severity list
44
+
45
+ severity increases from left to right
46
+ :return: an list with alarm severities
47
+ """
48
+ return [
49
+ AlarmCondition.NONE,
50
+ AlarmCondition.WARN,
51
+ AlarmCondition.ALARM,
52
+ AlarmCondition.INTERLOCK,
53
+ ]
54
+
55
+ def criticalityLevel(self):
56
+ """Return the severity level of this alarm condition"""
57
+ for p in AlarmCondition.criticalityList():
58
+ if p.value in self.value:
59
+ return p
60
+ return self
61
+
62
+ @staticmethod
63
+ def returnMostSignificant(conditionList):
64
+ """Returns the most severe/significant condition
65
+
66
+ Returns the most severe/significant condition in the given list of
67
+ conditions
68
+ :param conditionList: a list containing alarm conditions
69
+ :return: The most severe condition in the list
70
+ """
71
+ if len(conditionList) == 0:
72
+ return AlarmCondition.NONE
73
+ else:
74
+ s = conditionList[0]
75
+ for c in conditionList:
76
+ s = s.returnMoreSignificant(c)
77
+ return s.criticalityLevel()
78
+
79
+ def returnMoreSignificant(self, other):
80
+ """Return the more significant of this and the other condition
81
+
82
+ :param other: The condition to compare against
83
+ """
84
+ if self.criticalityList().index(
85
+ self.criticalityLevel()
86
+ ) > self.criticalityList().index(other.criticalityLevel()):
87
+ return self
88
+ else:
89
+ return other
90
+
91
+ @staticmethod
92
+ def fromString(name):
93
+ """Return an alarm condition from its stringified representation."""
94
+ return AlarmCondition(name)
95
+
96
+ def asString(self):
97
+ """Return the string representation of the alarm condition"""
98
+ return self.value
99
+
100
+ def asBaseString(self):
101
+ """Return the severity level, e.g. base of the alarmcondtions"""
102
+ return self.parent().value
103
+
104
+ def isSameCriticality(self, other):
105
+ """Return whether *other* is of same criticality/severity
106
+
107
+ Return whether this alarm condition is of same criticality/severity
108
+ as *other*
109
+ :param other: the alarm condition to compare against
110
+ """
111
+ return self.criticalityList().index(
112
+ self.criticalityLevel()
113
+ ) == self.criticalityList().index(other.criticalityLevel())
114
+
115
+ def __lt__(self, other):
116
+ return self.level < other.level
117
+
118
+
119
+ for i, condition in enumerate(AlarmCondition.__members__.values()):
120
+ condition.level = i
karabo/common/api.py ADDED
@@ -0,0 +1,73 @@
1
+ # This file is part of Karabo.
2
+ #
3
+ # http://www.karabo.eu
4
+ #
5
+ # Copyright (C) European XFEL GmbH Schenefeld. All rights reserved.
6
+ #
7
+ # Karabo is free software: you can redistribute it and/or modify it under
8
+ # the terms of the MPL-2 Mozilla Public License.
9
+ #
10
+ # You should have received a copy of the MPL-2 Public License along with
11
+ # Karabo. If not, see <https://www.mozilla.org/en-US/MPL/2.0/>.
12
+ #
13
+ # Karabo is distributed in the hope that it will be useful, but WITHOUT ANY
14
+ # WARRANTY; without even the implied warranty of MERCHANTABILITY or
15
+ # FITNESS FOR A PARTICULAR PURPOSE.
16
+ # flake8: noqa
17
+ from .alarm_conditions import AlarmCondition
18
+ from .const import (
19
+ KARABO_ALARM_HIGH, KARABO_ALARM_LOW, KARABO_ALARM_VARIANCE_HIGH,
20
+ KARABO_ALARM_VARIANCE_LOW, KARABO_CLASS_ID_ALARM, KARABO_CLASS_ID_STATE,
21
+ KARABO_EDITABLE_ATTRIBUTES, KARABO_LOGGER_CONTENT_DEFAULT,
22
+ KARABO_RUNTIME_ATTRIBUTES_MDL, KARABO_RUNTIME_SCHEMA_UPDATE,
23
+ KARABO_SCHEMA_ABSOLUTE_ERROR, KARABO_SCHEMA_ACCESS_MODE,
24
+ KARABO_SCHEMA_ALARM_ACK, KARABO_SCHEMA_ALARM_INFO, KARABO_SCHEMA_ALIAS,
25
+ KARABO_SCHEMA_ALLOWED_STATES, KARABO_SCHEMA_ARCHIVE_POLICY,
26
+ KARABO_SCHEMA_ASSIGNMENT, KARABO_SCHEMA_ATTRIBUTES, KARABO_SCHEMA_CLASS_ID,
27
+ KARABO_SCHEMA_DAQ_DATA_TYPE, KARABO_SCHEMA_DAQ_POLICY,
28
+ KARABO_SCHEMA_DEFAULT_SCENE, KARABO_SCHEMA_DEFAULT_VALUE,
29
+ KARABO_SCHEMA_DESCRIPTION, KARABO_SCHEMA_DISPLAY_TYPE,
30
+ KARABO_SCHEMA_DISPLAYED_NAME, KARABO_SCHEMA_ENABLE_ROLLING_STATS,
31
+ KARABO_SCHEMA_LEAF_TYPE, KARABO_SCHEMA_MAX, KARABO_SCHEMA_MAX_EXC,
32
+ KARABO_SCHEMA_MAX_INC, KARABO_SCHEMA_MAX_SIZE,
33
+ KARABO_SCHEMA_METRIC_PREFIX_ENUM, KARABO_SCHEMA_METRIC_PREFIX_NAME,
34
+ KARABO_SCHEMA_METRIC_PREFIX_SYMBOL, KARABO_SCHEMA_MIN,
35
+ KARABO_SCHEMA_MIN_EXC, KARABO_SCHEMA_MIN_INC, KARABO_SCHEMA_MIN_SIZE,
36
+ KARABO_SCHEMA_NODE_TYPE, KARABO_SCHEMA_OPTIONS, KARABO_SCHEMA_OVERWRITE,
37
+ KARABO_SCHEMA_REGEX, KARABO_SCHEMA_RELATIVE_ERROR,
38
+ KARABO_SCHEMA_REQUIRED_ACCESS_LEVEL, KARABO_SCHEMA_ROLLING_STATS_EVAL,
39
+ KARABO_SCHEMA_ROW_SCHEMA, KARABO_SCHEMA_SKIP_VALIDATION,
40
+ KARABO_SCHEMA_TAGS, KARABO_SCHEMA_UNIT_ENUM, KARABO_SCHEMA_UNIT_NAME,
41
+ KARABO_SCHEMA_UNIT_SYMBOL, KARABO_SCHEMA_VALUE_TYPE, KARABO_TYPE_BOOL,
42
+ KARABO_TYPE_BYTE_ARRAY, KARABO_TYPE_CHAR, KARABO_TYPE_COMPLEX_DOUBLE,
43
+ KARABO_TYPE_COMPLEX_FLOAT, KARABO_TYPE_DOUBLE, KARABO_TYPE_FLOAT,
44
+ KARABO_TYPE_HASH, KARABO_TYPE_INT8, KARABO_TYPE_INT16, KARABO_TYPE_INT32,
45
+ KARABO_TYPE_INT64, KARABO_TYPE_NONE, KARABO_TYPE_SCHEMA,
46
+ KARABO_TYPE_STRING, KARABO_TYPE_UINT8, KARABO_TYPE_UINT16,
47
+ KARABO_TYPE_UINT32, KARABO_TYPE_UINT64, KARABO_TYPE_VECTOR_BOOL,
48
+ KARABO_TYPE_VECTOR_CHAR, KARABO_TYPE_VECTOR_COMPLEX_DOUBLE,
49
+ KARABO_TYPE_VECTOR_COMPLEX_FLOAT, KARABO_TYPE_VECTOR_DOUBLE,
50
+ KARABO_TYPE_VECTOR_FLOAT, KARABO_TYPE_VECTOR_HASH, KARABO_TYPE_VECTOR_INT8,
51
+ KARABO_TYPE_VECTOR_INT16, KARABO_TYPE_VECTOR_INT32,
52
+ KARABO_TYPE_VECTOR_INT64, KARABO_TYPE_VECTOR_STRING,
53
+ KARABO_TYPE_VECTOR_UINT8, KARABO_TYPE_VECTOR_UINT16,
54
+ KARABO_TYPE_VECTOR_UINT32, KARABO_TYPE_VECTOR_UINT64, KARABO_WARN_HIGH,
55
+ KARABO_WARN_LOW, KARABO_WARN_VARIANCE_HIGH, KARABO_WARN_VARIANCE_LOW)
56
+ from .decorators import karabo_deprecated
57
+ from .display_types import (
58
+ KARABO_SCHEMA_DISPLAY_TYPE_ALARM, KARABO_SCHEMA_DISPLAY_TYPE_BIN,
59
+ KARABO_SCHEMA_DISPLAY_TYPE_BITSET, KARABO_SCHEMA_DISPLAY_TYPE_CURVE,
60
+ KARABO_SCHEMA_DISPLAY_TYPE_DIRECTORY, KARABO_SCHEMA_DISPLAY_TYPE_FILEIN,
61
+ KARABO_SCHEMA_DISPLAY_TYPE_FILEOUT, KARABO_SCHEMA_DISPLAY_TYPE_HEX,
62
+ KARABO_SCHEMA_DISPLAY_TYPE_IMAGEDATA, KARABO_SCHEMA_DISPLAY_TYPE_OCT,
63
+ KARABO_SCHEMA_DISPLAY_TYPE_RUNCONFIGURATOR,
64
+ KARABO_SCHEMA_DISPLAY_TYPE_SCENES, KARABO_SCHEMA_DISPLAY_TYPE_STATE)
65
+ from .enums import Capabilities, InstanceStatus, Interfaces, ServerFlags
66
+ from .module import create_module
67
+ from .sanity_check import has_sub_imports
68
+ from .savable import BaseSavableModel, set_initialized_flag, set_modified_flag
69
+ from .services import (
70
+ KARABO_ALARM_SERVICE, KARABO_CONFIG_MANAGER, KARABO_DAEMON_MANAGER,
71
+ KARABO_LOGBOOK_MANAGER, KARABO_PROJECT_MANAGER)
72
+ from .states import State, StateSignifier
73
+ from .utils import WeakMethodRef, walk_traits_object
karabo/common/const.py ADDED
@@ -0,0 +1,374 @@
1
+ # This file is part of Karabo.
2
+ #
3
+ # http://www.karabo.eu
4
+ #
5
+ # Copyright (C) European XFEL GmbH Schenefeld. All rights reserved.
6
+ #
7
+ # Karabo is free software: you can redistribute it and/or modify it under
8
+ # the terms of the MPL-2 Mozilla Public License.
9
+ #
10
+ # You should have received a copy of the MPL-2 Public License along with
11
+ # Karabo. If not, see <https://www.mozilla.org/en-US/MPL/2.0/>.
12
+ #
13
+ # Karabo is distributed in the hope that it will be useful, but WITHOUT ANY
14
+ # WARRANTY; without even the implied warranty of MERCHANTABILITY or
15
+ # FITNESS FOR A PARTICULAR PURPOSE.
16
+ # Copied from karabo/util/Schema.hh!
17
+ KARABO_SCHEMA_NODE_TYPE = "nodeType"
18
+ KARABO_SCHEMA_LEAF_TYPE = "leafType"
19
+ KARABO_SCHEMA_VALUE_TYPE = "valueType"
20
+ KARABO_SCHEMA_CLASS_ID = "classId"
21
+ KARABO_SCHEMA_DISPLAYED_NAME = "displayedName"
22
+ KARABO_SCHEMA_DESCRIPTION = "description"
23
+ KARABO_SCHEMA_DEFAULT_VALUE = "defaultValue"
24
+ KARABO_SCHEMA_DISPLAY_TYPE = "displayType"
25
+ KARABO_SCHEMA_ACCESS_MODE = "accessMode"
26
+ KARABO_SCHEMA_ALIAS = "alias"
27
+ KARABO_SCHEMA_ALLOWED_STATES = "allowedStates"
28
+ KARABO_SCHEMA_ASSIGNMENT = "assignment"
29
+ KARABO_SCHEMA_TAGS = "tags"
30
+ KARABO_SCHEMA_ROW_SCHEMA = "rowSchema"
31
+ KARABO_SCHEMA_SKIP_VALIDATION = "skipValidation"
32
+ KARABO_SCHEMA_OPTIONS = "options"
33
+ KARABO_SCHEMA_REQUIRED_ACCESS_LEVEL = "requiredAccessLevel"
34
+ KARABO_SCHEMA_UNIT_ENUM = "unitEnum"
35
+ KARABO_SCHEMA_UNIT_NAME = "unitName"
36
+ KARABO_SCHEMA_UNIT_SYMBOL = "unitSymbol"
37
+ KARABO_SCHEMA_METRIC_PREFIX_ENUM = "metricPrefixEnum"
38
+ KARABO_SCHEMA_METRIC_PREFIX_NAME = "metricPrefixName"
39
+ KARABO_SCHEMA_METRIC_PREFIX_SYMBOL = "metricPrefixSymbol"
40
+ KARABO_SCHEMA_MIN_INC = "minInc"
41
+ KARABO_SCHEMA_MAX_INC = "maxInc"
42
+ KARABO_SCHEMA_MIN_EXC = "minExc"
43
+ KARABO_SCHEMA_MAX_EXC = "maxExc"
44
+ KARABO_SCHEMA_RELATIVE_ERROR = "relativeError"
45
+ KARABO_SCHEMA_ABSOLUTE_ERROR = "absoluteError"
46
+ KARABO_SCHEMA_MIN_SIZE = "minSize"
47
+ KARABO_SCHEMA_MAX_SIZE = "maxSize"
48
+ KARABO_SCHEMA_ENABLE_ROLLING_STATS = "enableRollingStats"
49
+ KARABO_SCHEMA_ROLLING_STATS_EVAL = "rollingStatsEvalInterval"
50
+ KARABO_SCHEMA_ARCHIVE_POLICY = "archivePolicy"
51
+ KARABO_SCHEMA_MIN = "min"
52
+ KARABO_SCHEMA_MAX = "max"
53
+ KARABO_SCHEMA_OVERWRITE = "overwrite"
54
+ KARABO_SCHEMA_ALARM_ACK = "alarmNeedsAck"
55
+ KARABO_SCHEMA_ALARM_INFO = "alarmInfo"
56
+ KARABO_RUNTIME_SCHEMA_UPDATE = "runtimeSchemaUpdates"
57
+ KARABO_SCHEMA_DAQ_DATA_TYPE = "daqDataType"
58
+ KARABO_SCHEMA_DAQ_POLICY = "daqPolicy"
59
+ KARABO_SCHEMA_REGEX = "regex"
60
+
61
+ # Fixed classId definitions
62
+
63
+ KARABO_CLASS_ID_STATE = "State"
64
+ KARABO_CLASS_ID_ALARM = "AlarmCondition"
65
+
66
+ # These are from AlarmConditions.hh, but they also apply to schemata
67
+ KARABO_WARN_LOW = "warnLow"
68
+ KARABO_WARN_HIGH = "warnHigh"
69
+ KARABO_ALARM_LOW = "alarmLow"
70
+ KARABO_ALARM_HIGH = "alarmHigh"
71
+ KARABO_WARN_VARIANCE_LOW = "warnVarianceLow"
72
+ KARABO_WARN_VARIANCE_HIGH = "warnVarianceHigh"
73
+ KARABO_ALARM_VARIANCE_LOW = "alarmVarianceLow"
74
+ KARABO_ALARM_VARIANCE_HIGH = "alarmVarianceHigh"
75
+
76
+ # The default scene name to be used
77
+ KARABO_SCHEMA_DEFAULT_SCENE = "scene"
78
+
79
+ # A tuple which defines the ordering of the above attributes
80
+ KARABO_SCHEMA_ATTRIBUTES = (
81
+ KARABO_SCHEMA_DISPLAYED_NAME,
82
+ KARABO_SCHEMA_DESCRIPTION,
83
+ KARABO_SCHEMA_DEFAULT_VALUE,
84
+ KARABO_SCHEMA_DISPLAY_TYPE,
85
+ KARABO_SCHEMA_ACCESS_MODE,
86
+ KARABO_WARN_LOW,
87
+ KARABO_WARN_HIGH,
88
+ KARABO_ALARM_LOW,
89
+ KARABO_ALARM_HIGH,
90
+ KARABO_WARN_VARIANCE_LOW,
91
+ KARABO_WARN_VARIANCE_HIGH,
92
+ KARABO_ALARM_VARIANCE_LOW,
93
+ KARABO_ALARM_VARIANCE_HIGH,
94
+ KARABO_SCHEMA_NODE_TYPE,
95
+ KARABO_SCHEMA_LEAF_TYPE,
96
+ KARABO_SCHEMA_VALUE_TYPE,
97
+ KARABO_SCHEMA_CLASS_ID,
98
+ KARABO_SCHEMA_ALIAS,
99
+ KARABO_SCHEMA_ALLOWED_STATES,
100
+ KARABO_SCHEMA_ASSIGNMENT,
101
+ KARABO_SCHEMA_TAGS,
102
+ KARABO_SCHEMA_ROW_SCHEMA,
103
+ KARABO_SCHEMA_SKIP_VALIDATION,
104
+ KARABO_SCHEMA_OPTIONS,
105
+ KARABO_SCHEMA_REQUIRED_ACCESS_LEVEL,
106
+ KARABO_SCHEMA_UNIT_ENUM,
107
+ KARABO_SCHEMA_UNIT_NAME,
108
+ KARABO_SCHEMA_UNIT_SYMBOL,
109
+ KARABO_SCHEMA_METRIC_PREFIX_ENUM,
110
+ KARABO_SCHEMA_METRIC_PREFIX_NAME,
111
+ KARABO_SCHEMA_METRIC_PREFIX_SYMBOL,
112
+ KARABO_SCHEMA_MIN_INC,
113
+ KARABO_SCHEMA_MAX_INC,
114
+ KARABO_SCHEMA_MIN_EXC,
115
+ KARABO_SCHEMA_MAX_EXC,
116
+ KARABO_SCHEMA_RELATIVE_ERROR,
117
+ KARABO_SCHEMA_ABSOLUTE_ERROR,
118
+ KARABO_SCHEMA_MIN_SIZE,
119
+ KARABO_SCHEMA_MAX_SIZE,
120
+ KARABO_SCHEMA_ENABLE_ROLLING_STATS,
121
+ KARABO_SCHEMA_ROLLING_STATS_EVAL,
122
+ KARABO_SCHEMA_ARCHIVE_POLICY,
123
+ KARABO_SCHEMA_MIN,
124
+ KARABO_SCHEMA_MAX,
125
+ KARABO_SCHEMA_REGEX,
126
+ KARABO_SCHEMA_OVERWRITE,
127
+ KARABO_SCHEMA_ALARM_ACK,
128
+ KARABO_SCHEMA_ALARM_INFO,
129
+ KARABO_RUNTIME_SCHEMA_UPDATE,
130
+ KARABO_SCHEMA_DAQ_DATA_TYPE,
131
+ KARABO_SCHEMA_DAQ_POLICY,
132
+ )
133
+
134
+ # A tuple containing only the attributes which are editable pre-instantiation
135
+ KARABO_EDITABLE_ATTRIBUTES = (
136
+ KARABO_WARN_LOW,
137
+ KARABO_WARN_HIGH,
138
+ KARABO_ALARM_LOW,
139
+ KARABO_ALARM_HIGH,
140
+ )
141
+
142
+ # A tuple containing only the attributes which are editable on run-time
143
+ KARABO_RUNTIME_ATTRIBUTES_MDL = (
144
+ KARABO_SCHEMA_MIN_EXC,
145
+ KARABO_SCHEMA_MAX_EXC,
146
+ KARABO_SCHEMA_MIN_INC,
147
+ KARABO_SCHEMA_MAX_INC,
148
+ KARABO_SCHEMA_ABSOLUTE_ERROR,
149
+ KARABO_SCHEMA_RELATIVE_ERROR,
150
+ KARABO_WARN_LOW,
151
+ KARABO_WARN_HIGH,
152
+ KARABO_ALARM_LOW,
153
+ KARABO_ALARM_HIGH,
154
+ KARABO_SCHEMA_DAQ_POLICY,
155
+ )
156
+
157
+ KARABO_TYPE_BOOL = "BOOL"
158
+ KARABO_TYPE_CHAR = "CHAR"
159
+ KARABO_TYPE_INT8 = "INT8"
160
+ KARABO_TYPE_UINT8 = "UINT8"
161
+ KARABO_TYPE_INT16 = "INT16"
162
+ KARABO_TYPE_UINT16 = "UINT16"
163
+ KARABO_TYPE_INT32 = "INT32"
164
+ KARABO_TYPE_UINT32 = "UINT32"
165
+ KARABO_TYPE_INT64 = "INT64"
166
+ KARABO_TYPE_UINT64 = "UINT64"
167
+ KARABO_TYPE_FLOAT = "FLOAT"
168
+ KARABO_TYPE_DOUBLE = "DOUBLE"
169
+ KARABO_TYPE_COMPLEX_FLOAT = "COMPLEX_FLOAT"
170
+ KARABO_TYPE_COMPLEX_DOUBLE = "COMPLEX_DOUBLE"
171
+ KARABO_TYPE_STRING = "STRING"
172
+ KARABO_TYPE_HASH = "HASH"
173
+ KARABO_TYPE_SCHEMA = "SCHEMA"
174
+ KARABO_TYPE_NONE = "NONE"
175
+ KARABO_TYPE_BYTE_ARRAY = "BYTE_ARRAY"
176
+ KARABO_TYPE_VECTOR_BOOL = "VECTOR_BOOL"
177
+ KARABO_TYPE_VECTOR_CHAR = "VECTOR_CHAR"
178
+ KARABO_TYPE_VECTOR_INT8 = "VECTOR_INT8"
179
+ KARABO_TYPE_VECTOR_UINT8 = "VECTOR_UINT8"
180
+ KARABO_TYPE_VECTOR_INT16 = "VECTOR_INT16"
181
+ KARABO_TYPE_VECTOR_UINT16 = "VECTOR_UINT16"
182
+ KARABO_TYPE_VECTOR_INT32 = "VECTOR_INT32"
183
+ KARABO_TYPE_VECTOR_UINT32 = "VECTOR_UINT32"
184
+ KARABO_TYPE_VECTOR_INT64 = "VECTOR_INT64"
185
+ KARABO_TYPE_VECTOR_UINT64 = "VECTOR_UINT64"
186
+ KARABO_TYPE_VECTOR_DOUBLE = "VECTOR_DOUBLE"
187
+ KARABO_TYPE_VECTOR_FLOAT = "VECTOR_FLOAT"
188
+ KARABO_TYPE_VECTOR_COMPLEX_DOUBLE = "VECTOR_COMPLEX_DOUBLE"
189
+ KARABO_TYPE_VECTOR_COMPLEX_FLOAT = "VECTOR_COMPLEX_FLOAT"
190
+ KARABO_TYPE_VECTOR_STRING = "VECTOR_STRING"
191
+ KARABO_TYPE_VECTOR_HASH = "VECTOR_HASH"
192
+
193
+ KARABO_LOGGER_CONTENT_DEFAULT = 100
194
+
195
+ KARABO_TYPES = (
196
+ KARABO_TYPE_BOOL,
197
+ KARABO_TYPE_CHAR,
198
+ KARABO_TYPE_INT8,
199
+ KARABO_TYPE_UINT8,
200
+ KARABO_TYPE_INT16,
201
+ KARABO_TYPE_UINT16,
202
+ KARABO_TYPE_INT32,
203
+ KARABO_TYPE_UINT32,
204
+ KARABO_TYPE_INT64,
205
+ KARABO_TYPE_UINT64,
206
+ KARABO_TYPE_FLOAT,
207
+ KARABO_TYPE_DOUBLE,
208
+ KARABO_TYPE_COMPLEX_FLOAT,
209
+ KARABO_TYPE_COMPLEX_DOUBLE,
210
+ KARABO_TYPE_STRING,
211
+ KARABO_TYPE_HASH,
212
+ KARABO_TYPE_SCHEMA,
213
+ KARABO_TYPE_NONE,
214
+ KARABO_TYPE_BYTE_ARRAY,
215
+ KARABO_TYPE_VECTOR_BOOL,
216
+ KARABO_TYPE_VECTOR_CHAR,
217
+ KARABO_TYPE_VECTOR_INT8,
218
+ KARABO_TYPE_VECTOR_UINT8,
219
+ KARABO_TYPE_VECTOR_INT16,
220
+ KARABO_TYPE_VECTOR_UINT16,
221
+ KARABO_TYPE_VECTOR_INT32,
222
+ KARABO_TYPE_VECTOR_UINT32,
223
+ KARABO_TYPE_VECTOR_INT64,
224
+ KARABO_TYPE_VECTOR_UINT64,
225
+ KARABO_TYPE_VECTOR_DOUBLE,
226
+ KARABO_TYPE_VECTOR_FLOAT,
227
+ KARABO_TYPE_VECTOR_COMPLEX_DOUBLE,
228
+ KARABO_TYPE_VECTOR_COMPLEX_FLOAT,
229
+ KARABO_TYPE_VECTOR_STRING,
230
+ KARABO_TYPE_VECTOR_HASH,
231
+ )
232
+
233
+ __KARABO_VECTOR_TYPES = (
234
+ KARABO_TYPE_VECTOR_BOOL,
235
+ KARABO_TYPE_VECTOR_INT8,
236
+ KARABO_TYPE_VECTOR_UINT8,
237
+ KARABO_TYPE_VECTOR_INT16,
238
+ KARABO_TYPE_VECTOR_UINT16,
239
+ KARABO_TYPE_VECTOR_INT32,
240
+ KARABO_TYPE_VECTOR_UINT32,
241
+ KARABO_TYPE_VECTOR_INT64,
242
+ KARABO_TYPE_VECTOR_UINT64,
243
+ KARABO_TYPE_VECTOR_DOUBLE,
244
+ KARABO_TYPE_VECTOR_FLOAT,
245
+ KARABO_TYPE_VECTOR_COMPLEX_DOUBLE,
246
+ KARABO_TYPE_VECTOR_COMPLEX_FLOAT,
247
+ KARABO_TYPE_VECTOR_STRING,
248
+ KARABO_TYPE_VECTOR_HASH,
249
+ )
250
+
251
+ __KARABO_INTEGER_TYPES = (
252
+ KARABO_TYPE_INT8,
253
+ KARABO_TYPE_UINT8,
254
+ KARABO_TYPE_INT16,
255
+ KARABO_TYPE_UINT16,
256
+ KARABO_TYPE_INT32,
257
+ KARABO_TYPE_UINT32,
258
+ KARABO_TYPE_INT64,
259
+ KARABO_TYPE_UINT64,
260
+ )
261
+
262
+ __KARABO_SIGNED_INTEGER_TYPES = (
263
+ KARABO_TYPE_INT8,
264
+ KARABO_TYPE_INT16,
265
+ KARABO_TYPE_INT32,
266
+ KARABO_TYPE_INT64,
267
+ )
268
+
269
+ __KARABO_UNSIGNED_INTEGER_TYPES = (
270
+ KARABO_TYPE_UINT8,
271
+ KARABO_TYPE_UINT16,
272
+ KARABO_TYPE_UINT32,
273
+ KARABO_TYPE_UINT64,
274
+ )
275
+
276
+ __KARABO_FLOAT_TYPES = (
277
+ KARABO_TYPE_FLOAT,
278
+ KARABO_TYPE_DOUBLE,
279
+ KARABO_TYPE_COMPLEX_FLOAT,
280
+ KARABO_TYPE_COMPLEX_DOUBLE,
281
+ )
282
+
283
+ __KARABO_VECTOR_INTEGER_TYPES = (
284
+ KARABO_TYPE_VECTOR_INT8,
285
+ KARABO_TYPE_VECTOR_INT16,
286
+ KARABO_TYPE_VECTOR_INT32,
287
+ KARABO_TYPE_VECTOR_INT64,
288
+ KARABO_TYPE_VECTOR_UINT8,
289
+ KARABO_TYPE_VECTOR_UINT16,
290
+ KARABO_TYPE_VECTOR_UINT32,
291
+ KARABO_TYPE_VECTOR_UINT64,
292
+ )
293
+
294
+ __KARABO_VECTOR_FLOAT_TYPES = (
295
+ KARABO_TYPE_VECTOR_DOUBLE,
296
+ KARABO_TYPE_VECTOR_FLOAT,
297
+ KARABO_TYPE_VECTOR_COMPLEX_DOUBLE,
298
+ KARABO_TYPE_VECTOR_COMPLEX_FLOAT,
299
+ )
300
+
301
+
302
+ def is_string_like_type(vtype: str) -> bool:
303
+ """Check if this value type is a string like type"""
304
+ return vtype in (KARABO_TYPE_CHAR, KARABO_TYPE_STRING)
305
+
306
+
307
+ def is_string_type(vtype: str) -> bool:
308
+ """Check if this value type is a string type"""
309
+ return vtype == KARABO_TYPE_STRING
310
+
311
+
312
+ def is_boolean_type(vtype: str) -> bool:
313
+ """Check if this value type is a bool type"""
314
+ return vtype == KARABO_TYPE_BOOL
315
+
316
+
317
+ def is_bytearray_type(vtype: str) -> bool:
318
+ """Check if this value type is a bytearray type"""
319
+ return vtype == KARABO_TYPE_BYTE_ARRAY
320
+
321
+
322
+ def is_vector_bool_type(vtype: str) -> bool:
323
+ """Check if this value type is a vector bool type"""
324
+ return vtype == KARABO_TYPE_VECTOR_BOOL
325
+
326
+
327
+ def is_vector_char_type(vtype: str) -> bool:
328
+ """Check if this value type is a vector char type"""
329
+ return vtype == KARABO_TYPE_VECTOR_CHAR
330
+
331
+
332
+ def is_vector_string_type(vtype: str) -> bool:
333
+ """Check if this value type is a vector string type"""
334
+ return vtype == KARABO_TYPE_VECTOR_STRING
335
+
336
+
337
+ def is_vector_type(vtype: str) -> bool:
338
+ """Check if this value type is a vector type"""
339
+ return vtype in __KARABO_VECTOR_TYPES
340
+
341
+
342
+ def is_float_type(vtype: str) -> bool:
343
+ """Check if this value type is a floating type"""
344
+ return vtype in __KARABO_FLOAT_TYPES
345
+
346
+
347
+ def is_integer_type(vtype: str) -> bool:
348
+ """Check if this value type is an integer type"""
349
+ return vtype in __KARABO_INTEGER_TYPES
350
+
351
+
352
+ def is_unsigned_integer_type(vtype: str) -> bool:
353
+ """Check if this value type belongs to an unsigned integer"""
354
+ return vtype in __KARABO_UNSIGNED_INTEGER_TYPES
355
+
356
+
357
+ def is_signed_integer_type(vtype: str) -> bool:
358
+ """Check if this value type belongs to a signed integer"""
359
+ return vtype in __KARABO_SIGNED_INTEGER_TYPES
360
+
361
+
362
+ def is_vector_integer_type(vtype: str) -> bool:
363
+ """Check if this value type belongs to a vector with integers"""
364
+ return vtype in __KARABO_VECTOR_INTEGER_TYPES
365
+
366
+
367
+ def is_vector_float_type(vtype: str) -> bool:
368
+ """Check if this value type belongs to a vector with float types"""
369
+ return vtype in __KARABO_VECTOR_FLOAT_TYPES
370
+
371
+
372
+ def is_vector_hash_type(vtype: str) -> bool:
373
+ """Check if this value type belongs to a vector hash"""
374
+ return vtype == KARABO_TYPE_VECTOR_HASH
@@ -0,0 +1,95 @@
1
+ #############################################################################
2
+ # Author: <andrea.parenti@xfel.eu>
3
+ # Created on June 13, 2017
4
+ # This file is part of Karabo.
5
+ #
6
+ # http://www.karabo.eu
7
+ #
8
+ # Copyright (C) European XFEL GmbH Schenefeld. All rights reserved.
9
+ #
10
+ # Karabo is free software: you can redistribute it and/or modify it under
11
+ # the terms of the MPL-2 Mozilla Public License.
12
+ #
13
+ # You should have received a copy of the MPL-2 Public License along with
14
+ # Karabo. If not, see <https://www.mozilla.org/en-US/MPL/2.0/>.
15
+ #
16
+ # Karabo is distributed in the hope that it will be useful, but WITHOUT ANY
17
+ # WARRANTY; without even the implied warranty of MERCHANTABILITY or
18
+ # FITNESS FOR A PARTICULAR PURPOSE.
19
+ #############################################################################
20
+ import inspect
21
+ import warnings
22
+ from functools import wraps
23
+ from time import perf_counter
24
+
25
+
26
+ def karabo_deprecated(func):
27
+ """
28
+ This is a decorator which can be used to mark functions
29
+ as deprecated. It will result in a warning being emitted
30
+ when the function is used.
31
+
32
+ ## Usage examples ##
33
+ @karabo_deprecated
34
+ def my_func():
35
+ pass
36
+
37
+ @other_decorators_must_be_upper
38
+ @karabo_deprecated
39
+ def my_func():
40
+ pass
41
+ """
42
+
43
+ @wraps(func)
44
+ def new_func(*args, **kwargs):
45
+ warnings.warn_explicit(
46
+ f"Call to deprecated function {func.__name__}.",
47
+ category=DeprecationWarning,
48
+ filename=func.__code__.co_filename,
49
+ lineno=func.__code__.co_firstlineno + 1,
50
+ )
51
+ return func(*args, **kwargs)
52
+
53
+ return new_func
54
+
55
+
56
+ def timeit(func):
57
+ """A timing decorator"""
58
+
59
+ @wraps(func)
60
+ def wrapper(*args, **kwargs):
61
+ t_start = perf_counter()
62
+ ret = func(*args, **kwargs)
63
+ elapsed = perf_counter() - t_start
64
+ print(f"{func.__name__} took {elapsed}")
65
+ return ret
66
+
67
+ return wrapper
68
+
69
+
70
+ def validate_args(func):
71
+ """A decorator to be used to validate arguments with their annotations
72
+
73
+ Usage examples::
74
+
75
+ @validate_args
76
+ def my_func(param1: str, param2: (float, int)):
77
+ pass
78
+
79
+ The decorator will raise if the function is called with wrong type input.
80
+
81
+ Note: Booleans are also valid for integers!
82
+ """
83
+
84
+ @wraps(func)
85
+ def wrapper(*args):
86
+ argspec = inspect.getfullargspec(func).args
87
+ for index, name in enumerate(argspec):
88
+ if not isinstance(args[index], func.__annotations__[name]):
89
+ raise ValueError(
90
+ "Argument {} got wrong input "
91
+ "type {}".format(name, args[index])
92
+ )
93
+ return func(*args)
94
+
95
+ return wrapper