From 92a6a85a4b292e0fb4a6b1a60fef6b02c4ce59c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Sat, 11 Jan 2014 22:57:34 +0100 Subject: [PATCH] backups: kill self.backup_location variable This is copy of dir_line_edit content and its easy to desynchronize its value, so just use the later directly. --- qubesmanager/backup.py | 13 ++++++------- qubesmanager/backup_utils.py | 14 ++++++-------- qubesmanager/restore.py | 23 ++++++++++++----------- restoredlg.ui | 2 +- 4 files changed, 25 insertions(+), 27 deletions(-) diff --git a/qubesmanager/backup.py b/qubesmanager/backup.py index 934f4ef..f21fa13 100644 --- a/qubesmanager/backup.py +++ b/qubesmanager/backup.py @@ -66,7 +66,6 @@ class BackupVMsWindow(Ui_Backup, QWizard): self.shutdown_vm_func = shutdown_vm_func self.dev_mount_path = None - self.backup_location = None self.func_output = [] self.selected_vms = [] @@ -254,13 +253,14 @@ class BackupVMsWindow(Ui_Backup, QWizard): self.selected_vms.append(self.select_vms_widget.selected_list.item(i).vm) elif self.currentPage() is self.select_dir_page: - if not self.backup_location: + backup_location = str(self.dir_line_edit.text()) + if not backup_location: QMessageBox.information(None, "Wait!", "Enter backup target location first.") return False if self.appvm_combobox.currentIndex() == 0 and \ - not os.path.isdir(self.backup_location): + not os.path.isdir(backup_location): QMessageBox.information(None, "Wait!", - "Selected directory do not exists or not a directory (%s)." % self.backup_location) + "Selected directory do not exists or not a directory (%s)." % backup_location) return False if not len(self.passphrase_line_edit.text()): QMessageBox.information(None, "Wait!", "Enter passphrase for backup encryption/verification first.") @@ -281,7 +281,7 @@ class BackupVMsWindow(Ui_Backup, QWizard): msg = [] try: - backup.backup_do(str(self.backup_location), + backup.backup_do(str(self.dir_line_edit.text()), self.files_to_backup, str(self.passphrase_line_edit.text()), progress_callback=self.update_progress_bar, @@ -374,10 +374,9 @@ class BackupVMsWindow(Ui_Backup, QWizard): return False if self.passphrase_line_edit.text() != self.passphrase_line_edit_verify.text(): return False - return self.backup_location != None + return len(self.dir_line_edit.text()) > 0 def backup_location_changed(self, new_dir = None): - self.backup_location = str(self.dir_line_edit.text()) self.select_dir_page.emit(SIGNAL("completeChanged()")) diff --git a/qubesmanager/backup_utils.py b/qubesmanager/backup_utils.py index d783dbf..1cd017b 100644 --- a/qubesmanager/backup_utils.py +++ b/qubesmanager/backup_utils.py @@ -121,7 +121,6 @@ def dev_combobox_activated(dialog, idx): #there was a change dialog.dir_line_edit.setText("") - dialog.backup_location = None if dialog.dev_mount_path != None: dialog.dev_mount_path = umount_device(dialog.dev_mount_path) @@ -161,13 +160,12 @@ def dev_combobox_activated(dialog, idx): if dialog.dev_mount_path != None: # Initialize path with root of mounted device dialog.dir_line_edit.setText(dialog.dev_mount_path) - dialog.backup_location = dialog.dev_mount_path dialog.select_dir_page.emit(SIGNAL("completeChanged()")) def select_path_button_clicked(dialog, select_file = False): - dialog.backup_location = str(dialog.dir_line_edit.text()) + backup_location = str(dialog.dir_line_edit.text()) file_dialog = QFileDialog() file_dialog.setReadOnly(True) @@ -183,17 +181,17 @@ def select_path_button_clicked(dialog, select_file = False): elif dialog.dev_mount_path != None: new_path = file_dialog_function(dialog, "Select backup location.", dialog.dev_mount_path) else: - new_path = file_dialog_function(dialog, "Select backup location.", dialog.backup_location) + new_path = file_dialog_function(dialog, "Select backup location.", backup_location) if new_path != None: new_path = str(new_path) if os.path.basename(new_path) == 'qubes.xml': - dialog.backup_location = os.path.dirname(new_path) + backup_location = os.path.dirname(new_path) else: - dialog.backup_location = new_path - dialog.dir_line_edit.setText(dialog.backup_location) + backup_location = new_path + dialog.dir_line_edit.setText(backup_location) - if (new_path or new_appvm) and len(dialog.backup_location) > 0: + if (new_path or new_appvm) and len(backup_location) > 0: dialog.select_dir_page.emit(SIGNAL("completeChanged()")) def simulate_long_lasting_proces(period, progress_callback): diff --git a/qubesmanager/restore.py b/qubesmanager/restore.py index cfb7606..8e5db99 100644 --- a/qubesmanager/restore.py +++ b/qubesmanager/restore.py @@ -63,7 +63,6 @@ class RestoreVMsWindow(Ui_Restore, QWizard): self.blk_manager = blk_manager self.dev_mount_path = None - self.backup_location = None self.restore_options = None self.backup_vms_list = None self.func_output = [] @@ -133,12 +132,12 @@ class RestoreVMsWindow(Ui_Restore, QWizard): try: self.restore_tmpdir, qubes_xml = backup.backup_restore_header( - str(self.backup_location), + str(self.dir_line_edit.text()), str(self.passphrase_line_edit.text()), encrypted=self.encryption_checkbox.isChecked(), appvm=self.target_appvm) self.vms_to_restore = backup.backup_restore_prepare( - str(self.backup_location), + str(self.dir_line_edit.text()), os.path.join(self.restore_tmpdir, qubes_xml), str(self.passphrase_line_edit.text()), options=self.restore_options, @@ -186,7 +185,7 @@ class RestoreVMsWindow(Ui_Restore, QWizard): self.qvm_collection.lock_db_for_writing() try: backup.backup_restore_do( - str(self.backup_location), + str(self.dir_line_edit.text()), self.restore_tmpdir, str(self.passphrase_line_edit.text()), self.vms_to_restore, @@ -274,18 +273,20 @@ class RestoreVMsWindow(Ui_Restore, QWizard): self.done(0) def has_selected_dir(self): - return self.backup_location != None + backup_location = str(self.dir_line_edit.text()) + if self.appvm_combobox.currentText() == "dom0": + if os.path.isfile(backup_location) or \ + os.path.isfile(os.path.join(backup_location, 'qubes.xml')): + return True + elif len(backup_location) > 0: + return True + + return False def has_selected_vms(self): return self.select_vms_widget.selected_list.count() > 0 def backup_location_changed(self, new_dir = None): - if self.appvm_combobox.currentText() != "dom0" or \ - os.path.isfile(str(self.dir_line_edit.text())) or \ - os.path.isfile(os.path.join(str(self.dir_line_edit.text()), 'qubes.xml')): - self.backup_location = str(self.dir_line_edit.text()) - else: - self.backup_location = None self.select_dir_page.emit(SIGNAL("completeChanged()")) diff --git a/restoredlg.ui b/restoredlg.ui index 5a0fc9f..2db5bb9 100644 --- a/restoredlg.ui +++ b/restoredlg.ui @@ -143,7 +143,7 @@ - <html><head/><body><p>Backup directory:<br><span style=" font-size:8pt;">(for old backup format select qubes.xml file)</span></p></body></html> + <html><head/><body><p>Backup file:<br><span style=" font-size:8pt;">(for old backup format select qubes.xml file)</span></p></body></html> Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop