From 9d73ceb99d4d8f9370409a9faf21211d9dff31f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marta=20Marczykowska-G=C3=B3recka?= Date: Sun, 10 Dec 2017 22:11:07 +0100 Subject: [PATCH] Fixed imports Fixed import * and unused imports. --- qubesmanager/backup.py | 73 +++++++++++++++-------------- qubesmanager/backup_utils.py | 10 ++-- qubesmanager/restore.py | 91 +++++++++++++++++++----------------- 3 files changed, 90 insertions(+), 84 deletions(-) diff --git a/qubesmanager/backup.py b/qubesmanager/backup.py index b89b1cb..f8ccd0b 100644 --- a/qubesmanager/backup.py +++ b/qubesmanager/backup.py @@ -30,21 +30,23 @@ from qubesadmin import Qubes, events, exc from qubesadmin import utils as admin_utils from qubes.storage.file import get_disk_usage -from PyQt4 import QtCore, QtGui # pylint: disable=import-error +from PyQt4 import QtCore # pylint: disable=import-error +from PyQt4 import QtGui # pylint: disable=import-error +from . import ui_backupdlg +from . import multiselectwidget -from .ui_backupdlg import * -from .multiselectwidget import * - -from .backup_utils import * +from . import backup_utils from . import utils import grp import pwd import sys import os -from .thread_monitor import * +from . import thread_monitor +import threading import time -class BackupVMsWindow(Ui_Backup, QWizard): + +class BackupVMsWindow(ui_backupdlg.Ui_Backup, multiselectwidget.QtGui.QWizard): __pyqtSignals__ = ("backup_progress(int)",) @@ -67,21 +69,21 @@ class BackupVMsWindow(Ui_Backup, QWizard): self.progress_status.text = self.tr("Backup in progress...") self.dir_line_edit.setReadOnly(False) - self.select_vms_widget = MultiSelectWidget(self) + self.select_vms_widget = multiselectwidget.MultiSelectWidget(self) self.verticalLayout.insertWidget(1, self.select_vms_widget) - self.connect(self, SIGNAL("currentIdChanged(int)"), + self.connect(self, QtCore.SIGNAL("currentIdChanged(int)"), self.current_page_changed) self.connect(self.select_vms_widget, - SIGNAL("items_removed(PyQt_PyObject)"), + QtCore.SIGNAL("items_removed(PyQt_PyObject)"), self.vms_removed) self.connect(self.select_vms_widget, - SIGNAL("items_added(PyQt_PyObject)"), + QtCore.SIGNAL("items_added(PyQt_PyObject)"), self.vms_added) - self.connect(self, SIGNAL("backup_progress(int)"), + self.connect(self, QtCore.SIGNAL("backup_progress(int)"), self.progress_bar.setValue) self.dir_line_edit.connect(self.dir_line_edit, - SIGNAL("textChanged(QString)"), + QtCore.SIGNAL("textChanged(QString)"), self.backup_location_changed) self.select_vms_page.isComplete = self.has_selected_vms @@ -90,15 +92,15 @@ class BackupVMsWindow(Ui_Backup, QWizard): # this causes to run isComplete() twice, I don't know why self.select_vms_page.connect( self.select_vms_widget, - SIGNAL("selected_changed()"), - SIGNAL("completeChanged()")) + QtCore.SIGNAL("selected_changed()"), + QtCore.SIGNAL("completeChanged()")) self.passphrase_line_edit.connect( self.passphrase_line_edit, - SIGNAL("textChanged(QString)"), + QtCore.SIGNAL("textChanged(QString)"), self.backup_location_changed) self.passphrase_line_edit_verify.connect( self.passphrase_line_edit_verify, - SIGNAL("textChanged(QString)"), + QtCore.SIGNAL("textChanged(QString)"), self.backup_location_changed) self.total_size = 0 @@ -123,7 +125,7 @@ class BackupVMsWindow(Ui_Backup, QWizard): def load_settings(self): try: - profile_data = load_backup_profile() + profile_data = backup_utils.load_backup_profile() except Exception as ex: # TODO: fix just for file not found return if not profile_data: @@ -157,9 +159,9 @@ class BackupVMsWindow(Ui_Backup, QWizard): 'include': [vm.name for vm in self.selected_vms], 'passphrase_text': self.passphrase_line_edit.text()} # TODO: add compression when it is added - write_backup_profile(settings) + backup_utils.write_backup_profile(settings) - class VmListItem(QListWidgetItem): + class VmListItem(QtGui.QListWidgetItem): def __init__(self, vm): self.vm = vm if vm.qid == 0: @@ -205,9 +207,9 @@ class BackupVMsWindow(Ui_Backup, QWizard): self.total_size_label.setText( admin_utils.size_to_human(self.total_size)) - @pyqtSlot(name='on_select_path_button_clicked') + @QtCore.pyqtSlot(name='on_select_path_button_clicked') def select_path_button_clicked(self): - select_path_button_clicked(self) + backup_utils.select_path_button_clicked(self) def validateCurrentPage(self): if self.currentPage() is self.select_vms_page: @@ -220,26 +222,26 @@ class BackupVMsWindow(Ui_Backup, QWizard): elif self.currentPage() is self.select_dir_page: backup_location = str(self.dir_line_edit.text()) if not backup_location: - QMessageBox.information( + QtGui.QMessageBox.information( None, self.tr("Wait!"), self.tr("Enter backup target location first.")) return False if self.appvm_combobox.currentIndex() == 0 \ and not os.path.isdir(backup_location): - QMessageBox.information( + QtGui.QMessageBox.information( None, self.tr("Wait!"), self.tr("Selected directory do not exists or " "not a directory (%s).") % backup_location) return False if not len(self.passphrase_line_edit.text()): - QMessageBox.information( + QtGui.QMessageBox.information( None, self.tr("Wait!"), self.tr("Enter passphrase for backup " "encryption/verification first.")) return False if self.passphrase_line_edit.text() !=\ self.passphrase_line_edit_verify.text(): - QMessageBox.information( + QtGui.QMessageBox.information( None, self.tr("Wait!"), self.tr("Enter the same passphrase in both fields.")) return False @@ -250,7 +252,7 @@ class BackupVMsWindow(Ui_Backup, QWizard): # self.func_output.append(s) def update_progress_bar(self, value): - self.emit(SIGNAL("backup_progress(int)"), value) + self.emit(QtCore.SIGNAL("backup_progress(int)"), value) def __do_backup__(self, thread_monitor): msg = [] @@ -301,9 +303,10 @@ class BackupVMsWindow(Ui_Backup, QWizard): self.showFileDialog.setChecked(self.showFileDialog.isEnabled() and str(self.dir_line_edit.text()) .count("media/") > 0) - self.thread_monitor = ThreadMonitor() - thread = threading.Thread(target=self.__do_backup__, - args=(self.thread_monitor,)) + self.thread_monitor = thread_monitor.ThreadMonitor() + thread = threading.Thread( + target=self.__do_backup__, + args=(self.thread_monitor,)) thread.daemon = True thread.start() @@ -315,17 +318,17 @@ class BackupVMsWindow(Ui_Backup, QWizard): if self.canceled: self.progress_status.setText(self.tr("Backup aborted.")) if self.tmpdir_to_remove: - if QMessageBox.warning( + if QtGui.QMessageBox.warning( None, self.tr("Backup aborted"), self.tr( "Do you want to remove temporary files " "from %s?") % self.tmpdir_to_remove, - QMessageBox.Yes, QMessageBox.No) == \ - QMessageBox.Yes: + QtGui.QMessageBox.Yes, + QtGui.QMessageBox.No) == QtGui.QMessageBox.Yes: shutil.rmtree(self.tmpdir_to_remove) else: self.progress_status.setText(self.tr("Backup error.")) - QMessageBox.warning( + QtGui.QMessageBox.warning( self, self.tr("Backup error!"), self.tr("ERROR: {}").format( self.thread_monitor.error_msg)) @@ -368,7 +371,7 @@ class BackupVMsWindow(Ui_Backup, QWizard): return len(self.dir_line_edit.text()) > 0 def backup_location_changed(self, new_dir=None): - self.select_dir_page.emit(SIGNAL("completeChanged()")) + self.select_dir_page.emit(QtCore.SIGNAL("completeChanged()")) # Bases on the original code by: diff --git a/qubesmanager/backup_utils.py b/qubesmanager/backup_utils.py index 102b5be..083c4da 100644 --- a/qubesmanager/backup_utils.py +++ b/qubesmanager/backup_utils.py @@ -20,8 +20,8 @@ # # import re -from PyQt4.QtCore import * -from PyQt4.QtGui import * +from PyQt4 import QtGui +from PyQt4 import QtCore import subprocess from . import utils @@ -63,7 +63,7 @@ def enable_dir_line_edit(dialog, boolean): def select_path_button_clicked(dialog, select_file=False): backup_location = str(dialog.dir_line_edit.text()) - file_dialog = QFileDialog() + file_dialog = QtGui.QFileDialog() file_dialog.setReadOnly(True) new_path = None @@ -77,7 +77,7 @@ def select_path_button_clicked(dialog, select_file=False): "qubes.SelectFile" if select_file else "qubes.SelectDirectory") except subprocess.CalledProcessError as ex: - QMessageBox.warning( + QtGui.QMessageBox.warning( None, dialog.tr("Nothing selected!"), dialog.tr("No file or directory selected.")) @@ -87,7 +87,7 @@ def select_path_button_clicked(dialog, select_file=False): dialog.dir_line_edit.setText(new_path) if new_path and len(backup_location) > 0: - dialog.select_dir_page.emit(SIGNAL("completeChanged()")) + dialog.select_dir_page.emit(QtCore.SIGNAL("completeChanged()")) def load_backup_profile(): diff --git a/qubesmanager/restore.py b/qubesmanager/restore.py index f7f44b8..46e56f5 100644 --- a/qubesmanager/restore.py +++ b/qubesmanager/restore.py @@ -24,30 +24,29 @@ import sys import os import shutil -from PyQt4.QtCore import * -from PyQt4.QtGui import * -from .thread_monitor import * +from PyQt4 import QtCore +from PyQt4 import QtGui +from . import thread_monitor +import threading import time import os.path import traceback -import qubesmanager.resources_rc import signal from qubes import backup -from .ui_restoredlg import * -from .multiselectwidget import * +from . import ui_restoredlg +from . import multiselectwidget -from .backup_utils import * +from . import backup_utils from multiprocessing import Queue, Event from multiprocessing.queues import Empty -from qubesadmin import Qubes, events, exc -from qubesadmin import utils as admin_utils +from qubesadmin import Qubes, exc from qubesadmin.backup import restore -class RestoreVMsWindow(Ui_Restore, QWizard): +class RestoreVMsWindow(ui_restoredlg.Ui_Restore, QtGui.QWizard): __pyqtSignals__ = ("restore_progress(int)", "backup_progress(int)") @@ -69,20 +68,20 @@ class RestoreVMsWindow(Ui_Restore, QWizard): self.setupUi(self) - self.select_vms_widget = MultiSelectWidget(self) + self.select_vms_widget = multiselectwidget.MultiSelectWidget(self) self.select_vms_layout.insertWidget(1, self.select_vms_widget) self.connect(self, - SIGNAL("currentIdChanged(int)"), self.current_page_changed) + QtCore.SIGNAL("currentIdChanged(int)"), self.current_page_changed) self.connect(self, - SIGNAL("restore_progress(QString)"), + QtCore.SIGNAL("restore_progress(QString)"), self.commit_text_edit.append) self.connect(self, - SIGNAL("backup_progress(int)"), self.progress_bar.setValue) + QtCore.SIGNAL("backup_progress(int)"), self.progress_bar.setValue) self.dir_line_edit.connect(self.dir_line_edit, - SIGNAL("textChanged(QString)"), + QtCore.SIGNAL("textChanged(QString)"), self.backup_location_changed) - self.connect(self.verify_only, SIGNAL("stateChanged(int)"), + self.connect(self.verify_only, QtCore.SIGNAL("stateChanged(int)"), self.on_verify_only_toogled) self.select_dir_page.isComplete = self.has_selected_dir @@ -92,15 +91,15 @@ class RestoreVMsWindow(Ui_Restore, QWizard): # this causes to run isComplete() twice, I don't know why self.select_vms_page.connect( self.select_vms_widget, - SIGNAL("selected_changed()"), - SIGNAL("completeChanged()")) + QtCore.SIGNAL("selected_changed()"), + QtCore.SIGNAL("completeChanged()")) - fill_appvms_list(self) + backup_utils.fill_appvms_list(self) # self.__init_restore_options__() - @pyqtSlot(name='on_select_path_button_clicked') + @QtCore.pyqtSlot(name='on_select_path_button_clicked') def select_path_button_clicked(self): - select_path_button_clicked(self, True) + backup_utils.select_path_button_clicked(self, True) def on_ignore_missing_toggled(self, checked): self.restore_options['use-default-template'] = checked @@ -158,22 +157,22 @@ class RestoreVMsWindow(Ui_Restore, QWizard): continue self.select_vms_widget.available_list.addItem(vmname) except exc.QubesException as ex: - QMessageBox.warning(None, self.tr("Restore error!"), str(ex)) + QtGui.QMessageBox.warning(None, self.tr("Restore error!"), str(ex)) def gather_output(self, s): self.func_output.append(s) def restore_error_output(self, s): self.error_detected.set() - self.feedback_queue.put((SIGNAL("restore_progress(QString)"), + self.feedback_queue.put((QtCore.SIGNAL("restore_progress(QString)"), u'{0}'.format(s))) def restore_output(self, s): - self.feedback_queue.put((SIGNAL("restore_progress(QString)"), + self.feedback_queue.put((QtCore.SIGNAL("restore_progress(QString)"), u'{0}'.format(s))) def update_progress_bar(self, value): - self.feedback_queue.put((SIGNAL("backup_progress(int)"), value)) + self.feedback_queue.put((QtCore.SIGNAL("backup_progress(int)"), value)) def __do_restore__(self, thread_monitor): err_msg = [] @@ -192,17 +191,17 @@ class RestoreVMsWindow(Ui_Restore, QWizard): "investigate them and/or clean them up")) if self.canceled: - self.emit(SIGNAL("restore_progress(QString)"), + self.emit(QtCore.SIGNAL("restore_progress(QString)"), '{0}' .format(self.tr("Restore aborted!"))) elif len(err_msg) > 0 or self.error_detected.is_set(): if len(err_msg) > 0: thread_monitor.set_error_msg('\n'.join(err_msg)) - self.emit(SIGNAL("restore_progress(QString)"), + self.emit(QtCore.SIGNAL("restore_progress(QString)"), '{0}' .format(self.tr("Finished with errors!"))) else: - self.emit(SIGNAL("restore_progress(QString)"), + self.emit(QtCore.SIGNAL("restore_progress(QString)"), '{0}' .format(self.tr("Finished successfully!"))) @@ -234,7 +233,7 @@ class RestoreVMsWindow(Ui_Restore, QWizard): self.confirm_text_edit.setFontFamily("Monospace") self.confirm_text_edit.setText(self.func_output) - self.confirm_page.emit(SIGNAL("completeChanged()")) + self.confirm_page.emit(QtCore.SIGNAL("completeChanged()")) elif self.currentPage() is self.commit_page: self.button(self.FinishButton).setDisabled(True) @@ -243,8 +242,8 @@ class RestoreVMsWindow(Ui_Restore, QWizard): and str(self.dir_line_edit.text()) .count("media/") > 0) - self.thread_monitor = ThreadMonitor() - thread = threading.Thread (target= self.__do_restore__ , args=(self.thread_monitor,)) + self.thread_monitor = thread_monitor.ThreadMonitor() + thread = threading.Thread (target= self.__do_restore__, args=(self.thread_monitor,)) thread.daemon = True thread.start() @@ -260,19 +259,23 @@ class RestoreVMsWindow(Ui_Restore, QWizard): if not self.thread_monitor.success: if self.canceled: if self.tmpdir_to_remove and \ - QMessageBox.warning(None, self.tr("Restore aborted"), + QtGui.QMessageBox.warning( + None, + self.tr("Restore aborted"), self.tr("Do you want to remove temporary files " "from %s?") % self.tmpdir_to_remove, - QMessageBox.Yes, QMessageBox.No) == \ - QMessageBox.Yes: + QtGui.QMessageBox.Yes, + QtGui.QMessageBox.No) == QtGui.QMessageBox.Yes: shutil.rmtree(self.tmpdir_to_remove) else: - QMessageBox.warning(None, - self.tr("Backup error!"), self.tr("ERROR: {0}") - .format(self.thread_monitor.error_msg)) + QtGui.QMessageBox.warning( + None, + self.tr("Backup error!"), + self.tr("ERROR: {0}").format( + self.thread_monitor.error_msg)) if self.showFileDialog.isChecked(): # TODO: this is not working - self.emit(SIGNAL("restore_progress(QString)"), + self.emit(QtCore.SIGNAL("restore_progress(QString)"), '{0}'.format( self.tr( "Please unmount your backup volume and cancel" @@ -281,7 +284,7 @@ class RestoreVMsWindow(Ui_Restore, QWizard): self.target_appvm.run("QUBESRPC %s dom0" % "qubes.SelectDirectory") else: - file_dialog = QFileDialog() + file_dialog = QtGui.QFileDialog() file_dialog.setReadOnly(True) file_dialog.getExistingDirectory( self, self.tr("Detach backup device"), @@ -304,7 +307,7 @@ class RestoreVMsWindow(Ui_Restore, QWizard): def reject(self): # TODO: probably not working too if self.currentPage() is self.commit_page: if self.backup_restore.canceled: - self.emit(SIGNAL("restore_progress(QString)"), + self.emit(QtCore.SIGNAL("restore_progress(QString)"), '{0}' .format(self.tr("Aborting the operation..."))) self.button(self.CancelButton).setDisabled(True) @@ -328,7 +331,7 @@ class RestoreVMsWindow(Ui_Restore, QWizard): return self.select_vms_widget.selected_list.count() > 0 def backup_location_changed(self, new_dir=None): - self.select_dir_page.emit(SIGNAL("completeChanged()")) + self.select_dir_page.emit(QtCore.SIGNAL("completeChanged()")) # Bases on the original code by: @@ -340,18 +343,18 @@ def handle_exception(exc_type, exc_value, exc_traceback): filename = os.path.basename(filename) error = "%s: %s" % (exc_type.__name__, exc_value) - QMessageBox.critical(None, "Houston, we have a problem...", + QtGui.QMessageBox.critical(None, "Houston, we have a problem...", "Whoops. A critical error has occured. " "This is most likely a bug " "in Qubes Restore VMs application.

" "%s" % error + "at line %d of file %s.

" - % (line, filename)) + % (line, filename)) def main(): - qtapp = QApplication(sys.argv) + qtapp = QtGui.QApplication(sys.argv) qtapp.setOrganizationName("The Qubes Project") qtapp.setOrganizationDomain("http://qubes-os.org") qtapp.setApplicationName("Qubes Restore VMs")