Skip to content

Commit

Permalink
updater: unify cli options with cli updater
Browse files Browse the repository at this point in the history
(cherry picked from commit 819fdd9)
  • Loading branch information
piotrbartman authored and marmarek committed Jul 5, 2024
1 parent 81f8a55 commit 9d476a9
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 18 deletions.
3 changes: 2 additions & 1 deletion qui/updater/intro_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ def select_rows_ignoring_conditions(self, cliargs, dom0):

args = [a for a in dir(cliargs) if not a.startswith("_")]
for arg in args:
if arg in ("dom0", "no_restart", "restart", "max_concurrency",
if arg in ("dom0", "no_restart", "restart", "apply_to_sys",
"apply_to_all", "no_apply", "max_concurrency",
"log", "non_interactive"):
continue
value = getattr(cliargs, arg)
Expand Down
33 changes: 21 additions & 12 deletions qui/updater/updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from qubesadmin import Qubes

# using locale.gettext is necessary for Gtk.Builder translation support to work
# in most cases gettext is better, but it cannot handle Gtk.Builder/glade files
# in most cases, gettext is better, but it cannot handle Gtk.Builder/glade files
import locale
from locale import gettext as l

Expand Down Expand Up @@ -126,14 +126,20 @@ def perform_setup(self, *_args, **_kwargs):
settings_image = Gtk.Image.new_from_pixbuf(settings_pixbuf)
self.button_settings.set_image(settings_image)

overriden_restart = None
if self.cliargs.restart:
overriden_restart = True
overridden_apply_to_sys = None
overridden_apply_to_other = None
if self.cliargs.apply_to_all:
overridden_apply_to_sys = True
overridden_apply_to_other = True
elif self.cliargs.restart:
overridden_apply_to_sys = True
elif self.cliargs.no_restart:
overriden_restart = False
overridden_apply_to_sys = False
overridden_apply_to_other = False

overrides = OverridenSettings(
restart=overriden_restart,
apply_to_sys=overridden_apply_to_sys,
apply_to_other=overridden_apply_to_other,
max_concurrency=self.cliargs.max_concurrency,
update_if_stale=self.cliargs.update_if_stale,
)
Expand Down Expand Up @@ -186,7 +192,6 @@ def cell_data_func(_column, cell, model, it, data):
width = self.intro_page.vm_list.get_preferred_width().natural_width
self.main_window.resize(width + 50, int(width * 1.2))
self.main_window.set_position(Gtk.WindowPosition.CENTER_ALWAYS)
# return 0

def open_settings_window(self, _emitter):
self.settings.show()
Expand Down Expand Up @@ -283,12 +288,16 @@ def parse_args(args):
'(default: number of cpus)',
type=int)
restart_gr = parser.add_mutually_exclusive_group()
restart_gr.add_argument('--restart', action='store_true',
help='Restart AppVMs whose template '
'has been updated.')
restart_gr.add_argument('--no-restart', action='store_true',
help='Do not restart AppVMs whose template '
restart_gr.add_argument('--restart', '--apply-to-sys', '-r',
action='store_true',
help='Restart Service VMs whose template '
'has been updated.')
restart_gr.add_argument('--apply-to-all', '-R',
action='store_true',
help='Restart Service VMs and shutdown AppVMs '
'whose template has been updated.')
restart_gr.add_argument('--no-apply', action='store_true',
help='Do not restart/shutdown any AppVMs.')

group = parser.add_mutually_exclusive_group()
group.add_argument('--targets', action='store',
Expand Down
11 changes: 6 additions & 5 deletions qui/updater/updater_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@

@dataclasses.dataclass(frozen=True)
class OverridenSettings:
restart: Optional[bool] = None
apply_to_sys: Optional[bool] = None
apply_to_other: Optional[bool] = None
max_concurrency: Optional[int] = None
update_if_stale: Optional[int] = None

Expand Down Expand Up @@ -148,8 +149,8 @@ def update_if_stale(self) -> int:
@property
def restart_service_vms(self) -> bool:
"""Return the current (set by this window or manually) option value."""
if self.overrides.restart is not None:
return self.overrides.restart
if self.overrides.apply_to_sys is not None:
return self.overrides.apply_to_sys

result = get_boolean_feature(
self.vm, "qubes-vm-update-restart-servicevms",
Expand All @@ -168,8 +169,8 @@ def restart_service_vms(self) -> bool:
@property
def restart_other_vms(self) -> bool:
"""Return the current (set by this window or manually) option value."""
if self.overrides.restart is not None:
return self.overrides.restart
if self.overrides.apply_to_other is not None:
return self.overrides.apply_to_other
return get_boolean_feature(
self.vm, "qubes-vm-update-restart-other",
Settings.DEFAULT_RESTART_OTHER_VMS)
Expand Down

0 comments on commit 9d476a9

Please sign in to comment.