python3-cyberfusion-queue-support 1.1.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.
@@ -0,0 +1,59 @@
1
+ """Item."""
2
+
3
+ import logging
4
+ from typing import List, Optional
5
+
6
+ from cyberfusion.QueueSupport.interfaces import OutcomeInterface
7
+ from cyberfusion.QueueSupport.items import _Item
8
+ from cyberfusion.QueueSupport.outcomes import (
9
+ SystemdUnitDisableItemDisableOutcome,
10
+ )
11
+ from cyberfusion.SystemdSupport.units import Unit
12
+
13
+ logger = logging.getLogger(__name__)
14
+
15
+
16
+ class SystemdUnitDisableItem(_Item):
17
+ """Represents item."""
18
+
19
+ def __init__(
20
+ self,
21
+ *,
22
+ name: str,
23
+ reference: Optional[str] = None,
24
+ hide_outcomes: bool = False,
25
+ ) -> None:
26
+ """Set attributes."""
27
+ self.name = name
28
+ self._reference = reference
29
+ self._hide_outcomes = hide_outcomes
30
+
31
+ self.unit = Unit(self.name)
32
+
33
+ @property
34
+ def outcomes(self) -> List[OutcomeInterface]:
35
+ """Get outcomes of calling self.fulfill."""
36
+ outcomes = []
37
+
38
+ if self.unit.is_enabled:
39
+ outcomes.append(SystemdUnitDisableItemDisableOutcome(unit=self.unit))
40
+
41
+ return outcomes
42
+
43
+ def fulfill(self) -> None:
44
+ """Fulfill outcomes."""
45
+ systemd_unit_disable_outcomes = [
46
+ x
47
+ for x in self.outcomes
48
+ if isinstance(x, SystemdUnitDisableItemDisableOutcome)
49
+ ]
50
+
51
+ if systemd_unit_disable_outcomes:
52
+ systemd_unit_disable_outcomes[0].unit.disable()
53
+
54
+ def __eq__(self, other: object) -> bool:
55
+ """Get equality based on attributes."""
56
+ if not isinstance(other, SystemdUnitDisableItem):
57
+ return False
58
+
59
+ return other.name == self.name
@@ -0,0 +1,59 @@
1
+ """Item."""
2
+
3
+ import logging
4
+ from typing import List, Optional
5
+
6
+ from cyberfusion.QueueSupport.interfaces import OutcomeInterface
7
+ from cyberfusion.QueueSupport.items import _Item
8
+ from cyberfusion.QueueSupport.outcomes import (
9
+ SystemdUnitEnableItemEnableOutcome,
10
+ )
11
+ from cyberfusion.SystemdSupport.units import Unit
12
+
13
+ logger = logging.getLogger(__name__)
14
+
15
+
16
+ class SystemdUnitEnableItem(_Item):
17
+ """Represents item."""
18
+
19
+ def __init__(
20
+ self,
21
+ *,
22
+ name: str,
23
+ reference: Optional[str] = None,
24
+ hide_outcomes: bool = False,
25
+ ) -> None:
26
+ """Set attributes."""
27
+ self.name = name
28
+ self._reference = reference
29
+ self._hide_outcomes = hide_outcomes
30
+
31
+ self.unit = Unit(self.name)
32
+
33
+ @property
34
+ def outcomes(self) -> List[OutcomeInterface]:
35
+ """Get outcomes of calling self.fulfill."""
36
+ outcomes = []
37
+
38
+ if not self.unit.is_enabled:
39
+ outcomes.append(SystemdUnitEnableItemEnableOutcome(unit=self.unit))
40
+
41
+ return outcomes
42
+
43
+ def fulfill(self) -> None:
44
+ """Fulfill outcomes."""
45
+ systemd_unit_enable_outcomes = [
46
+ x
47
+ for x in self.outcomes
48
+ if isinstance(x, SystemdUnitEnableItemEnableOutcome)
49
+ ]
50
+
51
+ if systemd_unit_enable_outcomes:
52
+ systemd_unit_enable_outcomes[0].unit.enable()
53
+
54
+ def __eq__(self, other: object) -> bool:
55
+ """Get equality based on attributes."""
56
+ if not isinstance(other, SystemdUnitEnableItem):
57
+ return False
58
+
59
+ return other.name == self.name
@@ -0,0 +1,57 @@
1
+ """Item."""
2
+
3
+ import logging
4
+ from typing import List, Optional
5
+
6
+ from cyberfusion.QueueSupport.interfaces import OutcomeInterface
7
+ from cyberfusion.QueueSupport.items import _Item
8
+ from cyberfusion.QueueSupport.outcomes import (
9
+ SystemdUnitReloadItemReloadOutcome,
10
+ )
11
+ from cyberfusion.SystemdSupport.units import Unit
12
+
13
+ logger = logging.getLogger(__name__)
14
+
15
+
16
+ class SystemdUnitReloadItem(_Item):
17
+ """Represents item."""
18
+
19
+ def __init__(
20
+ self,
21
+ *,
22
+ name: str,
23
+ reference: Optional[str] = None,
24
+ hide_outcomes: bool = False,
25
+ ) -> None:
26
+ """Set attributes."""
27
+ self.name = name
28
+ self._reference = reference
29
+ self._hide_outcomes = hide_outcomes
30
+
31
+ self.unit = Unit(self.name)
32
+
33
+ @property
34
+ def outcomes(self) -> List[OutcomeInterface]:
35
+ """Get outcomes of calling self.fulfill."""
36
+ outcomes = []
37
+
38
+ outcomes.append(SystemdUnitReloadItemReloadOutcome(unit=self.unit))
39
+
40
+ return outcomes
41
+
42
+ def fulfill(self) -> None:
43
+ """Fulfill outcomes."""
44
+ systemd_unit_reload_outcomes = [
45
+ x
46
+ for x in self.outcomes
47
+ if isinstance(x, SystemdUnitReloadItemReloadOutcome)
48
+ ]
49
+
50
+ systemd_unit_reload_outcomes[0].unit.reload()
51
+
52
+ def __eq__(self, other: object) -> bool:
53
+ """Get equality based on attributes."""
54
+ if not isinstance(other, SystemdUnitReloadItem):
55
+ return False
56
+
57
+ return other.name == self.name
@@ -0,0 +1,57 @@
1
+ """Item."""
2
+
3
+ import logging
4
+ from typing import List, Optional
5
+
6
+ from cyberfusion.QueueSupport.interfaces import OutcomeInterface
7
+ from cyberfusion.QueueSupport.items import _Item
8
+ from cyberfusion.QueueSupport.outcomes import (
9
+ SystemdUnitRestartItemRestartOutcome,
10
+ )
11
+ from cyberfusion.SystemdSupport.units import Unit
12
+
13
+ logger = logging.getLogger(__name__)
14
+
15
+
16
+ class SystemdUnitRestartItem(_Item):
17
+ """Represents item."""
18
+
19
+ def __init__(
20
+ self,
21
+ *,
22
+ name: str,
23
+ reference: Optional[str] = None,
24
+ hide_outcomes: bool = False,
25
+ ) -> None:
26
+ """Set attributes."""
27
+ self.name = name
28
+ self._reference = reference
29
+ self._hide_outcomes = hide_outcomes
30
+
31
+ self.unit = Unit(self.name)
32
+
33
+ @property
34
+ def outcomes(self) -> List[OutcomeInterface]:
35
+ """Get outcomes of calling self.fulfill."""
36
+ outcomes = []
37
+
38
+ outcomes.append(SystemdUnitRestartItemRestartOutcome(unit=self.unit))
39
+
40
+ return outcomes
41
+
42
+ def fulfill(self) -> None:
43
+ """Fulfill outcomes."""
44
+ systemd_unit_restart_outcomes = [
45
+ x
46
+ for x in self.outcomes
47
+ if isinstance(x, SystemdUnitRestartItemRestartOutcome)
48
+ ]
49
+
50
+ systemd_unit_restart_outcomes[0].unit.restart()
51
+
52
+ def __eq__(self, other: object) -> bool:
53
+ """Get equality based on attributes."""
54
+ if not isinstance(other, SystemdUnitRestartItem):
55
+ return False
56
+
57
+ return other.name == self.name
@@ -0,0 +1,55 @@
1
+ """Item."""
2
+
3
+ import logging
4
+ from typing import List, Optional
5
+
6
+ from cyberfusion.QueueSupport.interfaces import OutcomeInterface
7
+ from cyberfusion.QueueSupport.items import _Item
8
+ from cyberfusion.QueueSupport.outcomes import SystemdUnitStopItemStopOutcome
9
+ from cyberfusion.SystemdSupport.units import Unit
10
+
11
+ logger = logging.getLogger(__name__)
12
+
13
+
14
+ class SystemdUnitStopItem(_Item):
15
+ """Represents item."""
16
+
17
+ def __init__(
18
+ self,
19
+ *,
20
+ name: str,
21
+ reference: Optional[str] = None,
22
+ hide_outcomes: bool = False,
23
+ ) -> None:
24
+ """Set attributes."""
25
+ self.name = name
26
+ self._reference = reference
27
+ self._hide_outcomes = hide_outcomes
28
+
29
+ self.unit = Unit(self.name)
30
+
31
+ @property
32
+ def outcomes(self) -> List[OutcomeInterface]:
33
+ """Get outcomes of calling self.fulfill."""
34
+ outcomes = []
35
+
36
+ if self.unit.is_active:
37
+ outcomes.append(SystemdUnitStopItemStopOutcome(unit=self.unit))
38
+
39
+ return outcomes
40
+
41
+ def fulfill(self) -> None:
42
+ """Fulfill outcomes."""
43
+ systemd_unit_stop_outcomes = [
44
+ x for x in self.outcomes if isinstance(x, SystemdUnitStopItemStopOutcome)
45
+ ]
46
+
47
+ if systemd_unit_stop_outcomes:
48
+ systemd_unit_stop_outcomes[0].unit.stop()
49
+
50
+ def __eq__(self, other: object) -> bool:
51
+ """Get equality based on attributes."""
52
+ if not isinstance(other, SystemdUnitStopItem):
53
+ return False
54
+
55
+ return other.name == self.name
@@ -0,0 +1,61 @@
1
+ """Item."""
2
+
3
+ import logging
4
+ import os
5
+ from typing import List, Optional
6
+
7
+ from cyberfusion.QueueSupport.exceptions import PathIsSymlinkError
8
+ from cyberfusion.QueueSupport.interfaces import OutcomeInterface
9
+ from cyberfusion.QueueSupport.items import _Item
10
+ from cyberfusion.QueueSupport.outcomes import UnlinkItemUnlinkOutcome
11
+
12
+ logger = logging.getLogger(__name__)
13
+
14
+
15
+ class UnlinkItem(_Item):
16
+ """Represents item."""
17
+
18
+ def __init__(
19
+ self,
20
+ *,
21
+ path: str,
22
+ reference: Optional[str] = None,
23
+ hide_outcomes: bool = False,
24
+ ) -> None:
25
+ """Set attributes."""
26
+ self.path = path
27
+ self._reference = reference
28
+ self._hide_outcomes = hide_outcomes
29
+
30
+ if os.path.islink(self.path):
31
+ raise PathIsSymlinkError(self.path)
32
+
33
+ @property
34
+ def outcomes(self) -> List[OutcomeInterface]:
35
+ """Get outcomes of calling self.fulfill."""
36
+ outcomes = []
37
+
38
+ if os.path.exists(self.path):
39
+ outcomes.append(
40
+ UnlinkItemUnlinkOutcome(
41
+ path=self.path,
42
+ )
43
+ )
44
+
45
+ return outcomes
46
+
47
+ def fulfill(self) -> None:
48
+ """Fulfill outcomes."""
49
+ unlink_outcomes = [
50
+ x for x in self.outcomes if isinstance(x, UnlinkItemUnlinkOutcome)
51
+ ]
52
+
53
+ if unlink_outcomes:
54
+ os.unlink(unlink_outcomes[0].path)
55
+
56
+ def __eq__(self, other: object) -> bool:
57
+ """Get equality based on attributes."""
58
+ if not isinstance(other, UnlinkItem):
59
+ return False
60
+
61
+ return other.path == self.path
@@ -0,0 +1,305 @@
1
+ """Outcomes."""
2
+
3
+ from typing import List, Optional
4
+
5
+ from cyberfusion.QueueSupport.interfaces import OutcomeInterface
6
+ from cyberfusion.SystemdSupport.units import Unit
7
+
8
+
9
+ class CopyItemCopyOutcome(OutcomeInterface):
10
+ """Represents outcome."""
11
+
12
+ def __init__(self, *, source: str, destination: str) -> None:
13
+ """Set attributes."""
14
+ self.source = source
15
+ self.destination = destination
16
+
17
+ def __str__(self) -> str:
18
+ """Get human-readable string."""
19
+ return f"Copy {self.source} to {self.destination}"
20
+
21
+ def __eq__(self, other: object) -> bool:
22
+ """Get equality based on attributes."""
23
+ if not isinstance(other, CopyItemCopyOutcome):
24
+ return False
25
+
26
+ return other.source == self.source and other.destination == self.destination
27
+
28
+
29
+ class MoveItemMoveOutcome(OutcomeInterface):
30
+ """Represents outcome."""
31
+
32
+ def __init__(self, *, source: str, destination: str) -> None:
33
+ """Set attributes."""
34
+ self.source = source
35
+ self.destination = destination
36
+
37
+ def __str__(self) -> str:
38
+ """Get human-readable string."""
39
+ return f"Move {self.source} to {self.destination}"
40
+
41
+ def __eq__(self, other: object) -> bool:
42
+ """Get equality based on attributes."""
43
+ if not isinstance(other, MoveItemMoveOutcome):
44
+ return False
45
+
46
+ return other.source == self.source and other.destination == self.destination
47
+
48
+
49
+ class MkdirItemCreateOutcome(OutcomeInterface):
50
+ """Represents outcome."""
51
+
52
+ def __init__(self, *, path: str) -> None:
53
+ """Set attributes."""
54
+ self.path = path
55
+
56
+ def __str__(self) -> str:
57
+ """Get human-readable string."""
58
+ return f"Create {self.path}"
59
+
60
+ def __eq__(self, other: object) -> bool:
61
+ """Get equality based on attributes."""
62
+ if not isinstance(other, MkdirItemCreateOutcome):
63
+ return False
64
+
65
+ return other.path == self.path
66
+
67
+
68
+ class SystemdTmpFilesCreateItemCreateOutcome(OutcomeInterface):
69
+ """Represents outcome."""
70
+
71
+ def __init__(self, *, path: str) -> None:
72
+ """Set attributes."""
73
+ self.path = path
74
+
75
+ def __str__(self) -> str:
76
+ """Get human-readable string."""
77
+ return (
78
+ f"Create tmp files according to tmp files configuration file at {self.path}"
79
+ )
80
+
81
+ def __eq__(self, other: object) -> bool:
82
+ """Get equality based on attributes."""
83
+ if not isinstance(other, SystemdTmpFilesCreateItemCreateOutcome):
84
+ return False
85
+
86
+ return other.path == self.path
87
+
88
+
89
+ class UnlinkItemUnlinkOutcome(OutcomeInterface):
90
+ """Represents outcome."""
91
+
92
+ def __init__(self, *, path: str) -> None:
93
+ """Set attributes."""
94
+ self.path = path
95
+
96
+ def __str__(self) -> str:
97
+ """Get human-readable string."""
98
+ return f"Unlink {self.path}"
99
+
100
+ def __eq__(self, other: object) -> bool:
101
+ """Get equality based on attributes."""
102
+ if not isinstance(other, UnlinkItemUnlinkOutcome):
103
+ return False
104
+
105
+ return other.path == self.path
106
+
107
+
108
+ class CommandItemRunOutcome(OutcomeInterface):
109
+ """Represents outcome."""
110
+
111
+ def __init__(self, *, command: List[str]) -> None:
112
+ """Set attributes."""
113
+ self.command = command
114
+
115
+ def __str__(self) -> str:
116
+ """Get human-readable string."""
117
+ return f"Run {self.command}"
118
+
119
+ def __eq__(self, other: object) -> bool:
120
+ """Get equality based on attributes."""
121
+ if not isinstance(other, CommandItemRunOutcome):
122
+ return False
123
+
124
+ return other.command == self.command
125
+
126
+
127
+ class ChmodItemModeChangeOutcome(OutcomeInterface):
128
+ """Represents outcome."""
129
+
130
+ def __init__(self, *, path: str, old_mode: Optional[int], new_mode: int) -> None:
131
+ """Set attributes."""
132
+ self.path = path
133
+ self.old_mode = old_mode
134
+ self.new_mode = new_mode
135
+
136
+ def __str__(self) -> str:
137
+ """Get human-readable string."""
138
+ old_mode: Optional[str]
139
+
140
+ if self.old_mode is not None:
141
+ old_mode = oct(self.old_mode)
142
+ else:
143
+ old_mode = None
144
+
145
+ return f"Change mode of {self.path} from {old_mode} to {oct(self.new_mode)}"
146
+
147
+ def __eq__(self, other: object) -> bool:
148
+ """Get equality based on attributes."""
149
+ if not isinstance(other, ChmodItemModeChangeOutcome):
150
+ return False
151
+
152
+ return (
153
+ other.path == self.path
154
+ and other.old_mode == self.old_mode
155
+ and other.new_mode == self.new_mode
156
+ )
157
+
158
+
159
+ class ChownItemOwnerChangeOutcome(OutcomeInterface):
160
+ """Represents outcome."""
161
+
162
+ def __init__(
163
+ self, *, path: str, old_owner_name: Optional[str], new_owner_name: str
164
+ ) -> None:
165
+ """Set attributes."""
166
+ self.path = path
167
+ self.old_owner_name = old_owner_name
168
+ self.new_owner_name = new_owner_name
169
+
170
+ def __str__(self) -> str:
171
+ """Get human-readable string."""
172
+ return f"Change owner of {self.path} from {self.old_owner_name} to {self.new_owner_name}"
173
+
174
+ def __eq__(self, other: object) -> bool:
175
+ """Get equality based on attributes."""
176
+ if not isinstance(other, ChownItemOwnerChangeOutcome):
177
+ return False
178
+
179
+ return (
180
+ other.path == self.path
181
+ and other.old_owner_name == self.old_owner_name
182
+ and other.new_owner_name == self.new_owner_name
183
+ )
184
+
185
+
186
+ class ChownItemGroupChangeOutcome(OutcomeInterface):
187
+ """Represents outcome."""
188
+
189
+ def __init__(
190
+ self, *, path: str, old_group_name: Optional[str], new_group_name: str
191
+ ) -> None:
192
+ """Set attributes."""
193
+ self.path = path
194
+ self.old_group_name = old_group_name
195
+ self.new_group_name = new_group_name
196
+
197
+ def __str__(self) -> str:
198
+ """Get human-readable string."""
199
+ return f"Change group of {self.path} from {self.old_group_name} to {self.new_group_name}"
200
+
201
+ def __eq__(self, other: object) -> bool:
202
+ """Get equality based on attributes."""
203
+ if not isinstance(other, ChownItemGroupChangeOutcome):
204
+ return False
205
+
206
+ return (
207
+ other.path == self.path
208
+ and other.old_group_name == self.old_group_name
209
+ and other.new_group_name == self.new_group_name
210
+ )
211
+
212
+
213
+ class SystemdUnitEnableItemEnableOutcome(OutcomeInterface):
214
+ """Represents outcome."""
215
+
216
+ def __init__(self, *, unit: Unit) -> None:
217
+ """Set attributes."""
218
+ self.unit = unit
219
+
220
+ def __str__(self) -> str:
221
+ """Get human-readable string."""
222
+ return f"Enable {self.unit.name}"
223
+
224
+ def __eq__(self, other: object) -> bool:
225
+ """Get equality based on attributes."""
226
+ if not isinstance(other, SystemdUnitEnableItemEnableOutcome):
227
+ return False
228
+
229
+ return other.unit.name == self.unit.name
230
+
231
+
232
+ class SystemdUnitDisableItemDisableOutcome(OutcomeInterface):
233
+ """Represents outcome."""
234
+
235
+ def __init__(self, *, unit: Unit) -> None:
236
+ """Set attributes."""
237
+ self.unit = unit
238
+
239
+ def __str__(self) -> str:
240
+ """Get human-readable string."""
241
+ return f"Disable {self.unit.name}"
242
+
243
+ def __eq__(self, other: object) -> bool:
244
+ """Get equality based on attributes."""
245
+ if not isinstance(other, SystemdUnitDisableItemDisableOutcome):
246
+ return False
247
+
248
+ return other.unit.name == self.unit.name
249
+
250
+
251
+ class SystemdUnitRestartItemRestartOutcome(OutcomeInterface):
252
+ """Represents outcome."""
253
+
254
+ def __init__(self, *, unit: Unit) -> None:
255
+ """Set attributes."""
256
+ self.unit = unit
257
+
258
+ def __str__(self) -> str:
259
+ """Get human-readable string."""
260
+ return f"Restart {self.unit.name}"
261
+
262
+ def __eq__(self, other: object) -> bool:
263
+ """Get equality based on attributes."""
264
+ if not isinstance(other, SystemdUnitRestartItemRestartOutcome):
265
+ return False
266
+
267
+ return other.unit.name == self.unit.name
268
+
269
+
270
+ class SystemdUnitReloadItemReloadOutcome(OutcomeInterface):
271
+ """Represents outcome."""
272
+
273
+ def __init__(self, *, unit: Unit) -> None:
274
+ """Set attributes."""
275
+ self.unit = unit
276
+
277
+ def __str__(self) -> str:
278
+ """Get human-readable string."""
279
+ return f"Reload {self.unit.name}"
280
+
281
+ def __eq__(self, other: object) -> bool:
282
+ """Get equality based on attributes."""
283
+ if not isinstance(other, SystemdUnitReloadItemReloadOutcome):
284
+ return False
285
+
286
+ return other.unit.name == self.unit.name
287
+
288
+
289
+ class SystemdUnitStopItemStopOutcome(OutcomeInterface):
290
+ """Represents outcome."""
291
+
292
+ def __init__(self, *, unit: Unit) -> None:
293
+ """Set attributes."""
294
+ self.unit = unit
295
+
296
+ def __str__(self) -> str:
297
+ """Get human-readable string."""
298
+ return f"Stop {self.unit.name}"
299
+
300
+ def __eq__(self, other: object) -> bool:
301
+ """Get equality based on attributes."""
302
+ if not isinstance(other, SystemdUnitStopItemStopOutcome):
303
+ return False
304
+
305
+ return other.unit.name == self.unit.name
@@ -0,0 +1,9 @@
1
+ """Utilities."""
2
+
3
+ import os
4
+ import stat
5
+
6
+
7
+ def get_decimal_permissions(path: str) -> int:
8
+ """Get decimal permissions with all bits."""
9
+ return stat.S_IMODE(os.lstat(path).st_mode)