Browse Source

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.
Marek Marczykowski-Górecki 10 years ago
parent
commit
92a6a85a4b
4 changed files with 25 additions and 27 deletions
  1. 6 7
      qubesmanager/backup.py
  2. 6 8
      qubesmanager/backup_utils.py
  3. 12 11
      qubesmanager/restore.py
  4. 1 1
      restoredlg.ui

+ 6 - 7
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()"))
 
 

+ 6 - 8
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):

+ 12 - 11
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()"))
 
 

+ 1 - 1
restoredlg.ui

@@ -143,7 +143,7 @@
           </size>
          </property>
          <property name="text">
-          <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Backup directory:&lt;br&gt;&lt;span style=&quot; font-size:8pt;&quot;&gt;(for old backup format select qubes.xml file)&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+          <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Backup file:&lt;br&gt;&lt;span style=&quot; font-size:8pt;&quot;&gt;(for old backup format select qubes.xml file)&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
          </property>
          <property name="alignment">
           <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>