Skip to content

Commit

Permalink
Improve Qubes OS Update reporting for dom0
Browse files Browse the repository at this point in the history
  • Loading branch information
alimirjamali committed Jul 18, 2024
1 parent 66e5cfb commit 84366b4
Showing 1 changed file with 33 additions and 32 deletions.
65 changes: 33 additions & 32 deletions qui/updater/progress_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,66 +148,67 @@ def update_admin_vm(self, admins):
return
self.log.debug("Start adminVM updating")

info = f"Updating {admin.name}...\n" \
f"{admin.name} does not support in-progress update " \
"information.\n"
info = f"Checking for available updates for {admin.name}...\n"
GLib.idle_add(
admin.append_text_view,
l(info).format(admin.name))
GLib.idle_add(admin.set_status, UpdateStatus.ProgressUnknown)

self.update_details.update_buffer()

try:
with Ticker(admin):
curr_pkg = self._get_packages_admin()

# pylint: disable=consider-using-with
check_updates = subprocess.Popen(
['sudo', 'qubes-dom0-update', '--refresh', '--check-only'],
stderr=subprocess.PIPE, stdout=subprocess.PIPE)
_stdout, stderr = check_updates.communicate()
if check_updates.returncode != 100:
GLib.idle_add(admin.append_text_view, stderr.decode())
if check_updates.returncode != 0:
GLib.idle_add(admin.set_status, UpdateStatus.Error)
else:
GLib.idle_add(
admin.set_status, UpdateStatus.NoUpdatesFound)
self.update_details.update_buffer()
return

proc = subprocess.Popen(
['sudo', 'qubes-dom0-update', '-y'],
stderr=subprocess.PIPE, stdout=subprocess.PIPE)
def qubes_dom0_update(*args):
with subprocess.Popen(['sudo', 'qubes-dom0-update'] + list(args),
stderr=subprocess.PIPE, stdout=subprocess.PIPE) as subproc:

read_err_thread = threading.Thread(
target=self.dump_to_textview,
args=(proc.stderr, admin)
args=(subproc.stderr, admin)
)
read_out_thread = threading.Thread(
target=self.dump_to_textview,
args=(proc.stdout, admin)
args=(subproc.stdout, admin)
)
read_err_thread.start()
read_out_thread.start()

while proc.poll() is None \
while subproc.poll() is None \
or read_out_thread.is_alive() \
or read_err_thread.is_alive():
time.sleep(1)
if self.exit_triggered and proc.poll() is None:
proc.send_signal(signal.SIGINT)
proc.wait()
if self.exit_triggered and subproc.poll() is None:
subproc.send_signal(signal.SIGINT)
subproc.wait()

Check warning on line 180 in qui/updater/progress_page.py

View check run for this annotation

Codecov / codecov/patch

qui/updater/progress_page.py#L179-L180

Added lines #L179 - L180 were not covered by tests
read_err_thread.join()
read_out_thread.join()

return subproc.returncode

try:
with Ticker(admin):
curr_pkg = self._get_packages_admin()

returncode = qubes_dom0_update('--refresh', '--check-only')
if returncode != 100:
if returncode != 0:
GLib.idle_add(admin.set_status, UpdateStatus.Error)
else:
GLib.idle_add(

Check warning on line 195 in qui/updater/progress_page.py

View check run for this annotation

Codecov / codecov/patch

qui/updater/progress_page.py#L195

Added line #L195 was not covered by tests
admin.set_status, UpdateStatus.NoUpdatesFound)
self.update_details.update_buffer()
return

returncode = qubes_dom0_update('-y')
if returncode != 0:
GLib.idle_add(admin.set_status, UpdateStatus.Error)
self.update_details.update_buffer()
return

Check warning on line 204 in qui/updater/progress_page.py

View check run for this annotation

Codecov / codecov/patch

qui/updater/progress_page.py#L200-L204

Added lines #L200 - L204 were not covered by tests

new_pkg = self._get_packages_admin()
changes = self._compare_packages(curr_pkg, new_pkg)
changes_str = self._print_changes(changes)
GLib.idle_add(admin.append_text_view, changes_str)

GLib.idle_add(admin.set_status, UpdateStatus.Success)

except subprocess.CalledProcessError as ex:
GLib.idle_add(
admin.append_text_view,
Expand Down

0 comments on commit 84366b4

Please sign in to comment.