python3-cyberfusion-queue-support 1.7.0__tar.gz → 2.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.7.0 → python3_cyberfusion_queue_support-2.2}/PKG-INFO +9 -1
- {python3_cyberfusion_queue_support-1.7.0 → python3_cyberfusion_queue_support-2.2}/README.md +4 -0
- {python3_cyberfusion_queue_support-1.7.0 → python3_cyberfusion_queue_support-2.2}/pyproject.toml +8 -1
- python3_cyberfusion_queue_support-2.2/src/cyberfusion/QueueSupport/__init__.py +150 -0
- python3_cyberfusion_queue_support-2.2/src/cyberfusion/QueueSupport/database.py +112 -0
- {python3_cyberfusion_queue_support-1.7.0 → python3_cyberfusion_queue_support-2.2}/src/cyberfusion/QueueSupport/interfaces.py +1 -1
- {python3_cyberfusion_queue_support-1.7.0 → python3_cyberfusion_queue_support-2.2}/src/cyberfusion/QueueSupport/items/__init__.py +13 -1
- {python3_cyberfusion_queue_support-1.7.0 → python3_cyberfusion_queue_support-2.2}/src/cyberfusion/QueueSupport/items/chmod.py +6 -2
- {python3_cyberfusion_queue_support-1.7.0 → python3_cyberfusion_queue_support-2.2}/src/cyberfusion/QueueSupport/items/chown.py +8 -2
- {python3_cyberfusion_queue_support-1.7.0 → python3_cyberfusion_queue_support-2.2}/src/cyberfusion/QueueSupport/items/command.py +6 -2
- {python3_cyberfusion_queue_support-1.7.0 → python3_cyberfusion_queue_support-2.2}/src/cyberfusion/QueueSupport/items/copy.py +6 -2
- python3_cyberfusion_queue_support-2.2/src/cyberfusion/QueueSupport/items/database_create.py +65 -0
- python3_cyberfusion_queue_support-2.2/src/cyberfusion/QueueSupport/items/database_drop.py +65 -0
- python3_cyberfusion_queue_support-2.2/src/cyberfusion/QueueSupport/items/database_user_drop.py +81 -0
- python3_cyberfusion_queue_support-2.2/src/cyberfusion/QueueSupport/items/database_user_ensure_state.py +100 -0
- python3_cyberfusion_queue_support-2.2/src/cyberfusion/QueueSupport/items/database_user_grant_grant.py +104 -0
- python3_cyberfusion_queue_support-2.2/src/cyberfusion/QueueSupport/items/database_user_grant_revoke.py +104 -0
- {python3_cyberfusion_queue_support-1.7.0 → python3_cyberfusion_queue_support-2.2}/src/cyberfusion/QueueSupport/items/mkdir.py +6 -2
- {python3_cyberfusion_queue_support-1.7.0 → python3_cyberfusion_queue_support-2.2}/src/cyberfusion/QueueSupport/items/move.py +6 -2
- {python3_cyberfusion_queue_support-1.7.0 → python3_cyberfusion_queue_support-2.2}/src/cyberfusion/QueueSupport/items/rmtree.py +6 -2
- {python3_cyberfusion_queue_support-1.7.0 → python3_cyberfusion_queue_support-2.2}/src/cyberfusion/QueueSupport/items/systemd_daemon_reload.py +6 -2
- {python3_cyberfusion_queue_support-1.7.0 → python3_cyberfusion_queue_support-2.2}/src/cyberfusion/QueueSupport/items/systemd_tmp_files_create.py +6 -2
- {python3_cyberfusion_queue_support-1.7.0 → python3_cyberfusion_queue_support-2.2}/src/cyberfusion/QueueSupport/items/systemd_unit_disable.py +6 -2
- {python3_cyberfusion_queue_support-1.7.0 → python3_cyberfusion_queue_support-2.2}/src/cyberfusion/QueueSupport/items/systemd_unit_enable.py +6 -2
- {python3_cyberfusion_queue_support-1.7.0 → python3_cyberfusion_queue_support-2.2}/src/cyberfusion/QueueSupport/items/systemd_unit_reload.py +6 -2
- {python3_cyberfusion_queue_support-1.7.0 → python3_cyberfusion_queue_support-2.2}/src/cyberfusion/QueueSupport/items/systemd_unit_restart.py +6 -2
- {python3_cyberfusion_queue_support-1.7.0 → python3_cyberfusion_queue_support-2.2}/src/cyberfusion/QueueSupport/items/systemd_unit_start.py +6 -2
- {python3_cyberfusion_queue_support-1.7.0 → python3_cyberfusion_queue_support-2.2}/src/cyberfusion/QueueSupport/items/systemd_unit_stop.py +6 -2
- {python3_cyberfusion_queue_support-1.7.0 → python3_cyberfusion_queue_support-2.2}/src/cyberfusion/QueueSupport/items/unlink.py +6 -2
- {python3_cyberfusion_queue_support-1.7.0 → python3_cyberfusion_queue_support-2.2}/src/cyberfusion/QueueSupport/outcomes.py +201 -4
- python3_cyberfusion_queue_support-2.2/src/cyberfusion/QueueSupport/settings.py +14 -0
- {python3_cyberfusion_queue_support-1.7.0 → python3_cyberfusion_queue_support-2.2}/src/python3_cyberfusion_queue_support.egg-info/PKG-INFO +9 -1
- {python3_cyberfusion_queue_support-1.7.0 → python3_cyberfusion_queue_support-2.2}/src/python3_cyberfusion_queue_support.egg-info/SOURCES.txt +9 -0
- python3_cyberfusion_queue_support-2.2/src/python3_cyberfusion_queue_support.egg-info/entry_points.txt +2 -0
- python3_cyberfusion_queue_support-2.2/src/python3_cyberfusion_queue_support.egg-info/requires.txt +5 -0
- python3_cyberfusion_queue_support-1.7.0/src/cyberfusion/QueueSupport/__init__.py +0 -72
- python3_cyberfusion_queue_support-1.7.0/src/python3_cyberfusion_queue_support.egg-info/requires.txt +0 -1
- {python3_cyberfusion_queue_support-1.7.0 → python3_cyberfusion_queue_support-2.2}/setup.cfg +0 -0
- {python3_cyberfusion_queue_support-1.7.0 → python3_cyberfusion_queue_support-2.2}/src/cyberfusion/QueueSupport/exceptions/__init__.py +0 -0
- {python3_cyberfusion_queue_support-1.7.0 → python3_cyberfusion_queue_support-2.2}/src/cyberfusion/QueueSupport/utilities.py +0 -0
- {python3_cyberfusion_queue_support-1.7.0 → python3_cyberfusion_queue_support-2.2}/src/python3_cyberfusion_queue_support.egg-info/dependency_links.txt +0 -0
- {python3_cyberfusion_queue_support-1.7.0 → python3_cyberfusion_queue_support-2.2}/src/python3_cyberfusion_queue_support.egg-info/top_level.txt +0 -0
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: python3-cyberfusion-queue-support
|
|
3
|
-
Version:
|
|
3
|
+
Version: 2.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
|
|
7
7
|
Description-Content-Type: text/markdown
|
|
8
8
|
Requires-Dist: python3-cyberfusion-systemd-support~=2.1
|
|
9
|
+
Requires-Dist: python3-cyberfusion-database-support~=3.0
|
|
10
|
+
Requires-Dist: alembic==1.8.1
|
|
11
|
+
Requires-Dist: SQLAlchemy==1.4.46
|
|
12
|
+
Requires-Dist: pydantic[dotenv]==1.10.4
|
|
9
13
|
|
|
10
14
|
# python3-cyberfusion-queue-support
|
|
11
15
|
|
|
@@ -46,6 +50,10 @@ Run the following command to install the package from PyPI:
|
|
|
46
50
|
|
|
47
51
|
pip3 install python3-cyberfusion-queue-support
|
|
48
52
|
|
|
53
|
+
Then, run database migrations:
|
|
54
|
+
|
|
55
|
+
bin/queue-support-migrate
|
|
56
|
+
|
|
49
57
|
## Debian
|
|
50
58
|
|
|
51
59
|
Run the following commands to build a Debian package:
|
|
@@ -37,6 +37,10 @@ Run the following command to install the package from PyPI:
|
|
|
37
37
|
|
|
38
38
|
pip3 install python3-cyberfusion-queue-support
|
|
39
39
|
|
|
40
|
+
Then, run database migrations:
|
|
41
|
+
|
|
42
|
+
bin/queue-support-migrate
|
|
43
|
+
|
|
40
44
|
## Debian
|
|
41
45
|
|
|
42
46
|
Run the following commands to build a Debian package:
|
{python3_cyberfusion_queue_support-1.7.0 → python3_cyberfusion_queue_support-2.2}/pyproject.toml
RENAMED
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "python3-cyberfusion-queue-support"
|
|
7
|
-
version = "
|
|
7
|
+
version = "2.2"
|
|
8
8
|
description = "Library to queue actions."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
authors = [
|
|
@@ -12,7 +12,14 @@ authors = [
|
|
|
12
12
|
]
|
|
13
13
|
dependencies = [
|
|
14
14
|
"python3-cyberfusion-systemd-support~=2.1",
|
|
15
|
+
"python3-cyberfusion-database-support~=3.0",
|
|
16
|
+
"alembic==1.8.1",
|
|
17
|
+
"SQLAlchemy==1.4.46",
|
|
18
|
+
"pydantic[dotenv]==1.10.4",
|
|
15
19
|
]
|
|
16
20
|
|
|
17
21
|
[project.urls]
|
|
18
22
|
"Source" = "https://github.com/CyberfusionIO/python3-cyberfusion-queue-support"
|
|
23
|
+
|
|
24
|
+
[project.scripts]
|
|
25
|
+
queue-support-migrate = "cyberfusion.QueueSupport.database:run_migrations"
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"""Classes for queue."""
|
|
2
|
+
|
|
3
|
+
import logging
|
|
4
|
+
from copy import copy
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
from typing import List
|
|
7
|
+
|
|
8
|
+
from cyberfusion.QueueSupport.database import (
|
|
9
|
+
Queue as QueueModel,
|
|
10
|
+
QueueItem,
|
|
11
|
+
make_database_session,
|
|
12
|
+
QueueItemOutcome,
|
|
13
|
+
QueueProcess,
|
|
14
|
+
)
|
|
15
|
+
from cyberfusion.QueueSupport.exceptions import QueueFulfillFailed
|
|
16
|
+
from cyberfusion.QueueSupport.interfaces import OutcomeInterface
|
|
17
|
+
from cyberfusion.QueueSupport.items import _Item
|
|
18
|
+
|
|
19
|
+
logger = logging.getLogger(__name__)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@dataclass
|
|
23
|
+
class QueueItemMapping:
|
|
24
|
+
"""Queue item mapping."""
|
|
25
|
+
|
|
26
|
+
item: _Item
|
|
27
|
+
database_object: QueueItem
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class Queue:
|
|
31
|
+
"""Represents queue."""
|
|
32
|
+
|
|
33
|
+
def __init__(self) -> None:
|
|
34
|
+
"""Set attributes."""
|
|
35
|
+
self.item_mappings: List[QueueItemMapping] = []
|
|
36
|
+
|
|
37
|
+
self._database_session = make_database_session()
|
|
38
|
+
|
|
39
|
+
object_ = QueueModel()
|
|
40
|
+
|
|
41
|
+
self._database_session.add(object_)
|
|
42
|
+
self._database_session.commit()
|
|
43
|
+
|
|
44
|
+
self.queue_database_object = object_
|
|
45
|
+
|
|
46
|
+
def add(self, item: _Item, *, run_duplicate_last: bool = True) -> None:
|
|
47
|
+
"""Add item to queue."""
|
|
48
|
+
deduplicated = False
|
|
49
|
+
|
|
50
|
+
existing_item_index = next(
|
|
51
|
+
(
|
|
52
|
+
index
|
|
53
|
+
for index, item_mapping in enumerate(self.item_mappings)
|
|
54
|
+
if item_mapping.item == item
|
|
55
|
+
),
|
|
56
|
+
None,
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
if existing_item_index is not None:
|
|
60
|
+
if run_duplicate_last:
|
|
61
|
+
self.item_mappings[
|
|
62
|
+
existing_item_index
|
|
63
|
+
].database_object.deduplicated = True
|
|
64
|
+
|
|
65
|
+
self._database_session.commit()
|
|
66
|
+
else:
|
|
67
|
+
deduplicated = True
|
|
68
|
+
|
|
69
|
+
item_dict = copy(item.__dict__)
|
|
70
|
+
|
|
71
|
+
del item_dict["_reference"]
|
|
72
|
+
del item_dict["_hide_outcomes"]
|
|
73
|
+
|
|
74
|
+
object_ = QueueItem(
|
|
75
|
+
queue=self.queue_database_object,
|
|
76
|
+
type=item.__class__.__name__,
|
|
77
|
+
reference=item.reference,
|
|
78
|
+
hide_outcomes=item.hide_outcomes,
|
|
79
|
+
deduplicated=deduplicated,
|
|
80
|
+
attributes=item_dict,
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
self._database_session.add(object_)
|
|
84
|
+
self._database_session.commit()
|
|
85
|
+
|
|
86
|
+
self.item_mappings.append(QueueItemMapping(item, object_))
|
|
87
|
+
|
|
88
|
+
def process(self, preview: bool) -> List[OutcomeInterface]:
|
|
89
|
+
"""Process items."""
|
|
90
|
+
logger.debug("Processing items")
|
|
91
|
+
|
|
92
|
+
process_object = QueueProcess(
|
|
93
|
+
queue_id=self.queue_database_object.id,
|
|
94
|
+
preview=preview,
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
self._database_session.add(process_object)
|
|
98
|
+
self._database_session.commit()
|
|
99
|
+
|
|
100
|
+
outcomes = []
|
|
101
|
+
|
|
102
|
+
for item_mapping in [
|
|
103
|
+
item_mapping
|
|
104
|
+
for item_mapping in self.item_mappings
|
|
105
|
+
if not item_mapping.database_object.deduplicated
|
|
106
|
+
]:
|
|
107
|
+
logger.debug(
|
|
108
|
+
"Processing item with id '%s'", item_mapping.database_object.id
|
|
109
|
+
)
|
|
110
|
+
|
|
111
|
+
if preview:
|
|
112
|
+
if not item_mapping.item.hide_outcomes:
|
|
113
|
+
outcomes.extend(item_mapping.item.outcomes)
|
|
114
|
+
else:
|
|
115
|
+
try:
|
|
116
|
+
logger.debug(
|
|
117
|
+
"Fulfilling item with id '%s'", item_mapping.database_object.id
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
fulfill_outcomes = item_mapping.item.fulfill()
|
|
121
|
+
|
|
122
|
+
if not item_mapping.item.hide_outcomes:
|
|
123
|
+
outcomes.extend(fulfill_outcomes)
|
|
124
|
+
|
|
125
|
+
logger.debug(
|
|
126
|
+
"Fulfilled item with id '%s'", item_mapping.database_object.id
|
|
127
|
+
)
|
|
128
|
+
except QueueFulfillFailed:
|
|
129
|
+
raise
|
|
130
|
+
except Exception as e:
|
|
131
|
+
raise QueueFulfillFailed(
|
|
132
|
+
item_mapping.item,
|
|
133
|
+
) from e
|
|
134
|
+
|
|
135
|
+
for outcome in outcomes:
|
|
136
|
+
outcome_object = QueueItemOutcome(
|
|
137
|
+
queue_item=item_mapping.database_object,
|
|
138
|
+
queue_process=process_object,
|
|
139
|
+
type=outcome.__class__.__name__,
|
|
140
|
+
attributes=outcome.__dict__,
|
|
141
|
+
)
|
|
142
|
+
|
|
143
|
+
self._database_session.add(outcome_object)
|
|
144
|
+
self._database_session.commit()
|
|
145
|
+
|
|
146
|
+
logger.debug("Processed item with id '%s'", item_mapping.database_object.id)
|
|
147
|
+
|
|
148
|
+
logger.debug("Processed items")
|
|
149
|
+
|
|
150
|
+
return outcomes
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
from alembic.config import Config
|
|
2
|
+
from alembic import command
|
|
3
|
+
import sqlite3
|
|
4
|
+
from datetime import datetime, timezone
|
|
5
|
+
from sqlalchemy.pool.base import _ConnectionRecord
|
|
6
|
+
from sqlalchemy import ForeignKey, MetaData, Boolean
|
|
7
|
+
from sqlalchemy import create_engine, Column, DateTime, Integer, String
|
|
8
|
+
from sqlalchemy.orm import Session, sessionmaker, relationship
|
|
9
|
+
from sqlalchemy.ext.declarative import declarative_base
|
|
10
|
+
from sqlalchemy.engine import Engine
|
|
11
|
+
from sqlalchemy import event
|
|
12
|
+
from sqlalchemy.types import JSON
|
|
13
|
+
|
|
14
|
+
from cyberfusion.QueueSupport.settings import settings
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@event.listens_for(Engine, "connect") # type: ignore[misc]
|
|
18
|
+
def set_sqlite_pragma(
|
|
19
|
+
dbapi_connection: sqlite3.Connection, connection_record: _ConnectionRecord
|
|
20
|
+
) -> None:
|
|
21
|
+
"""Enable foreign key support.
|
|
22
|
+
|
|
23
|
+
This is needed for cascade deletes to work.
|
|
24
|
+
|
|
25
|
+
See https://docs.sqlalchemy.org/en/13/dialects/sqlite.html#sqlite-foreign-keys
|
|
26
|
+
"""
|
|
27
|
+
cursor = dbapi_connection.cursor()
|
|
28
|
+
|
|
29
|
+
cursor.execute("PRAGMA foreign_keys=ON")
|
|
30
|
+
|
|
31
|
+
cursor.close()
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def run_migrations() -> None:
|
|
35
|
+
"""Upgrade database schema to latest version."""
|
|
36
|
+
alembic_config = Config(file_=settings.alembic_config_file_path)
|
|
37
|
+
alembic_config.set_main_option("sqlalchemy.url", settings.database_path)
|
|
38
|
+
|
|
39
|
+
command.upgrade(alembic_config, "head")
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def make_database_session() -> Session:
|
|
43
|
+
engine = create_engine(
|
|
44
|
+
settings.database_path, connect_args={"check_same_thread": False}
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
return sessionmaker(bind=engine)()
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
naming_convention = {
|
|
51
|
+
"ix": "ix_%(column_0_label)s",
|
|
52
|
+
"uq": "uq_%(table_name)s_%(column_0_name)s",
|
|
53
|
+
"ck": "ck_%(table_name)s_%(constraint_name)s",
|
|
54
|
+
"fk": "fk_%(table_name)s_%(column_0_name)s_%(referred_table_name)s",
|
|
55
|
+
"pk": "pk_%(table_name)s",
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
metadata = MetaData(naming_convention=naming_convention)
|
|
59
|
+
|
|
60
|
+
Base = declarative_base(metadata=metadata)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
class BaseModel(Base): # type: ignore[misc, valid-type]
|
|
64
|
+
"""Base model."""
|
|
65
|
+
|
|
66
|
+
__abstract__ = True
|
|
67
|
+
|
|
68
|
+
id = Column(Integer, primary_key=True)
|
|
69
|
+
created_at = Column(DateTime, default=datetime.now(timezone.utc), nullable=False)
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
class Queue(BaseModel):
|
|
73
|
+
"""Queue model."""
|
|
74
|
+
|
|
75
|
+
__tablename__ = "queues"
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
class QueueProcess(BaseModel):
|
|
79
|
+
"""QueueProcess model."""
|
|
80
|
+
|
|
81
|
+
__tablename__ = "queue_processes"
|
|
82
|
+
|
|
83
|
+
queue_id = Column(Integer, ForeignKey("queues.id"), nullable=False)
|
|
84
|
+
queue = relationship("Queue")
|
|
85
|
+
preview = Column(Boolean, nullable=False)
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
class QueueItem(BaseModel):
|
|
89
|
+
"""QueueItem model."""
|
|
90
|
+
|
|
91
|
+
__tablename__ = "queue_items"
|
|
92
|
+
|
|
93
|
+
queue_id = Column(Integer, ForeignKey("queues.id"), nullable=False)
|
|
94
|
+
queue = relationship("Queue")
|
|
95
|
+
type = Column(String(length=255), nullable=False)
|
|
96
|
+
reference = Column(String(length=255), nullable=True)
|
|
97
|
+
hide_outcomes = Column(Boolean, nullable=False)
|
|
98
|
+
deduplicated = Column(Boolean, nullable=False)
|
|
99
|
+
attributes = Column(JSON, nullable=False)
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
class QueueItemOutcome(BaseModel):
|
|
103
|
+
"""QueueItemOutcome model."""
|
|
104
|
+
|
|
105
|
+
__tablename__ = "queue_item_outcomes"
|
|
106
|
+
|
|
107
|
+
queue_item_id = Column(Integer, ForeignKey("queue_items.id"), nullable=False)
|
|
108
|
+
queue_item = relationship("QueueItem")
|
|
109
|
+
queue_process_id = Column(Integer, ForeignKey("queue_processes.id"), nullable=False)
|
|
110
|
+
queue_process = relationship("QueueProcess")
|
|
111
|
+
type = Column(String(length=255), nullable=False)
|
|
112
|
+
attributes = Column(JSON, nullable=False)
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"""Items."""
|
|
2
2
|
|
|
3
3
|
import logging
|
|
4
|
+
from abc import ABC, abstractmethod
|
|
4
5
|
from typing import Optional
|
|
5
6
|
|
|
6
7
|
from cyberfusion.QueueSupport.interfaces import ItemInterface
|
|
@@ -8,9 +9,20 @@ from cyberfusion.QueueSupport.interfaces import ItemInterface
|
|
|
8
9
|
logger = logging.getLogger(__name__)
|
|
9
10
|
|
|
10
11
|
|
|
11
|
-
class _Item(ItemInterface):
|
|
12
|
+
class _Item(ItemInterface, ABC):
|
|
12
13
|
"""Represents base item."""
|
|
13
14
|
|
|
15
|
+
@abstractmethod
|
|
16
|
+
def __init__(
|
|
17
|
+
self,
|
|
18
|
+
*,
|
|
19
|
+
reference: Optional[str] = None,
|
|
20
|
+
hide_outcomes: bool = False,
|
|
21
|
+
) -> None: # pragma: no cover
|
|
22
|
+
"""Set attributes."""
|
|
23
|
+
self._reference = reference
|
|
24
|
+
self._hide_outcomes = hide_outcomes
|
|
25
|
+
|
|
14
26
|
@property
|
|
15
27
|
def hide_outcomes(self) -> bool:
|
|
16
28
|
"""Get if outcomes should be hidden."""
|
|
@@ -56,11 +56,15 @@ class ChmodItem(_Item):
|
|
|
56
56
|
|
|
57
57
|
return outcomes
|
|
58
58
|
|
|
59
|
-
def fulfill(self) ->
|
|
59
|
+
def fulfill(self) -> List[ChmodItemModeChangeOutcome]:
|
|
60
60
|
"""Fulfill outcomes."""
|
|
61
|
-
|
|
61
|
+
outcomes = self.outcomes
|
|
62
|
+
|
|
63
|
+
for outcome in outcomes:
|
|
62
64
|
os.chmod(outcome.path, outcome.new_mode)
|
|
63
65
|
|
|
66
|
+
return outcomes
|
|
67
|
+
|
|
64
68
|
def __eq__(self, other: object) -> bool:
|
|
65
69
|
"""Get equality based on attributes."""
|
|
66
70
|
if not isinstance(other, ChmodItem):
|
|
@@ -106,9 +106,13 @@ class ChownItem(_Item):
|
|
|
106
106
|
|
|
107
107
|
return outcomes
|
|
108
108
|
|
|
109
|
-
def fulfill(
|
|
109
|
+
def fulfill(
|
|
110
|
+
self,
|
|
111
|
+
) -> List[ChownItemOwnerChangeOutcome | ChownItemGroupChangeOutcome]:
|
|
110
112
|
"""Fulfill outcomes."""
|
|
111
|
-
|
|
113
|
+
outcomes = self.outcomes
|
|
114
|
+
|
|
115
|
+
for outcome in outcomes:
|
|
112
116
|
if isinstance(outcome, ChownItemOwnerChangeOutcome):
|
|
113
117
|
os.chown(
|
|
114
118
|
outcome.path,
|
|
@@ -122,6 +126,8 @@ class ChownItem(_Item):
|
|
|
122
126
|
gid=get_gid(outcome.new_group_name),
|
|
123
127
|
)
|
|
124
128
|
|
|
129
|
+
return outcomes
|
|
130
|
+
|
|
125
131
|
def __eq__(self, other: object) -> bool:
|
|
126
132
|
"""Get equality based on attributes."""
|
|
127
133
|
if not isinstance(other, ChownItem):
|
|
@@ -35,9 +35,11 @@ class CommandItem(_Item):
|
|
|
35
35
|
|
|
36
36
|
return outcomes
|
|
37
37
|
|
|
38
|
-
def fulfill(self) ->
|
|
38
|
+
def fulfill(self) -> List[CommandItemRunOutcome]:
|
|
39
39
|
"""Fulfill outcomes."""
|
|
40
|
-
|
|
40
|
+
outcomes = self.outcomes
|
|
41
|
+
|
|
42
|
+
for outcome in outcomes:
|
|
41
43
|
try:
|
|
42
44
|
output = subprocess.run(
|
|
43
45
|
outcome.command,
|
|
@@ -53,6 +55,8 @@ class CommandItem(_Item):
|
|
|
53
55
|
self, command=outcome.command, stdout=e.stdout, stderr=e.stderr
|
|
54
56
|
) from e
|
|
55
57
|
|
|
58
|
+
return outcomes
|
|
59
|
+
|
|
56
60
|
def __eq__(self, other: object) -> bool:
|
|
57
61
|
"""Get equality based on attributes."""
|
|
58
62
|
if not isinstance(other, CommandItem):
|
|
@@ -94,11 +94,15 @@ class CopyItem(_Item):
|
|
|
94
94
|
|
|
95
95
|
return outcomes
|
|
96
96
|
|
|
97
|
-
def fulfill(self) ->
|
|
97
|
+
def fulfill(self) -> List[CopyItemCopyOutcome]:
|
|
98
98
|
"""Fulfill outcomes."""
|
|
99
|
-
|
|
99
|
+
outcomes = self.outcomes
|
|
100
|
+
|
|
101
|
+
for outcome in outcomes:
|
|
100
102
|
shutil.copyfile(outcome.source, outcome.destination)
|
|
101
103
|
|
|
104
|
+
return outcomes
|
|
105
|
+
|
|
102
106
|
def __eq__(self, other: object) -> bool:
|
|
103
107
|
"""Get equality based on attributes."""
|
|
104
108
|
if not isinstance(other, CopyItem):
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"""Item."""
|
|
2
|
+
|
|
3
|
+
import logging
|
|
4
|
+
from typing import List, Optional
|
|
5
|
+
|
|
6
|
+
from cyberfusion.QueueSupport.items import _Item
|
|
7
|
+
from cyberfusion.QueueSupport.outcomes import DatabaseCreateItemCreateOutcome
|
|
8
|
+
|
|
9
|
+
from cyberfusion.DatabaseSupport.databases import Database
|
|
10
|
+
from cyberfusion.DatabaseSupport import DatabaseSupport
|
|
11
|
+
|
|
12
|
+
logger = logging.getLogger(__name__)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class DatabaseCreateItem(_Item):
|
|
16
|
+
"""Represents item."""
|
|
17
|
+
|
|
18
|
+
def __init__(
|
|
19
|
+
self,
|
|
20
|
+
*,
|
|
21
|
+
server_software_name: str,
|
|
22
|
+
name: str,
|
|
23
|
+
reference: Optional[str] = None,
|
|
24
|
+
hide_outcomes: bool = False,
|
|
25
|
+
) -> None:
|
|
26
|
+
"""Set attributes."""
|
|
27
|
+
self.server_software_name = server_software_name
|
|
28
|
+
self.name = name
|
|
29
|
+
self._reference = reference
|
|
30
|
+
self._hide_outcomes = hide_outcomes
|
|
31
|
+
|
|
32
|
+
self.database = Database(
|
|
33
|
+
support=DatabaseSupport(server_software_names=[self.server_software_name]),
|
|
34
|
+
name=self.name,
|
|
35
|
+
server_software_name=self.server_software_name,
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
@property
|
|
39
|
+
def outcomes(self) -> List[DatabaseCreateItemCreateOutcome]:
|
|
40
|
+
"""Get outcomes of item."""
|
|
41
|
+
outcomes = []
|
|
42
|
+
|
|
43
|
+
if not self.database.exists:
|
|
44
|
+
outcomes.append(DatabaseCreateItemCreateOutcome(database=self.database))
|
|
45
|
+
|
|
46
|
+
return outcomes
|
|
47
|
+
|
|
48
|
+
def fulfill(self) -> List[DatabaseCreateItemCreateOutcome]:
|
|
49
|
+
"""Fulfill outcomes."""
|
|
50
|
+
outcomes = self.outcomes
|
|
51
|
+
|
|
52
|
+
for outcome in outcomes:
|
|
53
|
+
outcome.database.create()
|
|
54
|
+
|
|
55
|
+
return outcomes
|
|
56
|
+
|
|
57
|
+
def __eq__(self, other: object) -> bool:
|
|
58
|
+
"""Get equality based on attributes."""
|
|
59
|
+
if not isinstance(other, DatabaseCreateItem):
|
|
60
|
+
return False
|
|
61
|
+
|
|
62
|
+
return (
|
|
63
|
+
other.server_software_name == self.server_software_name
|
|
64
|
+
and other.name == self.name
|
|
65
|
+
)
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"""Item."""
|
|
2
|
+
|
|
3
|
+
import logging
|
|
4
|
+
from typing import List, Optional
|
|
5
|
+
|
|
6
|
+
from cyberfusion.QueueSupport.items import _Item
|
|
7
|
+
from cyberfusion.QueueSupport.outcomes import DatabaseDropItemDropOutcome
|
|
8
|
+
|
|
9
|
+
from cyberfusion.DatabaseSupport.databases import Database
|
|
10
|
+
from cyberfusion.DatabaseSupport import DatabaseSupport
|
|
11
|
+
|
|
12
|
+
logger = logging.getLogger(__name__)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class DatabaseDropItem(_Item):
|
|
16
|
+
"""Represents item."""
|
|
17
|
+
|
|
18
|
+
def __init__(
|
|
19
|
+
self,
|
|
20
|
+
*,
|
|
21
|
+
server_software_name: str,
|
|
22
|
+
name: str,
|
|
23
|
+
reference: Optional[str] = None,
|
|
24
|
+
hide_outcomes: bool = False,
|
|
25
|
+
) -> None:
|
|
26
|
+
"""Set attributes."""
|
|
27
|
+
self.server_software_name = server_software_name
|
|
28
|
+
self.name = name
|
|
29
|
+
self._reference = reference
|
|
30
|
+
self._hide_outcomes = hide_outcomes
|
|
31
|
+
|
|
32
|
+
self.database = Database(
|
|
33
|
+
support=DatabaseSupport(server_software_names=[self.server_software_name]),
|
|
34
|
+
name=self.name,
|
|
35
|
+
server_software_name=self.server_software_name,
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
@property
|
|
39
|
+
def outcomes(self) -> List[DatabaseDropItemDropOutcome]:
|
|
40
|
+
"""Get outcomes of item."""
|
|
41
|
+
outcomes = []
|
|
42
|
+
|
|
43
|
+
if self.database.exists:
|
|
44
|
+
outcomes.append(DatabaseDropItemDropOutcome(database=self.database))
|
|
45
|
+
|
|
46
|
+
return outcomes
|
|
47
|
+
|
|
48
|
+
def fulfill(self) -> List[DatabaseDropItemDropOutcome]:
|
|
49
|
+
"""Fulfill outcomes."""
|
|
50
|
+
outcomes = self.outcomes
|
|
51
|
+
|
|
52
|
+
for outcome in outcomes:
|
|
53
|
+
outcome.database.drop()
|
|
54
|
+
|
|
55
|
+
return outcomes
|
|
56
|
+
|
|
57
|
+
def __eq__(self, other: object) -> bool:
|
|
58
|
+
"""Get equality based on attributes."""
|
|
59
|
+
if not isinstance(other, DatabaseDropItem):
|
|
60
|
+
return False
|
|
61
|
+
|
|
62
|
+
return (
|
|
63
|
+
other.server_software_name == self.server_software_name
|
|
64
|
+
and other.name == self.name
|
|
65
|
+
)
|
python3_cyberfusion_queue_support-2.2/src/cyberfusion/QueueSupport/items/database_user_drop.py
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"""Item."""
|
|
2
|
+
|
|
3
|
+
import logging
|
|
4
|
+
from typing import List, Optional
|
|
5
|
+
|
|
6
|
+
from cyberfusion.DatabaseSupport.database_users import DatabaseUser
|
|
7
|
+
from cyberfusion.DatabaseSupport.servers import Server
|
|
8
|
+
|
|
9
|
+
from cyberfusion.QueueSupport.items import _Item
|
|
10
|
+
from cyberfusion.QueueSupport.outcomes import (
|
|
11
|
+
DatabaseUserDropItemDropOutcome,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
from cyberfusion.DatabaseSupport import DatabaseSupport
|
|
15
|
+
|
|
16
|
+
logger = logging.getLogger(__name__)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class DatabaseUserDropItem(_Item):
|
|
20
|
+
"""Represents item."""
|
|
21
|
+
|
|
22
|
+
def __init__(
|
|
23
|
+
self,
|
|
24
|
+
*,
|
|
25
|
+
server_software_name: str,
|
|
26
|
+
name: str,
|
|
27
|
+
host: Optional[str] = None,
|
|
28
|
+
reference: Optional[str] = None,
|
|
29
|
+
hide_outcomes: bool = False,
|
|
30
|
+
) -> None:
|
|
31
|
+
"""Set attributes."""
|
|
32
|
+
self.server_software_name = server_software_name
|
|
33
|
+
self.name = name
|
|
34
|
+
self._host = host
|
|
35
|
+
self._reference = reference
|
|
36
|
+
self._hide_outcomes = hide_outcomes
|
|
37
|
+
|
|
38
|
+
self.database_user = DatabaseUser(
|
|
39
|
+
server=Server(
|
|
40
|
+
support=DatabaseSupport(
|
|
41
|
+
server_software_names=[self.server_software_name]
|
|
42
|
+
)
|
|
43
|
+
),
|
|
44
|
+
name=self.name,
|
|
45
|
+
server_software_name=self.server_software_name,
|
|
46
|
+
host=self._host,
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
@property
|
|
50
|
+
def outcomes(
|
|
51
|
+
self,
|
|
52
|
+
) -> List[DatabaseUserDropItemDropOutcome]:
|
|
53
|
+
"""Get outcomes of item."""
|
|
54
|
+
outcomes = []
|
|
55
|
+
|
|
56
|
+
if self.database_user.exists:
|
|
57
|
+
outcomes.append(
|
|
58
|
+
DatabaseUserDropItemDropOutcome(database_user=self.database_user)
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
return outcomes
|
|
62
|
+
|
|
63
|
+
def fulfill(self) -> List[DatabaseUserDropItemDropOutcome]:
|
|
64
|
+
"""Fulfill outcomes."""
|
|
65
|
+
outcomes = self.outcomes
|
|
66
|
+
|
|
67
|
+
for outcome in outcomes:
|
|
68
|
+
outcome.database_user.drop()
|
|
69
|
+
|
|
70
|
+
return outcomes
|
|
71
|
+
|
|
72
|
+
def __eq__(self, other: object) -> bool:
|
|
73
|
+
"""Get equality based on attributes."""
|
|
74
|
+
if not isinstance(other, DatabaseUserDropItem):
|
|
75
|
+
return False
|
|
76
|
+
|
|
77
|
+
return (
|
|
78
|
+
other.server_software_name == self.server_software_name
|
|
79
|
+
and other.name == self.name
|
|
80
|
+
and other._host == self._host
|
|
81
|
+
)
|