Skip to content

Commit

Permalink
feat: Add module that waits for transaction completion before updating (
Browse files Browse the repository at this point in the history
  • Loading branch information
akdev1l authored Sep 2, 2023
2 parents 6bd7568 + 0abd5dc commit d8d038b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
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(
"-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)

0 comments on commit d8d038b

Please sign in to comment.