python3-cyberfusion-queue-support 1.1.3__tar.gz → 1.2__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.
- {python3_cyberfusion_queue_support-1.1.3 → python3_cyberfusion_queue_support-1.2}/PKG-INFO +38 -1
- python3_cyberfusion_queue_support-1.2/README.md +82 -0
- {python3_cyberfusion_queue_support-1.1.3 → python3_cyberfusion_queue_support-1.2}/pyproject.toml +1 -1
- {python3_cyberfusion_queue_support-1.1.3 → python3_cyberfusion_queue_support-1.2}/src/cyberfusion/QueueSupport/interfaces.py +1 -1
- {python3_cyberfusion_queue_support-1.1.3 → python3_cyberfusion_queue_support-1.2}/src/cyberfusion/QueueSupport/items/chmod.py +4 -9
- {python3_cyberfusion_queue_support-1.1.3 → python3_cyberfusion_queue_support-1.2}/src/cyberfusion/QueueSupport/items/chown.py +17 -23
- {python3_cyberfusion_queue_support-1.1.3 → python3_cyberfusion_queue_support-1.2}/src/cyberfusion/QueueSupport/items/command.py +17 -23
- {python3_cyberfusion_queue_support-1.1.3 → python3_cyberfusion_queue_support-1.2}/src/cyberfusion/QueueSupport/items/copy.py +4 -6
- {python3_cyberfusion_queue_support-1.1.3 → python3_cyberfusion_queue_support-1.2}/src/cyberfusion/QueueSupport/items/mkdir.py +4 -9
- {python3_cyberfusion_queue_support-1.1.3 → python3_cyberfusion_queue_support-1.2}/src/cyberfusion/QueueSupport/items/move.py +4 -6
- python3_cyberfusion_queue_support-1.2/src/cyberfusion/QueueSupport/items/rmtree.py +57 -0
- {python3_cyberfusion_queue_support-1.1.3 → python3_cyberfusion_queue_support-1.2}/src/cyberfusion/QueueSupport/items/systemd_tmp_files_create.py +4 -10
- {python3_cyberfusion_queue_support-1.1.3 → python3_cyberfusion_queue_support-1.2}/src/cyberfusion/QueueSupport/items/systemd_unit_disable.py +4 -11
- {python3_cyberfusion_queue_support-1.1.3 → python3_cyberfusion_queue_support-1.2}/src/cyberfusion/QueueSupport/items/systemd_unit_enable.py +4 -11
- {python3_cyberfusion_queue_support-1.1.3 → python3_cyberfusion_queue_support-1.2}/src/cyberfusion/QueueSupport/items/systemd_unit_reload.py +4 -10
- {python3_cyberfusion_queue_support-1.1.3 → python3_cyberfusion_queue_support-1.2}/src/cyberfusion/QueueSupport/items/systemd_unit_restart.py +4 -10
- {python3_cyberfusion_queue_support-1.1.3 → python3_cyberfusion_queue_support-1.2}/src/cyberfusion/QueueSupport/items/systemd_unit_stop.py +4 -9
- {python3_cyberfusion_queue_support-1.1.3 → python3_cyberfusion_queue_support-1.2}/src/cyberfusion/QueueSupport/items/unlink.py +4 -9
- {python3_cyberfusion_queue_support-1.1.3 → python3_cyberfusion_queue_support-1.2}/src/cyberfusion/QueueSupport/outcomes.py +19 -0
- {python3_cyberfusion_queue_support-1.1.3 → python3_cyberfusion_queue_support-1.2}/src/python3_cyberfusion_queue_support.egg-info/PKG-INFO +38 -1
- {python3_cyberfusion_queue_support-1.1.3 → python3_cyberfusion_queue_support-1.2}/src/python3_cyberfusion_queue_support.egg-info/SOURCES.txt +1 -0
- python3_cyberfusion_queue_support-1.1.3/README.md +0 -45
- {python3_cyberfusion_queue_support-1.1.3 → python3_cyberfusion_queue_support-1.2}/setup.cfg +0 -0
- {python3_cyberfusion_queue_support-1.1.3 → python3_cyberfusion_queue_support-1.2}/src/cyberfusion/QueueSupport/__init__.py +0 -0
- {python3_cyberfusion_queue_support-1.1.3 → python3_cyberfusion_queue_support-1.2}/src/cyberfusion/QueueSupport/exceptions/__init__.py +0 -0
- {python3_cyberfusion_queue_support-1.1.3 → python3_cyberfusion_queue_support-1.2}/src/cyberfusion/QueueSupport/items/__init__.py +0 -0
- {python3_cyberfusion_queue_support-1.1.3 → python3_cyberfusion_queue_support-1.2}/src/cyberfusion/QueueSupport/utilities.py +0 -0
- {python3_cyberfusion_queue_support-1.1.3 → python3_cyberfusion_queue_support-1.2}/src/python3_cyberfusion_queue_support.egg-info/dependency_links.txt +0 -0
- {python3_cyberfusion_queue_support-1.1.3 → python3_cyberfusion_queue_support-1.2}/src/python3_cyberfusion_queue_support.egg-info/requires.txt +0 -0
- {python3_cyberfusion_queue_support-1.1.3 → python3_cyberfusion_queue_support-1.2}/src/python3_cyberfusion_queue_support.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: python3-cyberfusion-queue-support
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.2
|
|
4
4
|
Summary: Library to queue actions.
|
|
5
5
|
Author-email: Cyberfusion <support@cyberfusion.io>
|
|
6
6
|
Project-URL: Source, https://github.com/CyberfusionIO/python3-cyberfusion-queue-support
|
|
@@ -11,6 +11,43 @@ Requires-Dist: python3-cyberfusion-systemd-support~=1.0
|
|
|
11
11
|
|
|
12
12
|
Library to queue actions.
|
|
13
13
|
|
|
14
|
+
# Concepts
|
|
15
|
+
|
|
16
|
+
All project-specific terms are in _italic_.
|
|
17
|
+
|
|
18
|
+
After creating a _queue_, _items_ can be added to it.
|
|
19
|
+
|
|
20
|
+
```python
|
|
21
|
+
queue = Queue()
|
|
22
|
+
|
|
23
|
+
queue.add(item)
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
These _items_ can be of multiple types such as `ChmodItem` or `SystemdUnitRestartItem`, and they can have attributes such as a path for an `MkdirItem` or a unit name for a `SystemdUnitEnableItem`.
|
|
27
|
+
|
|
28
|
+
```python
|
|
29
|
+
item1 = ChmodItem(path="/tmp/example.txt", mode=0o600)
|
|
30
|
+
item2 = SystemdUnitEnableItem(name="httpd.service")
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Each _item_ type has one or multiple _outcomes_ that should come true for an _item_ of that type to be completed. For example: for an _item_ of type `UnlinkItem`, the _outcome_ is that the file at the path given with the _item_ is unlinked.
|
|
34
|
+
|
|
35
|
+
When a _queue_ is _processed_, all the _items_ added to it are _fulfilled_, meaning all the _items'_ _outcomes_ are completed.
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
item = RmTreeItem(path="/tmp/dir")
|
|
39
|
+
|
|
40
|
+
queue = Queue()
|
|
41
|
+
|
|
42
|
+
queue.add(item)
|
|
43
|
+
|
|
44
|
+
# for each item added to the queue, its fulfill() function is run
|
|
45
|
+
queue.process()
|
|
46
|
+
|
|
47
|
+
# this would do the same
|
|
48
|
+
item.fulfill()
|
|
49
|
+
```
|
|
50
|
+
|
|
14
51
|
# Install
|
|
15
52
|
|
|
16
53
|
## PyPI
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# python3-cyberfusion-queue-support
|
|
2
|
+
|
|
3
|
+
Library to queue actions.
|
|
4
|
+
|
|
5
|
+
# Concepts
|
|
6
|
+
|
|
7
|
+
All project-specific terms are in _italic_.
|
|
8
|
+
|
|
9
|
+
After creating a _queue_, _items_ can be added to it.
|
|
10
|
+
|
|
11
|
+
```python
|
|
12
|
+
queue = Queue()
|
|
13
|
+
|
|
14
|
+
queue.add(item)
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
These _items_ can be of multiple types such as `ChmodItem` or `SystemdUnitRestartItem`, and they can have attributes such as a path for an `MkdirItem` or a unit name for a `SystemdUnitEnableItem`.
|
|
18
|
+
|
|
19
|
+
```python
|
|
20
|
+
item1 = ChmodItem(path="/tmp/example.txt", mode=0o600)
|
|
21
|
+
item2 = SystemdUnitEnableItem(name="httpd.service")
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Each _item_ type has one or multiple _outcomes_ that should come true for an _item_ of that type to be completed. For example: for an _item_ of type `UnlinkItem`, the _outcome_ is that the file at the path given with the _item_ is unlinked.
|
|
25
|
+
|
|
26
|
+
When a _queue_ is _processed_, all the _items_ added to it are _fulfilled_, meaning all the _items'_ _outcomes_ are completed.
|
|
27
|
+
|
|
28
|
+
```python
|
|
29
|
+
item = RmTreeItem(path="/tmp/dir")
|
|
30
|
+
|
|
31
|
+
queue = Queue()
|
|
32
|
+
|
|
33
|
+
queue.add(item)
|
|
34
|
+
|
|
35
|
+
# for each item added to the queue, its fulfill() function is run
|
|
36
|
+
queue.process()
|
|
37
|
+
|
|
38
|
+
# this would do the same
|
|
39
|
+
item.fulfill()
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
# Install
|
|
43
|
+
|
|
44
|
+
## PyPI
|
|
45
|
+
|
|
46
|
+
Run the following command to install the package from PyPI:
|
|
47
|
+
|
|
48
|
+
pip3 install python3-cyberfusion-queue-support
|
|
49
|
+
|
|
50
|
+
## Debian
|
|
51
|
+
|
|
52
|
+
Run the following commands to build a Debian package:
|
|
53
|
+
|
|
54
|
+
mk-build-deps -i -t 'apt -o Debug::pkgProblemResolver=yes --no-install-recommends -y'
|
|
55
|
+
dpkg-buildpackage -us -uc
|
|
56
|
+
|
|
57
|
+
# Configure
|
|
58
|
+
|
|
59
|
+
No configuration is supported.
|
|
60
|
+
|
|
61
|
+
# Usage
|
|
62
|
+
|
|
63
|
+
## Example
|
|
64
|
+
|
|
65
|
+
```python
|
|
66
|
+
from cyberfusion.QueueSupport import Queue
|
|
67
|
+
from cyberfusion.QueueSupport.items.chmod import ChmodItem
|
|
68
|
+
|
|
69
|
+
queue = Queue()
|
|
70
|
+
|
|
71
|
+
item = ChmodItem(path="/tmp/example.txt", mode=0o600)
|
|
72
|
+
print(item.outcomes)
|
|
73
|
+
|
|
74
|
+
queue.add(item)
|
|
75
|
+
|
|
76
|
+
preview = True or False
|
|
77
|
+
|
|
78
|
+
outcomes = queue.process(preview=preview)
|
|
79
|
+
|
|
80
|
+
for outcome in outcomes:
|
|
81
|
+
print(str(outcome))
|
|
82
|
+
```
|
|
@@ -5,7 +5,6 @@ import os
|
|
|
5
5
|
from typing import List, Optional
|
|
6
6
|
|
|
7
7
|
from cyberfusion.QueueSupport.exceptions import PathIsSymlinkError
|
|
8
|
-
from cyberfusion.QueueSupport.interfaces import OutcomeInterface
|
|
9
8
|
from cyberfusion.QueueSupport.items import _Item
|
|
10
9
|
from cyberfusion.QueueSupport.outcomes import ChmodItemModeChangeOutcome
|
|
11
10
|
from cyberfusion.QueueSupport.utilities import get_decimal_permissions
|
|
@@ -34,8 +33,8 @@ class ChmodItem(_Item):
|
|
|
34
33
|
raise PathIsSymlinkError(self.path)
|
|
35
34
|
|
|
36
35
|
@property
|
|
37
|
-
def outcomes(self) -> List[
|
|
38
|
-
"""Get outcomes of
|
|
36
|
+
def outcomes(self) -> List[ChmodItemModeChangeOutcome]:
|
|
37
|
+
"""Get outcomes of item."""
|
|
39
38
|
outcomes = []
|
|
40
39
|
|
|
41
40
|
if not os.path.exists(self.path):
|
|
@@ -59,12 +58,8 @@ class ChmodItem(_Item):
|
|
|
59
58
|
|
|
60
59
|
def fulfill(self) -> None:
|
|
61
60
|
"""Fulfill outcomes."""
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
]
|
|
65
|
-
|
|
66
|
-
if mode_change_outcomes:
|
|
67
|
-
os.chmod(mode_change_outcomes[0].path, mode_change_outcomes[0].new_mode)
|
|
61
|
+
for outcome in self.outcomes:
|
|
62
|
+
os.chmod(outcome.path, outcome.new_mode)
|
|
68
63
|
|
|
69
64
|
def __eq__(self, other: object) -> bool:
|
|
70
65
|
"""Get equality based on attributes."""
|
|
@@ -9,7 +9,6 @@ from pwd import getpwuid
|
|
|
9
9
|
from typing import List, Optional
|
|
10
10
|
|
|
11
11
|
from cyberfusion.QueueSupport.exceptions import PathIsSymlinkError
|
|
12
|
-
from cyberfusion.QueueSupport.interfaces import OutcomeInterface
|
|
13
12
|
from cyberfusion.QueueSupport.items import _Item
|
|
14
13
|
from cyberfusion.QueueSupport.outcomes import (
|
|
15
14
|
ChownItemGroupChangeOutcome,
|
|
@@ -52,8 +51,10 @@ class ChownItem(_Item):
|
|
|
52
51
|
raise PathIsSymlinkError(self.path)
|
|
53
52
|
|
|
54
53
|
@property
|
|
55
|
-
def outcomes(
|
|
56
|
-
|
|
54
|
+
def outcomes(
|
|
55
|
+
self,
|
|
56
|
+
) -> List[ChownItemOwnerChangeOutcome | ChownItemGroupChangeOutcome]:
|
|
57
|
+
"""Get outcomes of item."""
|
|
57
58
|
outcomes = []
|
|
58
59
|
|
|
59
60
|
if not os.path.exists(self.path):
|
|
@@ -107,26 +108,19 @@ class ChownItem(_Item):
|
|
|
107
108
|
|
|
108
109
|
def fulfill(self) -> None:
|
|
109
110
|
"""Fulfill outcomes."""
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
if group_name_change_outcomes:
|
|
125
|
-
os.chown(
|
|
126
|
-
group_name_change_outcomes[0].path,
|
|
127
|
-
uid=-1,
|
|
128
|
-
gid=get_gid(group_name_change_outcomes[0].new_group_name),
|
|
129
|
-
)
|
|
111
|
+
for outcome in self.outcomes:
|
|
112
|
+
if isinstance(outcome, ChownItemOwnerChangeOutcome):
|
|
113
|
+
os.chown(
|
|
114
|
+
outcome.path,
|
|
115
|
+
uid=get_uid(outcome.new_owner_name),
|
|
116
|
+
gid=-1,
|
|
117
|
+
)
|
|
118
|
+
else:
|
|
119
|
+
os.chown(
|
|
120
|
+
outcome.path,
|
|
121
|
+
uid=-1,
|
|
122
|
+
gid=get_gid(outcome.new_group_name),
|
|
123
|
+
)
|
|
130
124
|
|
|
131
125
|
def __eq__(self, other: object) -> bool:
|
|
132
126
|
"""Get equality based on attributes."""
|
|
@@ -5,7 +5,6 @@ import subprocess
|
|
|
5
5
|
from typing import List, Optional
|
|
6
6
|
|
|
7
7
|
from cyberfusion.QueueSupport.exceptions import CommandQueueFulfillFailed
|
|
8
|
-
from cyberfusion.QueueSupport.interfaces import OutcomeInterface
|
|
9
8
|
from cyberfusion.QueueSupport.items import _Item
|
|
10
9
|
from cyberfusion.QueueSupport.outcomes import CommandItemRunOutcome
|
|
11
10
|
|
|
@@ -28,8 +27,8 @@ class CommandItem(_Item):
|
|
|
28
27
|
self._hide_outcomes = hide_outcomes
|
|
29
28
|
|
|
30
29
|
@property
|
|
31
|
-
def outcomes(self) -> List[
|
|
32
|
-
"""Get outcomes of
|
|
30
|
+
def outcomes(self) -> List[CommandItemRunOutcome]:
|
|
31
|
+
"""Get outcomes of item."""
|
|
33
32
|
outcomes = []
|
|
34
33
|
|
|
35
34
|
outcomes.append(CommandItemRunOutcome(command=self.command))
|
|
@@ -38,26 +37,21 @@ class CommandItem(_Item):
|
|
|
38
37
|
|
|
39
38
|
def fulfill(self) -> None:
|
|
40
39
|
"""Fulfill outcomes."""
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
logger.info("Command stderr: %s", output.stderr)
|
|
57
|
-
except subprocess.CalledProcessError as e:
|
|
58
|
-
raise CommandQueueFulfillFailed(
|
|
59
|
-
self, command=command, stdout=e.stdout, stderr=e.stderr
|
|
60
|
-
) from e
|
|
40
|
+
for outcome in self.outcomes:
|
|
41
|
+
try:
|
|
42
|
+
output = subprocess.run(
|
|
43
|
+
outcome.command,
|
|
44
|
+
check=True,
|
|
45
|
+
text=True,
|
|
46
|
+
capture_output=True,
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
logger.info("Command stdout: %s", output.stdout)
|
|
50
|
+
logger.info("Command stderr: %s", output.stderr)
|
|
51
|
+
except subprocess.CalledProcessError as e:
|
|
52
|
+
raise CommandQueueFulfillFailed(
|
|
53
|
+
self, command=outcome.command, stdout=e.stdout, stderr=e.stderr
|
|
54
|
+
) from e
|
|
61
55
|
|
|
62
56
|
def __eq__(self, other: object) -> bool:
|
|
63
57
|
"""Get equality based on attributes."""
|
|
@@ -6,7 +6,6 @@ import shutil
|
|
|
6
6
|
from typing import List, Optional
|
|
7
7
|
|
|
8
8
|
from cyberfusion.QueueSupport.exceptions import PathIsSymlinkError
|
|
9
|
-
from cyberfusion.QueueSupport.interfaces import OutcomeInterface
|
|
10
9
|
from cyberfusion.QueueSupport.items import _Item
|
|
11
10
|
from cyberfusion.QueueSupport.outcomes import CopyItemCopyOutcome
|
|
12
11
|
|
|
@@ -37,8 +36,8 @@ class CopyItem(_Item):
|
|
|
37
36
|
raise PathIsSymlinkError(self.destination)
|
|
38
37
|
|
|
39
38
|
@property
|
|
40
|
-
def outcomes(self) -> List[
|
|
41
|
-
"""Get outcomes of
|
|
39
|
+
def outcomes(self) -> List[CopyItemCopyOutcome]:
|
|
40
|
+
"""Get outcomes of item."""
|
|
42
41
|
outcomes = []
|
|
43
42
|
|
|
44
43
|
outcomes.append(
|
|
@@ -49,9 +48,8 @@ class CopyItem(_Item):
|
|
|
49
48
|
|
|
50
49
|
def fulfill(self) -> None:
|
|
51
50
|
"""Fulfill outcomes."""
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
shutil.copyfile(copy_outcomes[0].source, copy_outcomes[0].destination)
|
|
51
|
+
for outcome in self.outcomes:
|
|
52
|
+
shutil.copyfile(outcome.source, outcome.destination)
|
|
55
53
|
|
|
56
54
|
def __eq__(self, other: object) -> bool:
|
|
57
55
|
"""Get equality based on attributes."""
|
|
@@ -5,7 +5,6 @@ import os
|
|
|
5
5
|
from typing import List, Optional
|
|
6
6
|
|
|
7
7
|
from cyberfusion.QueueSupport.exceptions import PathIsSymlinkError
|
|
8
|
-
from cyberfusion.QueueSupport.interfaces import OutcomeInterface
|
|
9
8
|
from cyberfusion.QueueSupport.items import _Item
|
|
10
9
|
from cyberfusion.QueueSupport.outcomes import MkdirItemCreateOutcome
|
|
11
10
|
|
|
@@ -31,8 +30,8 @@ class MkdirItem(_Item):
|
|
|
31
30
|
raise PathIsSymlinkError(self.path)
|
|
32
31
|
|
|
33
32
|
@property
|
|
34
|
-
def outcomes(self) -> List[
|
|
35
|
-
"""Get outcomes of
|
|
33
|
+
def outcomes(self) -> List[MkdirItemCreateOutcome]:
|
|
34
|
+
"""Get outcomes of item."""
|
|
36
35
|
outcomes = []
|
|
37
36
|
|
|
38
37
|
if not os.path.isdir(self.path):
|
|
@@ -46,12 +45,8 @@ class MkdirItem(_Item):
|
|
|
46
45
|
|
|
47
46
|
def fulfill(self) -> None:
|
|
48
47
|
"""Fulfill outcomes."""
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
]
|
|
52
|
-
|
|
53
|
-
if create_outcomes:
|
|
54
|
-
os.mkdir(create_outcomes[0].path)
|
|
48
|
+
for outcome in self.outcomes:
|
|
49
|
+
os.mkdir(outcome.path)
|
|
55
50
|
|
|
56
51
|
def __eq__(self, other: object) -> bool:
|
|
57
52
|
"""Get equality based on attributes."""
|
|
@@ -6,7 +6,6 @@ import shutil
|
|
|
6
6
|
from typing import List, Optional
|
|
7
7
|
|
|
8
8
|
from cyberfusion.QueueSupport.exceptions import PathIsSymlinkError
|
|
9
|
-
from cyberfusion.QueueSupport.interfaces import OutcomeInterface
|
|
10
9
|
from cyberfusion.QueueSupport.items import _Item
|
|
11
10
|
from cyberfusion.QueueSupport.outcomes import MoveItemMoveOutcome
|
|
12
11
|
|
|
@@ -37,8 +36,8 @@ class MoveItem(_Item):
|
|
|
37
36
|
raise PathIsSymlinkError(self.destination)
|
|
38
37
|
|
|
39
38
|
@property
|
|
40
|
-
def outcomes(self) -> List[
|
|
41
|
-
"""Get outcomes of
|
|
39
|
+
def outcomes(self) -> List[MoveItemMoveOutcome]:
|
|
40
|
+
"""Get outcomes of item."""
|
|
42
41
|
outcomes = []
|
|
43
42
|
|
|
44
43
|
outcomes.append(
|
|
@@ -49,9 +48,8 @@ class MoveItem(_Item):
|
|
|
49
48
|
|
|
50
49
|
def fulfill(self) -> None:
|
|
51
50
|
"""Fulfill outcomes."""
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
shutil.move(move_outcomes[0].source, move_outcomes[0].destination)
|
|
51
|
+
for outcome in self.outcomes:
|
|
52
|
+
shutil.move(outcome.source, outcome.destination)
|
|
55
53
|
|
|
56
54
|
def __eq__(self, other: object) -> bool:
|
|
57
55
|
"""Get equality based on attributes."""
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"""Item."""
|
|
2
|
+
|
|
3
|
+
import logging
|
|
4
|
+
import os
|
|
5
|
+
import shutil
|
|
6
|
+
from typing import List, Optional
|
|
7
|
+
|
|
8
|
+
from cyberfusion.QueueSupport.exceptions import PathIsSymlinkError
|
|
9
|
+
from cyberfusion.QueueSupport.items import _Item
|
|
10
|
+
from cyberfusion.QueueSupport.outcomes import RmTreeItemRemoveOutcome
|
|
11
|
+
|
|
12
|
+
logger = logging.getLogger(__name__)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class RmTreeItem(_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[RmTreeItemRemoveOutcome]:
|
|
35
|
+
"""Get outcomes of calling self.fulfill."""
|
|
36
|
+
outcomes = []
|
|
37
|
+
|
|
38
|
+
if os.path.exists(self.path):
|
|
39
|
+
outcomes.append(
|
|
40
|
+
RmTreeItemRemoveOutcome(
|
|
41
|
+
path=self.path,
|
|
42
|
+
)
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
return outcomes
|
|
46
|
+
|
|
47
|
+
def fulfill(self) -> None:
|
|
48
|
+
"""Fulfill outcomes."""
|
|
49
|
+
for outcome in self.outcomes:
|
|
50
|
+
shutil.rmtree(outcome.path)
|
|
51
|
+
|
|
52
|
+
def __eq__(self, other: object) -> bool:
|
|
53
|
+
"""Get equality based on attributes."""
|
|
54
|
+
if not isinstance(other, RmTreeItem):
|
|
55
|
+
return False
|
|
56
|
+
|
|
57
|
+
return other.path == self.path
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
import logging
|
|
4
4
|
from typing import List, Optional
|
|
5
5
|
|
|
6
|
-
from cyberfusion.QueueSupport.interfaces import OutcomeInterface
|
|
7
6
|
from cyberfusion.QueueSupport.items import _Item
|
|
8
7
|
from cyberfusion.QueueSupport.outcomes import (
|
|
9
8
|
SystemdTmpFilesCreateItemCreateOutcome,
|
|
@@ -29,8 +28,8 @@ class SystemdTmpFilesCreateItem(_Item):
|
|
|
29
28
|
self._hide_outcomes = hide_outcomes
|
|
30
29
|
|
|
31
30
|
@property
|
|
32
|
-
def outcomes(self) -> List[
|
|
33
|
-
"""Get outcomes of
|
|
31
|
+
def outcomes(self) -> List[SystemdTmpFilesCreateItemCreateOutcome]:
|
|
32
|
+
"""Get outcomes of item."""
|
|
34
33
|
outcomes = []
|
|
35
34
|
|
|
36
35
|
outcomes.append(SystemdTmpFilesCreateItemCreateOutcome(path=self.path))
|
|
@@ -39,13 +38,8 @@ class SystemdTmpFilesCreateItem(_Item):
|
|
|
39
38
|
|
|
40
39
|
def fulfill(self) -> None:
|
|
41
40
|
"""Fulfill outcomes."""
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
for x in self.outcomes
|
|
45
|
-
if isinstance(x, SystemdTmpFilesCreateItemCreateOutcome)
|
|
46
|
-
]
|
|
47
|
-
|
|
48
|
-
TmpFileConfigurationFile(systemd_tmp_files_create_outcomes[0].path).create()
|
|
41
|
+
for outcome in self.outcomes:
|
|
42
|
+
TmpFileConfigurationFile(outcome.path).create()
|
|
49
43
|
|
|
50
44
|
def __eq__(self, other: object) -> bool:
|
|
51
45
|
"""Get equality based on attributes."""
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
import logging
|
|
4
4
|
from typing import List, Optional
|
|
5
5
|
|
|
6
|
-
from cyberfusion.QueueSupport.interfaces import OutcomeInterface
|
|
7
6
|
from cyberfusion.QueueSupport.items import _Item
|
|
8
7
|
from cyberfusion.QueueSupport.outcomes import (
|
|
9
8
|
SystemdUnitDisableItemDisableOutcome,
|
|
@@ -31,8 +30,8 @@ class SystemdUnitDisableItem(_Item):
|
|
|
31
30
|
self.unit = Unit(self.name)
|
|
32
31
|
|
|
33
32
|
@property
|
|
34
|
-
def outcomes(self) -> List[
|
|
35
|
-
"""Get outcomes of
|
|
33
|
+
def outcomes(self) -> List[SystemdUnitDisableItemDisableOutcome]:
|
|
34
|
+
"""Get outcomes of item."""
|
|
36
35
|
outcomes = []
|
|
37
36
|
|
|
38
37
|
if self.unit.is_enabled:
|
|
@@ -42,14 +41,8 @@ class SystemdUnitDisableItem(_Item):
|
|
|
42
41
|
|
|
43
42
|
def fulfill(self) -> None:
|
|
44
43
|
"""Fulfill outcomes."""
|
|
45
|
-
|
|
46
|
-
|
|
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()
|
|
44
|
+
for outcome in self.outcomes:
|
|
45
|
+
outcome.unit.disable()
|
|
53
46
|
|
|
54
47
|
def __eq__(self, other: object) -> bool:
|
|
55
48
|
"""Get equality based on attributes."""
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
import logging
|
|
4
4
|
from typing import List, Optional
|
|
5
5
|
|
|
6
|
-
from cyberfusion.QueueSupport.interfaces import OutcomeInterface
|
|
7
6
|
from cyberfusion.QueueSupport.items import _Item
|
|
8
7
|
from cyberfusion.QueueSupport.outcomes import (
|
|
9
8
|
SystemdUnitEnableItemEnableOutcome,
|
|
@@ -31,8 +30,8 @@ class SystemdUnitEnableItem(_Item):
|
|
|
31
30
|
self.unit = Unit(self.name)
|
|
32
31
|
|
|
33
32
|
@property
|
|
34
|
-
def outcomes(self) -> List[
|
|
35
|
-
"""Get outcomes of
|
|
33
|
+
def outcomes(self) -> List[SystemdUnitEnableItemEnableOutcome]:
|
|
34
|
+
"""Get outcomes of item."""
|
|
36
35
|
outcomes = []
|
|
37
36
|
|
|
38
37
|
if not self.unit.is_enabled:
|
|
@@ -42,14 +41,8 @@ class SystemdUnitEnableItem(_Item):
|
|
|
42
41
|
|
|
43
42
|
def fulfill(self) -> None:
|
|
44
43
|
"""Fulfill outcomes."""
|
|
45
|
-
|
|
46
|
-
|
|
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()
|
|
44
|
+
for outcome in self.outcomes:
|
|
45
|
+
outcome.unit.enable()
|
|
53
46
|
|
|
54
47
|
def __eq__(self, other: object) -> bool:
|
|
55
48
|
"""Get equality based on attributes."""
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
import logging
|
|
4
4
|
from typing import List, Optional
|
|
5
5
|
|
|
6
|
-
from cyberfusion.QueueSupport.interfaces import OutcomeInterface
|
|
7
6
|
from cyberfusion.QueueSupport.items import _Item
|
|
8
7
|
from cyberfusion.QueueSupport.outcomes import (
|
|
9
8
|
SystemdUnitReloadItemReloadOutcome,
|
|
@@ -31,8 +30,8 @@ class SystemdUnitReloadItem(_Item):
|
|
|
31
30
|
self.unit = Unit(self.name)
|
|
32
31
|
|
|
33
32
|
@property
|
|
34
|
-
def outcomes(self) -> List[
|
|
35
|
-
"""Get outcomes of
|
|
33
|
+
def outcomes(self) -> List[SystemdUnitReloadItemReloadOutcome]:
|
|
34
|
+
"""Get outcomes of item."""
|
|
36
35
|
outcomes = []
|
|
37
36
|
|
|
38
37
|
outcomes.append(SystemdUnitReloadItemReloadOutcome(unit=self.unit))
|
|
@@ -41,13 +40,8 @@ class SystemdUnitReloadItem(_Item):
|
|
|
41
40
|
|
|
42
41
|
def fulfill(self) -> None:
|
|
43
42
|
"""Fulfill outcomes."""
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
for x in self.outcomes
|
|
47
|
-
if isinstance(x, SystemdUnitReloadItemReloadOutcome)
|
|
48
|
-
]
|
|
49
|
-
|
|
50
|
-
systemd_unit_reload_outcomes[0].unit.reload()
|
|
43
|
+
for outcome in self.outcomes:
|
|
44
|
+
outcome.unit.reload()
|
|
51
45
|
|
|
52
46
|
def __eq__(self, other: object) -> bool:
|
|
53
47
|
"""Get equality based on attributes."""
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
import logging
|
|
4
4
|
from typing import List, Optional
|
|
5
5
|
|
|
6
|
-
from cyberfusion.QueueSupport.interfaces import OutcomeInterface
|
|
7
6
|
from cyberfusion.QueueSupport.items import _Item
|
|
8
7
|
from cyberfusion.QueueSupport.outcomes import (
|
|
9
8
|
SystemdUnitRestartItemRestartOutcome,
|
|
@@ -31,8 +30,8 @@ class SystemdUnitRestartItem(_Item):
|
|
|
31
30
|
self.unit = Unit(self.name)
|
|
32
31
|
|
|
33
32
|
@property
|
|
34
|
-
def outcomes(self) -> List[
|
|
35
|
-
"""Get outcomes of
|
|
33
|
+
def outcomes(self) -> List[SystemdUnitRestartItemRestartOutcome]:
|
|
34
|
+
"""Get outcomes of item."""
|
|
36
35
|
outcomes = []
|
|
37
36
|
|
|
38
37
|
outcomes.append(SystemdUnitRestartItemRestartOutcome(unit=self.unit))
|
|
@@ -41,13 +40,8 @@ class SystemdUnitRestartItem(_Item):
|
|
|
41
40
|
|
|
42
41
|
def fulfill(self) -> None:
|
|
43
42
|
"""Fulfill outcomes."""
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
for x in self.outcomes
|
|
47
|
-
if isinstance(x, SystemdUnitRestartItemRestartOutcome)
|
|
48
|
-
]
|
|
49
|
-
|
|
50
|
-
systemd_unit_restart_outcomes[0].unit.restart()
|
|
43
|
+
for outcome in self.outcomes:
|
|
44
|
+
outcome.unit.restart()
|
|
51
45
|
|
|
52
46
|
def __eq__(self, other: object) -> bool:
|
|
53
47
|
"""Get equality based on attributes."""
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
import logging
|
|
4
4
|
from typing import List, Optional
|
|
5
5
|
|
|
6
|
-
from cyberfusion.QueueSupport.interfaces import OutcomeInterface
|
|
7
6
|
from cyberfusion.QueueSupport.items import _Item
|
|
8
7
|
from cyberfusion.QueueSupport.outcomes import SystemdUnitStopItemStopOutcome
|
|
9
8
|
from cyberfusion.SystemdSupport.units import Unit
|
|
@@ -29,8 +28,8 @@ class SystemdUnitStopItem(_Item):
|
|
|
29
28
|
self.unit = Unit(self.name)
|
|
30
29
|
|
|
31
30
|
@property
|
|
32
|
-
def outcomes(self) -> List[
|
|
33
|
-
"""Get outcomes of
|
|
31
|
+
def outcomes(self) -> List[SystemdUnitStopItemStopOutcome]:
|
|
32
|
+
"""Get outcomes of item."""
|
|
34
33
|
outcomes = []
|
|
35
34
|
|
|
36
35
|
if self.unit.is_active:
|
|
@@ -40,12 +39,8 @@ class SystemdUnitStopItem(_Item):
|
|
|
40
39
|
|
|
41
40
|
def fulfill(self) -> None:
|
|
42
41
|
"""Fulfill outcomes."""
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
]
|
|
46
|
-
|
|
47
|
-
if systemd_unit_stop_outcomes:
|
|
48
|
-
systemd_unit_stop_outcomes[0].unit.stop()
|
|
42
|
+
for outcome in self.outcomes:
|
|
43
|
+
outcome.unit.stop()
|
|
49
44
|
|
|
50
45
|
def __eq__(self, other: object) -> bool:
|
|
51
46
|
"""Get equality based on attributes."""
|
|
@@ -5,7 +5,6 @@ import os
|
|
|
5
5
|
from typing import List, Optional
|
|
6
6
|
|
|
7
7
|
from cyberfusion.QueueSupport.exceptions import PathIsSymlinkError
|
|
8
|
-
from cyberfusion.QueueSupport.interfaces import OutcomeInterface
|
|
9
8
|
from cyberfusion.QueueSupport.items import _Item
|
|
10
9
|
from cyberfusion.QueueSupport.outcomes import UnlinkItemUnlinkOutcome
|
|
11
10
|
|
|
@@ -31,8 +30,8 @@ class UnlinkItem(_Item):
|
|
|
31
30
|
raise PathIsSymlinkError(self.path)
|
|
32
31
|
|
|
33
32
|
@property
|
|
34
|
-
def outcomes(self) -> List[
|
|
35
|
-
"""Get outcomes of
|
|
33
|
+
def outcomes(self) -> List[UnlinkItemUnlinkOutcome]:
|
|
34
|
+
"""Get outcomes of item."""
|
|
36
35
|
outcomes = []
|
|
37
36
|
|
|
38
37
|
if os.path.exists(self.path):
|
|
@@ -46,12 +45,8 @@ class UnlinkItem(_Item):
|
|
|
46
45
|
|
|
47
46
|
def fulfill(self) -> None:
|
|
48
47
|
"""Fulfill outcomes."""
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
]
|
|
52
|
-
|
|
53
|
-
if unlink_outcomes:
|
|
54
|
-
os.unlink(unlink_outcomes[0].path)
|
|
48
|
+
for outcome in self.outcomes:
|
|
49
|
+
os.unlink(outcome.path)
|
|
55
50
|
|
|
56
51
|
def __eq__(self, other: object) -> bool:
|
|
57
52
|
"""Get equality based on attributes."""
|
|
@@ -105,6 +105,25 @@ class UnlinkItemUnlinkOutcome(OutcomeInterface):
|
|
|
105
105
|
return other.path == self.path
|
|
106
106
|
|
|
107
107
|
|
|
108
|
+
class RmTreeItemRemoveOutcome(OutcomeInterface):
|
|
109
|
+
"""Represents outcome."""
|
|
110
|
+
|
|
111
|
+
def __init__(self, *, path: str) -> None:
|
|
112
|
+
"""Set attributes."""
|
|
113
|
+
self.path = path
|
|
114
|
+
|
|
115
|
+
def __str__(self) -> str:
|
|
116
|
+
"""Get human-readable string."""
|
|
117
|
+
return f"Remove directory tree {self.path}"
|
|
118
|
+
|
|
119
|
+
def __eq__(self, other: object) -> bool:
|
|
120
|
+
"""Get equality based on attributes."""
|
|
121
|
+
if not isinstance(other, RmTreeItemRemoveOutcome):
|
|
122
|
+
return False
|
|
123
|
+
|
|
124
|
+
return other.path == self.path
|
|
125
|
+
|
|
126
|
+
|
|
108
127
|
class CommandItemRunOutcome(OutcomeInterface):
|
|
109
128
|
"""Represents outcome."""
|
|
110
129
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: python3-cyberfusion-queue-support
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.2
|
|
4
4
|
Summary: Library to queue actions.
|
|
5
5
|
Author-email: Cyberfusion <support@cyberfusion.io>
|
|
6
6
|
Project-URL: Source, https://github.com/CyberfusionIO/python3-cyberfusion-queue-support
|
|
@@ -11,6 +11,43 @@ Requires-Dist: python3-cyberfusion-systemd-support~=1.0
|
|
|
11
11
|
|
|
12
12
|
Library to queue actions.
|
|
13
13
|
|
|
14
|
+
# Concepts
|
|
15
|
+
|
|
16
|
+
All project-specific terms are in _italic_.
|
|
17
|
+
|
|
18
|
+
After creating a _queue_, _items_ can be added to it.
|
|
19
|
+
|
|
20
|
+
```python
|
|
21
|
+
queue = Queue()
|
|
22
|
+
|
|
23
|
+
queue.add(item)
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
These _items_ can be of multiple types such as `ChmodItem` or `SystemdUnitRestartItem`, and they can have attributes such as a path for an `MkdirItem` or a unit name for a `SystemdUnitEnableItem`.
|
|
27
|
+
|
|
28
|
+
```python
|
|
29
|
+
item1 = ChmodItem(path="/tmp/example.txt", mode=0o600)
|
|
30
|
+
item2 = SystemdUnitEnableItem(name="httpd.service")
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Each _item_ type has one or multiple _outcomes_ that should come true for an _item_ of that type to be completed. For example: for an _item_ of type `UnlinkItem`, the _outcome_ is that the file at the path given with the _item_ is unlinked.
|
|
34
|
+
|
|
35
|
+
When a _queue_ is _processed_, all the _items_ added to it are _fulfilled_, meaning all the _items'_ _outcomes_ are completed.
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
item = RmTreeItem(path="/tmp/dir")
|
|
39
|
+
|
|
40
|
+
queue = Queue()
|
|
41
|
+
|
|
42
|
+
queue.add(item)
|
|
43
|
+
|
|
44
|
+
# for each item added to the queue, its fulfill() function is run
|
|
45
|
+
queue.process()
|
|
46
|
+
|
|
47
|
+
# this would do the same
|
|
48
|
+
item.fulfill()
|
|
49
|
+
```
|
|
50
|
+
|
|
14
51
|
# Install
|
|
15
52
|
|
|
16
53
|
## PyPI
|
|
@@ -13,6 +13,7 @@ src/cyberfusion/QueueSupport/items/command.py
|
|
|
13
13
|
src/cyberfusion/QueueSupport/items/copy.py
|
|
14
14
|
src/cyberfusion/QueueSupport/items/mkdir.py
|
|
15
15
|
src/cyberfusion/QueueSupport/items/move.py
|
|
16
|
+
src/cyberfusion/QueueSupport/items/rmtree.py
|
|
16
17
|
src/cyberfusion/QueueSupport/items/systemd_tmp_files_create.py
|
|
17
18
|
src/cyberfusion/QueueSupport/items/systemd_unit_disable.py
|
|
18
19
|
src/cyberfusion/QueueSupport/items/systemd_unit_enable.py
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
# python3-cyberfusion-queue-support
|
|
2
|
-
|
|
3
|
-
Library to queue actions.
|
|
4
|
-
|
|
5
|
-
# Install
|
|
6
|
-
|
|
7
|
-
## PyPI
|
|
8
|
-
|
|
9
|
-
Run the following command to install the package from PyPI:
|
|
10
|
-
|
|
11
|
-
pip3 install python3-cyberfusion-queue-support
|
|
12
|
-
|
|
13
|
-
## Debian
|
|
14
|
-
|
|
15
|
-
Run the following commands to build a Debian package:
|
|
16
|
-
|
|
17
|
-
mk-build-deps -i -t 'apt -o Debug::pkgProblemResolver=yes --no-install-recommends -y'
|
|
18
|
-
dpkg-buildpackage -us -uc
|
|
19
|
-
|
|
20
|
-
# Configure
|
|
21
|
-
|
|
22
|
-
No configuration is supported.
|
|
23
|
-
|
|
24
|
-
# Usage
|
|
25
|
-
|
|
26
|
-
## Example
|
|
27
|
-
|
|
28
|
-
```python
|
|
29
|
-
from cyberfusion.QueueSupport import Queue
|
|
30
|
-
from cyberfusion.QueueSupport.items.chmod import ChmodItem
|
|
31
|
-
|
|
32
|
-
queue = Queue()
|
|
33
|
-
|
|
34
|
-
item = ChmodItem(path="/tmp/example.txt", mode=0o600)
|
|
35
|
-
print(item.outcomes)
|
|
36
|
-
|
|
37
|
-
queue.add(item)
|
|
38
|
-
|
|
39
|
-
preview = True or False
|
|
40
|
-
|
|
41
|
-
outcomes = queue.process(preview=preview)
|
|
42
|
-
|
|
43
|
-
for outcome in outcomes:
|
|
44
|
-
print(str(outcome))
|
|
45
|
-
```
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|