Skip to content

Commit

Permalink
fully featured version, no progress report
Browse files Browse the repository at this point in the history
  • Loading branch information
Enchufa2 committed Aug 8, 2024
1 parent eebc98b commit 9e78a8f
Showing 1 changed file with 52 additions and 20 deletions.
72 changes: 52 additions & 20 deletions inst/service/backend/dnf5.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,20 @@
AVAILABLE = libdnf5.repo.Repo.Type_AVAILABLE
SYSTEM = libdnf5.repo.Repo.Type_SYSTEM

def _setup(repo_type):
def _setup():
base = libdnf5.base.Base()
# add callbacks for progress report??
base.load_config()
base.setup()
repo_sack = base.get_repo_sack()
repo_sack.create_repos_from_system_configuration()
repo_sack.load_repos(repo_type)
return base, repo_sack

def discover():
base, repo_sack = _setup(AVAILABLE)
base, repo_sack = _setup()
repo_sack.load_repos(AVAILABLE)

q = libdnf5.rpm.PackageQuery(base)
q.filter_available()
q.filter_name("R-*[!-debuginfo][!-devel]", GLOB)
prefixes = {"-".join(x.get_name().split("-")[:-1]) + "-" for x in q}

Expand All @@ -30,10 +29,10 @@ def discover():
}

def available(prefixes, exclusions):
base, repo_sack = _setup(AVAILABLE)
base, repo_sack = _setup()
repo_sack.load_repos(AVAILABLE)

q = libdnf5.rpm.PackageQuery(base)
q.filter_available()
q.filter_latest_evr()
q.filter_name([_ + "*" for _ in prefixes], GLOB)
pkgs = []
Expand All @@ -50,27 +49,60 @@ def available(prefixes, exclusions):

return pkgs

def install(prefixes, pkgs, exclusions): # does not work
base, repo_sack = _setup(AVAILABLE)

goal = libdnf5.base.Goal(base)
ifun = goal.add_install # does not fail if package doesn't exist
ufun = goal.add_upgrade
notavail = mark(ifun, prefixes, pkgs, exclusions, post=ufun)
def _add(base, fn_installed, fn_available = None):
class Query:
def __init__(self, pkg):
self.q = libdnf5.rpm.PackageQuery(base)
self.q.filter_name(pkg)
def is_installed(self):
self.q.filter_installed()
return self.q.size() > 0
def is_available(self):
self.q.filter_available()
return self.q.size() > 0

def wrapper(pkg):
if Query(pkg).is_installed():
return fn_installed(pkg)
if Query(pkg).is_available() and fn_available is not None:
return fn_available(pkg)
raise Exception(f"Package {pkg} not found")
return wrapper

def _run(goal):
INSTALL = libdnf5.transaction.TransactionItemAction_INSTALL
UPGRADE = libdnf5.transaction.TransactionItemAction_UPGRADE
REMOVE = libdnf5.transaction.TransactionItemAction_REMOVE
iats = libdnf5.transaction.transaction_item_action_to_string

transaction = goal.resolve()
actions = [_.get_action() for _ in transaction.get_transaction_packages()]
actions = {iats(_) : actions.count(_) for _ in [INSTALL, UPGRADE, REMOVE]}
transaction.set_description(f"bspm transaction: {actions}")

transaction.download()
transaction.run() # does not raise, but returns an error code
ret = transaction.run()
if ret:
raise Exception(transaction.transaction_result_to_string(ret))

def install(prefixes, pkgs, exclusions):
base, repo_sack = _setup()
repo_sack.load_repos()

goal = libdnf5.base.Goal(base)
fn = _add(base, goal.add_upgrade, goal.add_install)
notavail = mark(fn, prefixes, pkgs, exclusions)
_run(goal)

return notavail

def remove(prefixes, pkgs, exclusions): # does not work
base, repo_sack = _setup(SYSTEM)
def remove(prefixes, pkgs, exclusions):
base, repo_sack = _setup()
repo_sack.load_repos(SYSTEM)

goal = libdnf5.base.Goal(base)
notavail = mark(goal.add_remove, prefixes, pkgs, exclusions)

transaction = goal.resolve()
transaction.run()
fn = _add(base, goal.add_remove)
notavail = mark(fn, prefixes, pkgs, exclusions)
_run(goal)

return notavail

0 comments on commit 9e78a8f

Please sign in to comment.