Added transaction.py
Allow for transactions to be created, controlling and managing operation goals. enum@PkgGoal: - An enumaration of all possible package goals which a transaction can perform. class@Transaction: - Create a new transaction for the given context of a comment (specified by the `goal=`). - method@compute: - Compute all the system dependencies and return them as a tuple. Note, dependencies that soypak can install will not be listed here and included in the final state. - method@apply: - Will apply the goal to the transaction and handle the appropriate operations call. - method@problems: - Report a tuple of packages which were identified as problematic during the transaction goal. - method@commit: - Commit the transaction to record to inform what exactly happened during that transaction, i.e., the goal. -method@finalised: - Return a list of the final state, i.e., those packages related to the transaction goal.
This commit is contained in:
parent
7407ba1084
commit
18634e7794
53
soypak/deps/transaction.py
Normal file
53
soypak/deps/transaction.py
Normal file
|
|
@ -0,0 +1,53 @@
|
||||||
|
import enum
|
||||||
|
import sys
|
||||||
|
import clog
|
||||||
|
import soypak.deps.bottler as bottler
|
||||||
|
import soypak.deps.operations as ops
|
||||||
|
|
||||||
|
|
||||||
|
_log = clog.Logger.get("runtime_logger")
|
||||||
|
|
||||||
|
|
||||||
|
class PkgGoal(enum.Enum):
|
||||||
|
PKG_INSTALL = 1
|
||||||
|
|
||||||
|
|
||||||
|
class Transaction:
|
||||||
|
def __init__(self, goal: PkgGoal) -> None:
|
||||||
|
"""Setup a new transaction."""
|
||||||
|
if not isinstance(goal, PkgGoal):
|
||||||
|
_log.error(f"TypeError: {goal=}, expected PkgGoal.")
|
||||||
|
_log.printLog("There was an issue when operating on the transaction.", level=4)
|
||||||
|
sys.exit(1)
|
||||||
|
self.pkg_goal: PkgGoal = goal
|
||||||
|
|
||||||
|
|
||||||
|
def compute(self, pkgs: list[bottler._Soybottle]) -> tuple:
|
||||||
|
"""Compute dependencies and conflicts of packages. Returns a list of total packages to install."""
|
||||||
|
self._final_state = []
|
||||||
|
sys_depends = []
|
||||||
|
for pkg in pkgs:
|
||||||
|
...
|
||||||
|
# :@TODO: compute the dependencies
|
||||||
|
|
||||||
|
return tuple(sys_depends)
|
||||||
|
|
||||||
|
|
||||||
|
def apply(self):
|
||||||
|
if self.pkg_goal == PkgGoal.PKG_INSTALL:
|
||||||
|
ops.install_packages(self._final_state)
|
||||||
|
|
||||||
|
|
||||||
|
def problems(self) -> tuple:
|
||||||
|
"""Provide a report of conflicts and packages which cannot be resolved (dependencies not installable)."""
|
||||||
|
return ()
|
||||||
|
|
||||||
|
|
||||||
|
def commit(self):
|
||||||
|
"""Commit the transaction to record for what happened."""
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@property
|
||||||
|
def finalised(self):
|
||||||
|
return self._final_state
|
||||||
Loading…
Reference in New Issue
Block a user