Skip to content
122 changes: 60 additions & 62 deletions qui/updater/intro_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,46 +101,24 @@ def populate_vm_list(self, qapp, settings):
self.log.debug("Populate update list")
self.list_store = ListWrapper(UpdateRowWrapper, self.vm_list.get_model())

for vm in qapp.domains:
if vm.klass == "AdminVM":
try:
if settings.hide_skipped and bool(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I might be confused here, but I think the check for skip-update is needed?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It's in lines 123–126 (dom0 is now treated like the other VMs).

vm.features.get("skip-update", False)
):
continue
state = bool(vm.features.get("updates-available", False))
except exc.QubesDaemonCommunicationError:
state = False
self.list_store.append_vm(vm, state)

to_update = set()
if settings.hide_updated:
cmd = [
"qubes-vm-update",
"--quiet",
"--dry-run",
"--update-if-stale",
str(settings.update_if_stale),
]
to_update = self._get_stale_qubes(cmd)

for vm in qapp.domains:
try:
if settings.hide_skipped and bool(
vm.features.get("skip-update", False)
):
continue
if settings.hide_updated and not vm.name in to_update:
# TODO: Make re-filtering possible without App restart
continue
except exc.QubesDaemonCommunicationError:
continue
if getattr(vm, "updateable", False) and vm.klass != "AdminVM":
self.list_store.append_vm(vm)

self.refresh_update_list(settings.update_if_stale)
for vm in sorted(qapp.domains, key=lambda vm: vm.klass):
if getattr(vm, "updateable", False):
self.list_store.append_vm(vm, state=False)

self.refresh_update_list(
settings.update_if_stale,
settings.hide_updated,
settings.hide_skipped,
settings.hide_prohibited,
)

def refresh_update_list(self, update_if_stale):
def refresh_update_list(
self,
update_if_stale,
hide_updated=False,
hide_skipped=False,
hide_prohibited=False,
):
"""
Refreshes "Updates Available" column if settings changed.
"""
Expand All @@ -158,13 +136,29 @@ def refresh_update_list(self, update_if_stale):

to_update = self._get_stale_qubes(cmd)

for row in self.list_store:
if row.vm.name == "dom0":
continue
row.updates_available = bool(row.vm.name in to_update)
row.selected = bool(row.vm.name in to_update) and not row.vm.features.get(
"prohibit-start", False
)
rows = self.list_store.get_all()
self.list_store.clear()
for row in rows:

# Determine visibility
visible = True
if hide_updated and not row.vm.name in to_update:
visible = False
else:
try:
if hide_skipped and bool(row.vm.features.get("skip-update", False)):
visible = False
if hide_prohibited and bool(
row.vm.features.get("prohibit-start", False)
):
visible = False
except exc.QubesDaemonCommunicationError:
visible = True

state = bool(row.vm.name in to_update) if visible else None
appended = self.list_store.append_vm(row.vm, state=state)
if state is not None:
appended.selected = bool(row.vm.name in to_update)

def get_vms_to_update(self) -> ListWrapper:
"""Returns list of vms selected to be updated"""
Expand Down Expand Up @@ -215,7 +209,7 @@ def select_rows(self):
for row in self.list_store:
row.selected = row.updates_available in self.head_checkbox.allowed

def select_rows_ignoring_conditions(self, cliargs, dom0):
def select_rows_ignoring_conditions(self, cliargs):
cmd = ["qubes-vm-update", "--dry-run", "--quiet"]

args = [a for a in dir(cliargs) if not a.startswith("_")]
Expand All @@ -236,13 +230,12 @@ def select_rows_ignoring_conditions(self, cliargs, dom0):
if value:
if arg in ("skip", "targets"):
vms = set(value.split(","))
vms_without_dom0 = vms.difference({"dom0"})
if not vms_without_dom0:
continue
value = ",".join(sorted(vms_without_dom0))
value = ",".join(sorted(vms))
cmd.append(f"--{arg.replace('_', '-')}")
if not isinstance(value, bool):
cmd.append(str(value))
if cliargs.dom0:
cmd.extend(["--targets", "dom0"])

to_update = set()
non_default_select = [
Expand All @@ -252,8 +245,6 @@ def select_rows_ignoring_conditions(self, cliargs, dom0):
if non_default or cliargs.non_interactive:
to_update = self._get_stale_qubes(cmd)

to_update = self._handle_cli_dom0(dom0, to_update, cliargs)

for row in self.list_store:
row.selected = row.name in to_update

Expand All @@ -264,13 +255,20 @@ def _get_stale_qubes(self, cmd):
self.log.debug("Command returns: %s", output.decode())

output_lines = output.decode().split("\n")
if ":" not in output_lines[0]:
return set()

return {
vm_name.strip()
for vm_name in output_lines[0].split(":", maxsplit=1)[1].split(",")
}
result = set()
if "dom0" in output_lines[0]:
result.add("dom0")

second_line = output_lines[1] if len(output_lines) > 1 else ""
if ":" not in second_line:
return result

return result.union(
{
vm_name.strip()
for vm_name in second_line.split(":", maxsplit=1)[1].split(",")
}
)
except subprocess.CalledProcessError as err:
if err.returncode != 100:
raise err
Expand Down Expand Up @@ -513,8 +511,8 @@ class UpdatesAvailable(Enum):
@staticmethod
def from_features(
updates_available: Optional[bool],
supported: Optional[str] = None,
prohibited: Optional[str] = None,
supported: Optional[bool] = None,
prohibited: Optional[bool] = None,
) -> "UpdatesAvailable":
if prohibited:
return UpdatesAvailable.PROHIBITED
Expand Down
Loading