Skip to content

Commit

Permalink
try to remove dnf5 first
Browse files Browse the repository at this point in the history
  • Loading branch information
praiskup committed Jan 24, 2024
1 parent 43e02e6 commit 32781aa
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
27 changes: 26 additions & 1 deletion behave/features/steps/other.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,24 @@
# pylint: disable=missing-function-docstring,function-redefined


def _first_int(string):
for line in string.split("\n")[:5]: # first 5 lines
first_word = line.split()[0]
if first_word.isdigit():
return first_word
raise Exception("unexpected dnf history output")


def add_cleanup_last_transaction(context):
# TODO: DNF5 support https://github.com/rpm-software-management/dnf5/issues/140
dnf = ["sudo", "/usr/bin/dnf-3", "-y", "history"]
_, out, _ = run(dnf + ["list"])
transaction_id = _first_int(out)
def _revert_transaction(_context):
cmd = dnf + ["undo", transaction_id]
assert_that(run(cmd)[0], equal_to(0))
context.add_cleanup(_revert_transaction, context)

@given(u'an unique mock namespace')
def step_impl(context):
print("using uniqueext {}".format(context.uniqueext))
Expand All @@ -39,7 +57,14 @@ def step_impl(context, package, state):
is_installed = bool(not is_installed)

if "not" in state:
assert_that(is_installed, equal_to(False))
if not is_installed:
return # nothing to do

# Remove the package and schedule it'đ ...
cmd = ["sudo", "dnf", "-y", "remove", package]
assert_that(run(cmd)[0], equal_to(0))
# schedule removal
add_cleanup_last_transaction(context)
return

if is_installed:
Expand Down
5 changes: 5 additions & 0 deletions behave/scripts/dnf-last-transaction
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#! /bin/bash

dnf-3 history list 2>/dev/null | while read first_word _unused; do

Check notice

Code scanning / shellcheck

read without -r will mangle backslashes. Note

read without -r will mangle backslashes.
[[ "$first_word" =~ ^[0-9]+$ ]] && echo "$first_word" && exit 0
done

0 comments on commit 32781aa

Please sign in to comment.