More consistent 'include_in_backups' behavior

Instead of always selecting for backup all the VMs that were selected
during last saved backup, now the GUI tool will disregard last selected
VMs and instead use VM attribute 'include_in_backups'

fixes QubesOS/qubes-issues#4713
This commit is contained in:
Marta Marczykowska-Górecka 2019-01-16 20:43:08 +01:00
parent f047a56906
commit 60f62ff7cf
No known key found for this signature in database
GPG Key ID: 9A752C30B26FD04B

View File

@ -130,7 +130,10 @@ class BackupVMsWindow(ui_backupdlg.Ui_Backup, multiselectwidget.QtGui.QWizard):
allow_none=False allow_none=False
) )
selected = self.load_settings() self.unrecognized_config_label.setVisible(False)
self.load_settings()
selected = self.vms_to_include()
self.__fill_vms_list__(selected) self.__fill_vms_list__(selected)
# Connect backup events for progress_bar # Connect backup events for progress_bar
@ -142,14 +145,28 @@ class BackupVMsWindow(ui_backupdlg.Ui_Backup, multiselectwidget.QtGui.QWizard):
def on_backup_progress(self, __submitter, _event, **kwargs): def on_backup_progress(self, __submitter, _event, **kwargs):
self.progress_bar.setValue(int(float(kwargs['progress']))) self.progress_bar.setValue(int(float(kwargs['progress'])))
def vms_to_include(self):
"""
Helper function that returns list of VMs with 'include_in_backups'
attribute set to True.
:return: list of VM names
"""
result = []
for domain in self.qubes_app.domains:
if getattr(domain, 'include_in_backups', None):
result.append(domain.name)
return result
def load_settings(self): def load_settings(self):
""" """
Helper function that tries to load existing backup profile Helper function that tries to load existing backup profile
(default path: /etc/qubes/backup/qubes-manager-backup.conf ) (default path: /etc/qubes/backup/qubes-manager-backup.conf )
and then apply its contents to the Backup window. and then apply its contents to the Backup window.
:return: list of vms to include in backup, if it exists in the profile, Ignores listed VMs, to prioritize include_in_backups feature.
or None if it does not :return: None
""" """
try: try:
profile_data = backup_utils.load_backup_profile() profile_data = backup_utils.load_backup_profile()
@ -168,6 +185,8 @@ class BackupVMsWindow(ui_backupdlg.Ui_Backup, multiselectwidget.QtGui.QWizard):
dest_vm_idx = self.appvm_combobox.findText(dest_vm_name) dest_vm_idx = self.appvm_combobox.findText(dest_vm_name)
if dest_vm_idx > -1: if dest_vm_idx > -1:
self.appvm_combobox.setCurrentIndex(dest_vm_idx) self.appvm_combobox.setCurrentIndex(dest_vm_idx)
else:
self.unrecognized_config_label.setVisible(True)
if 'destination_path' in profile_data: if 'destination_path' in profile_data:
dest_path = profile_data['destination_path'] dest_path = profile_data['destination_path']
@ -181,11 +200,6 @@ class BackupVMsWindow(ui_backupdlg.Ui_Backup, multiselectwidget.QtGui.QWizard):
if 'compression' in profile_data: if 'compression' in profile_data:
self.compress_checkbox.setChecked(profile_data['compression']) self.compress_checkbox.setChecked(profile_data['compression'])
if 'include' in profile_data:
return profile_data['include']
return None
def save_settings(self, use_temp): def save_settings(self, use_temp):
""" """
Helper function that saves backup profile to either Helper function that saves backup profile to either
@ -231,9 +245,6 @@ class BackupVMsWindow(ui_backupdlg.Ui_Backup, multiselectwidget.QtGui.QWizard):
self.select_vms_widget.available_list.sortItems() self.select_vms_widget.available_list.sortItems()
self.select_vms_widget.selected_list.sortItems() self.select_vms_widget.selected_list.sortItems()
self.unrecognized_config_label.setVisible(
selected is not None and
len(selected) != len(self.select_vms_widget.selected_list))
self.total_size_label.setText( self.total_size_label.setText(
admin_utils.size_to_human(self.total_size)) admin_utils.size_to_human(self.total_size))