Skip to content

Commit d8d038b

Browse files
authored
feat: Add module that waits for transaction completion before updating (#55)
2 parents 6bd7568 + 0abd5dc commit d8d038b

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/ublue_update/cli.py

+15
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
import tomllib
66
import argparse
77

8+
89
from ublue_update.update_checks.system import system_update_check
10+
from ublue_update.update_checks.wait import transaction_wait
911

1012

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

154156
log.info("Running system update")
155157

158+
"""Wait on any existing transactions to complete before updating"""
159+
transaction_wait()
160+
156161
for root, dirs, files in os.walk(root_dir):
157162
for file in files:
158163
full_path = root_dir + str(file)
@@ -214,9 +219,19 @@ def main():
214219
action="store_true",
215220
help="check for updates and exit",
216221
)
222+
parser.add_argument(
223+
"-w",
224+
"--wait",
225+
action="store_true",
226+
help="wait for transactions to complete and exit",
227+
)
217228
args = parser.parse_args()
218229
hardware_checks_failed = False
219230

231+
if args.wait:
232+
transaction_wait()
233+
os._exit(0)
234+
220235
if not args.force and not args.updatecheck:
221236
hardware_checks_failed, failures = check_hardware_inhibitors()
222237
if hardware_checks_failed:
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from json import loads
2+
from subprocess import PIPE, run
3+
from time import sleep
4+
5+
6+
def transaction():
7+
"""Pull deployment status via rpm-ostree"""
8+
rpm_ostree_status = ["rpm-ostree", "status", "--json"]
9+
status = run(rpm_ostree_status, stdout=PIPE)
10+
"""Parse transaction state"""
11+
return loads(status.stdout)["transaction"]
12+
13+
14+
def transaction_wait():
15+
while transaction() is not None:
16+
sleep(1)

0 commit comments

Comments
 (0)