Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add module that waits for transaction completion before updating #55

Merged
merged 1 commit into from
Sep 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/ublue_update/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import tomllib
import argparse


from ublue_update.update_checks.system import system_update_check
from ublue_update.update_checks.wait import transaction_wait


def notify(title: str, body: str, actions: list = [], expire_time: int = 0):
Expand Down Expand Up @@ -153,6 +155,9 @@ def run_updates():

log.info("Running system update")

"""Wait on any existing transactions to complete before updating"""
transaction_wait()

for root, dirs, files in os.walk(root_dir):
for file in files:
full_path = root_dir + str(file)
Expand Down Expand Up @@ -214,9 +219,19 @@ def main():
action="store_true",
help="check for updates and exit",
)
parser.add_argument(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it default to false?

"-w",
"--wait",
action="store_true",
help="wait for transactions to complete and exit",
)
args = parser.parse_args()
hardware_checks_failed = False

if args.wait:
transaction_wait()
os._exit(0)

if not args.force and not args.updatecheck:
hardware_checks_failed, failures = check_hardware_inhibitors()
if hardware_checks_failed:
Expand Down
16 changes: 16 additions & 0 deletions src/ublue_update/update_checks/wait.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from json import loads
from subprocess import PIPE, run
from time import sleep


def transaction():
"""Pull deployment status via rpm-ostree"""
rpm_ostree_status = ["rpm-ostree", "status", "--json"]
status = run(rpm_ostree_status, stdout=PIPE)
"""Parse transaction state"""
return loads(status.stdout)["transaction"]


def transaction_wait():
while transaction() is not None:
sleep(1)