From 6f465fc67400e300bd802109f95e08141001f406 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Sun, 23 Aug 2020 02:53:36 +0200 Subject: [PATCH] Make pylint happy - fix super-with-arguments - fix various other issues - review broad-except and ignore where appropriate --- qubesmanager/about.py | 2 +- qubesmanager/appmenu_select.py | 2 +- qubesmanager/backup.py | 2 +- qubesmanager/backup_utils.py | 2 +- qubesmanager/bootfromdevice.py | 2 +- qubesmanager/clone_vm.py | 2 +- qubesmanager/common_threads.py | 2 +- qubesmanager/create_new_vm.py | 2 +- qubesmanager/device_list.py | 2 +- qubesmanager/firewall.py | 2 +- qubesmanager/global_settings.py | 19 ++++++++++--------- qubesmanager/informationnotes.py | 2 +- qubesmanager/log_dialog.py | 2 +- qubesmanager/multiselectwidget.py | 2 +- qubesmanager/qube_manager.py | 25 ++++++++++++------------- qubesmanager/releasenotes.py | 2 +- qubesmanager/restore.py | 4 ++-- qubesmanager/settings.py | 10 +++++----- qubesmanager/template_manager.py | 10 +++++----- qubesmanager/utils.py | 2 +- 20 files changed, 49 insertions(+), 49 deletions(-) diff --git a/qubesmanager/about.py b/qubesmanager/about.py index 49670b6..da3f398 100644 --- a/qubesmanager/about.py +++ b/qubesmanager/about.py @@ -31,7 +31,7 @@ from . import ui_about # pylint: disable=no-name-in-module # pylint: disable=too-few-public-methods class AboutDialog(ui_about.Ui_AboutDialog, QDialog): def __init__(self): - super(AboutDialog, self).__init__() + super().__init__() self.setupUi(self) diff --git a/qubesmanager/appmenu_select.py b/qubesmanager/appmenu_select.py index bd4788b..a1cd907 100755 --- a/qubesmanager/appmenu_select.py +++ b/qubesmanager/appmenu_select.py @@ -28,7 +28,7 @@ from qubesadmin import exc # pylint: disable=too-few-public-methods class AppListWidgetItem(QtWidgets.QListWidgetItem): def __init__(self, name, ident, tooltip=None, parent=None): - super(AppListWidgetItem, self).__init__(name, parent) + super().__init__(name, parent) additional_description = ".desktop filename: " + str(ident) if not tooltip: tooltip = additional_description diff --git a/qubesmanager/backup.py b/qubesmanager/backup.py index 81dca30..c1ba6e9 100644 --- a/qubesmanager/backup.py +++ b/qubesmanager/backup.py @@ -70,7 +70,7 @@ class BackupThread(QtCore.QThread): class BackupVMsWindow(ui_backupdlg.Ui_Backup, QtWidgets.QWizard): def __init__(self, qt_app, qubes_app, dispatcher, parent=None): - super(BackupVMsWindow, self).__init__(parent) + super().__init__(parent) self.qt_app = qt_app self.qubes_app = qubes_app diff --git a/qubesmanager/backup_utils.py b/qubesmanager/backup_utils.py index a791064..ae67945 100644 --- a/qubesmanager/backup_utils.py +++ b/qubesmanager/backup_utils.py @@ -101,7 +101,7 @@ def select_path_button_clicked(dialog, select_file=False, read_only=False): dialog.tr("Unexpected characters in path!"), dialog.tr("Backup path can only contain the following " "special characters: /:.,_+=() -")) - except Exception as ex: + except Exception as ex: # pylint: disable=broad-except QtWidgets.QMessageBox.warning( dialog, dialog.tr("Failed to select path!"), diff --git a/qubesmanager/bootfromdevice.py b/qubesmanager/bootfromdevice.py index 0ee48ff..dfdd3a6 100644 --- a/qubesmanager/bootfromdevice.py +++ b/qubesmanager/bootfromdevice.py @@ -30,7 +30,7 @@ from qubesadmin import exc class VMBootFromDeviceWindow(ui_bootfromdevice.Ui_BootDialog, QtWidgets.QDialog): def __init__(self, vm, qapp, qubesapp=None, parent=None): - super(VMBootFromDeviceWindow, self).__init__(parent) + super().__init__(parent) self.vm = vm self.qapp = qapp diff --git a/qubesmanager/clone_vm.py b/qubesmanager/clone_vm.py index df91646..9c8df77 100644 --- a/qubesmanager/clone_vm.py +++ b/qubesmanager/clone_vm.py @@ -38,7 +38,7 @@ from .ui_clonevmdlg import Ui_CloneVMDlg # pylint: disable=import-error class CloneVMDlg(QtWidgets.QDialog, Ui_CloneVMDlg): def __init__(self, qtapp, app, parent=None, src_vm=None): - super(CloneVMDlg, self).__init__(parent) + super().__init__(parent) self.setupUi(self) self.qtapp = qtapp diff --git a/qubesmanager/common_threads.py b/qubesmanager/common_threads.py index 0957f3a..d3a0ebc 100644 --- a/qubesmanager/common_threads.py +++ b/qubesmanager/common_threads.py @@ -56,7 +56,7 @@ class RemoveVMThread(QubesThread): # pylint: disable=too-few-public-methods class CloneVMThread(QubesThread): def __init__(self, vm, dst_name, pool=None, label=None): - super(CloneVMThread, self).__init__(vm) + super().__init__(vm) self.dst_name = dst_name self.pool = pool self.label = label diff --git a/qubesmanager/create_new_vm.py b/qubesmanager/create_new_vm.py index b1be32a..a89aca3 100644 --- a/qubesmanager/create_new_vm.py +++ b/qubesmanager/create_new_vm.py @@ -87,7 +87,7 @@ class CreateVMThread(QtCore.QThread): class NewVmDlg(QtWidgets.QDialog, Ui_NewVMDlg): def __init__(self, qtapp, app, parent=None): - super(NewVmDlg, self).__init__(parent) + super().__init__(parent) self.setupUi(self) self.qtapp = qtapp diff --git a/qubesmanager/device_list.py b/qubesmanager/device_list.py index 80a4b25..284ddc2 100644 --- a/qubesmanager/device_list.py +++ b/qubesmanager/device_list.py @@ -23,7 +23,7 @@ from PyQt5 import QtWidgets # pylint: disable=import-error class PCIDeviceListWindow(ui_devicelist.Ui_Dialog, QtWidgets.QDialog): def __init__(self, vm, qapp, dev_list, no_strict_reset_list, parent=None): - super(PCIDeviceListWindow, self).__init__(parent) + super().__init__(parent) self.vm = vm self.qapp = qapp diff --git a/qubesmanager/firewall.py b/qubesmanager/firewall.py index e935827..f095074 100644 --- a/qubesmanager/firewall.py +++ b/qubesmanager/firewall.py @@ -33,7 +33,7 @@ class FirewallModifiedOutsideError(ValueError): class NewFwRuleDlg(QtWidgets.QDialog, ui_newfwruledlg.Ui_NewFwRuleDlg): def __init__(self, parent=None): - super(NewFwRuleDlg, self).__init__(parent) + super().__init__(parent) self.setupUi(self) self.set_ok_state(False) diff --git a/qubesmanager/global_settings.py b/qubesmanager/global_settings.py index 067cf66..334f31b 100644 --- a/qubesmanager/global_settings.py +++ b/qubesmanager/global_settings.py @@ -50,12 +50,12 @@ def _run_qrexec_repo(service, arg=''): env=env ) if p.stderr: - raise RuntimeError( + raise exc.QubesException( QtCore.QCoreApplication.translate( "GlobalSettings", 'qrexec call stderr was not empty'), {'stderr': p.stderr.decode('utf-8')}) if p.returncode != 0: - raise RuntimeError( + raise exc.QubesException( QtCore.QCoreApplication.translate( "GlobalSettings", 'qrexec call exited with non-zero return code'), @@ -67,7 +67,7 @@ class GlobalSettingsWindow(ui_globalsettingsdlg.Ui_GlobalSettings, QtWidgets.QDialog): def __init__(self, app, qubes_app, parent=None): - super(GlobalSettingsWindow, self).__init__(parent) + super().__init__(parent) self.app = app self.qubes_app = qubes_app @@ -287,7 +287,7 @@ class GlobalSettingsWindow(ui_globalsettingsdlg.Ui_GlobalSettings, else: try: self.vm.features[feature] = widget.currentData() - except exc.QubesDaemonAccessError as ex: + except exc.QubesDaemonAccessError: self.errors.append( "Failed to set {} due to insufficient " "permissions".format(feature)) @@ -309,7 +309,8 @@ class GlobalSettingsWindow(ui_globalsettingsdlg.Ui_GlobalSettings, try: self.qmemman_config = ConfigParser() self.vm_min_mem_val = '200MiB' # str(qmemman_algo.MIN_PREFMEM) - self.dom0_mem_boost_val = '350MiB' # str(qmemman_algo.DOM0_MEM_BOOST) + # str(qmemman_algo.DOM0_MEM_BOOST) + self.dom0_mem_boost_val = '350MiB' self.qmemman_config.read(qmemman_config_path) if self.qmemman_config.has_section('global'): @@ -360,7 +361,7 @@ class GlobalSettingsWindow(ui_globalsettingsdlg.Ui_GlobalSettings, qmemman_config_file = open(qmemman_config_path, 'a') self.qmemman_config.write(qmemman_config_file) qmemman_config_file.close() - except Exception as ex: + except Exception as ex: # pylint: disable=broad-except self.errors.append( "Failed to set memory settings due to {}".format( str(ex))) @@ -380,7 +381,7 @@ class GlobalSettingsWindow(ui_globalsettingsdlg.Ui_GlobalSettings, try: qmemman_config_file = open(qmemman_config_path, 'r') - except Exception as ex: + except Exception as ex: # pylint: disable=broad-except self.errors.append( "Failed to set memory settings due to {}".format( str(ex))) @@ -405,7 +406,7 @@ class GlobalSettingsWindow(ui_globalsettingsdlg.Ui_GlobalSettings, qmemman_config_file = open(qmemman_config_path, 'w') qmemman_config_file.writelines(config_lines) qmemman_config_file.close() - except Exception as ex: + except Exception as ex: # pylint: disable=broad-except self.errors.append( "Failed to set memory settings due to {}".format( str(ex))) @@ -435,7 +436,7 @@ class GlobalSettingsWindow(ui_globalsettingsdlg.Ui_GlobalSettings, dct = repos[lst[0]] = dict() dct['prettyname'] = lst[1] dct['enabled'] = lst[2] == 'enabled' - except Exception as ex: + except exc.QubesException: self.dom0_updates_repo.setEnabled(False) self.itl_tmpl_updates_repo.setEnabled(False) self.comm_tmpl_updates_repo.setEnabled(False) diff --git a/qubesmanager/informationnotes.py b/qubesmanager/informationnotes.py index b5adc32..4383aac 100644 --- a/qubesmanager/informationnotes.py +++ b/qubesmanager/informationnotes.py @@ -30,7 +30,7 @@ class InformationNotesDialog(ui_informationnotes.Ui_InformationNotesDialog, QDialog): # pylint: disable=too-few-public-methods def __init__(self): - super(InformationNotesDialog, self).__init__() + super().__init__() self.setupUi(self) details = subprocess.check_output( diff --git a/qubesmanager/log_dialog.py b/qubesmanager/log_dialog.py index e0e999c..a5f07b9 100644 --- a/qubesmanager/log_dialog.py +++ b/qubesmanager/log_dialog.py @@ -36,7 +36,7 @@ class LogDialog(ui_logdlg.Ui_LogDialog, QtWidgets.QDialog): # pylint: disable=too-few-public-methods def __init__(self, app, log_path, parent=None): - super(LogDialog, self).__init__(parent) + super().__init__(parent) self.app = app self.log_path = log_path diff --git a/qubesmanager/multiselectwidget.py b/qubesmanager/multiselectwidget.py index bad8005..91d7f23 100644 --- a/qubesmanager/multiselectwidget.py +++ b/qubesmanager/multiselectwidget.py @@ -10,7 +10,7 @@ class MultiSelectWidget( itemsRemoved = QtCore.pyqtSignal(list) def __init__(self, parent=None): - super(MultiSelectWidget, self).__init__(parent) + super().__init__(parent) self.setupUi(self) self.add_selected_button.clicked.connect(self.add_selected) self.add_all_button.clicked.connect(self.add_all) diff --git a/qubesmanager/qube_manager.py b/qubesmanager/qube_manager.py index 71363e2..8fde5d1 100644 --- a/qubesmanager/qube_manager.py +++ b/qubesmanager/qube_manager.py @@ -58,16 +58,16 @@ from . import clone_vm class SearchBox(QLineEdit): def __init__(self, parent=None): - super(SearchBox, self).__init__(parent) + super().__init__(parent) self.focusing = False def focusInEvent(self, e): # pylint: disable=invalid-name - super(SearchBox, self).focusInEvent(e) + super().focusInEvent(e) self.selectAll() self.focusing = True def mousePressEvent(self, e): # pylint: disable=invalid-name - super(SearchBox, self).mousePressEvent(e) + super().mousePressEvent(e) if self.focusing: self.selectAll() self.focusing = False @@ -78,7 +78,7 @@ icon_size = QSize(22, 22) class StateIconDelegate(QStyledItemDelegate): lastIndex = None def __init__(self): - super(StateIconDelegate, self).__init__() + super().__init__() self.stateIcons = { "Running" : QIcon(":/on.png"), "Paused" : QIcon(":/paused.png"), @@ -104,7 +104,7 @@ class StateIconDelegate(QStyledItemDelegate): } def sizeHint(self, option, index): - hint = super(StateIconDelegate, self).sizeHint(option, index) + hint = super().sizeHint(option, index) option = QStyleOptionViewItem(option) option.features |= option.HasDecoration widget = option.widget @@ -153,7 +153,7 @@ class StateIconDelegate(QStyledItemDelegate): def helpEvent(self, event, view, option, index): if event.type() != QEvent.ToolTip: - return super(StateIconDelegate, self).helpEvent(event, view, + return super().helpEvent(event, view, option, index) option = QStyleOptionViewItem(option) widget = option.widget @@ -222,10 +222,9 @@ class VmInfo(): self.state['outdated'] = "to-be-outdated" else: try: - for vol in self.vm.volumes.values(): - if vol.is_outdated(): - self.state['outdated'] = "outdated" - break + if any(vol.is_outdated() + for vol in self.vm.volumes.values()): + self.state['outdated'] = "outdated" except exc.QubesDaemonAccessError: pass @@ -612,7 +611,7 @@ class UpdateVMThread(common_threads.QubesThread): # pylint: disable=too-few-public-methods class RunCommandThread(common_threads.QubesThread): def __init__(self, vm, command_to_run): - super(RunCommandThread, self).__init__(vm) + super().__init__(vm) self.command_to_run = command_to_run def run(self): @@ -638,7 +637,7 @@ class VmManagerWindow(ui_qubemanager.Ui_VmManagerWindow, QMainWindow): settings_loaded = False def __init__(self, qt_app, qubes_app, dispatcher, _parent=None): - super(VmManagerWindow, self).__init__() + super().__init__() self.setupUi(self) self.manager_settings = QSettings(self) @@ -816,7 +815,7 @@ class VmManagerWindow(ui_qubemanager.Ui_VmManagerWindow, QMainWindow): def keyPressEvent(self, event): # pylint: disable=invalid-name if event.key() == Qt.Key_Escape: self.searchbox.clear() - super(VmManagerWindow, self).keyPressEvent(event) + super().keyPressEvent(event) def clear_threads(self): for thread in self.threads_list: diff --git a/qubesmanager/releasenotes.py b/qubesmanager/releasenotes.py index 7ac3a7c..b91fb57 100644 --- a/qubesmanager/releasenotes.py +++ b/qubesmanager/releasenotes.py @@ -28,7 +28,7 @@ from . import ui_releasenotes # pylint: disable=no-name-in-module class ReleaseNotesDialog(ui_releasenotes.Ui_ReleaseNotesDialog, QDialog): # pylint: disable=too-few-public-methods def __init__(self): - super(ReleaseNotesDialog, self).__init__() + super().__init__() self.setupUi(self) diff --git a/qubesmanager/restore.py b/qubesmanager/restore.py index 6b62b44..63148a3 100644 --- a/qubesmanager/restore.py +++ b/qubesmanager/restore.py @@ -70,7 +70,7 @@ class RestoreThread(QtCore.QThread): class RestoreVMsWindow(ui_restoredlg.Ui_Restore, QtWidgets.QWizard): def __init__(self, qt_app, qubes_app, parent=None): - super(RestoreVMsWindow, self).__init__(parent) + super().__init__(parent) self.qt_app = qt_app self.qubes_app = qubes_app @@ -122,7 +122,7 @@ class RestoreVMsWindow(ui_restoredlg.Ui_Restore, QtWidgets.QWizard): if self.page(p_int) is self.select_vms_page: self.vms_to_restore = None else: - super(RestoreVMsWindow, self).cleanupPage(p_int) + super().cleanupPage(p_int) def __fill_vms_list__(self): if self.vms_to_restore is not None: diff --git a/qubesmanager/settings.py b/qubesmanager/settings.py index 29120da..0340f44 100644 --- a/qubesmanager/settings.py +++ b/qubesmanager/settings.py @@ -48,7 +48,7 @@ from . import ui_settingsdlg # pylint: disable=no-name-in-module # pylint: disable=too-few-public-methods class RenameVMThread(common_threads.QubesThread): def __init__(self, vm, new_vm_name, dependencies): - super(RenameVMThread, self).__init__(vm) + super().__init__(vm) self.new_vm_name = new_vm_name self.dependencies = dependencies @@ -88,7 +88,7 @@ class RenameVMThread(common_threads.QubesThread): # pylint: disable=too-few-public-methods class RefreshAppsVMThread(common_threads.QubesThread): def __init__(self, vm, button): - super(RefreshAppsVMThread, self).__init__(vm) + super().__init__(vm) self.button = button def run(self): @@ -129,7 +129,7 @@ class VMSettingsWindow(ui_settingsdlg.Ui_SettingsDialog, QtWidgets.QDialog): def __init__(self, vm, init_page="basic", qapp=None, qubesapp=None, parent=None): - super(VMSettingsWindow, self).__init__(parent) + super().__init__(parent) self.vm = vm self.qapp = qapp @@ -251,7 +251,7 @@ class VMSettingsWindow(ui_settingsdlg.Ui_SettingsDialog, QtWidgets.QDialog): if event.key() == QtCore.Qt.Key_Enter \ or event.key() == QtCore.Qt.Key_Return: return - super(VMSettingsWindow, self).keyPressEvent(event) + super().keyPressEvent(event) def accept(self): self.save_and_apply() @@ -1096,7 +1096,7 @@ class VMSettingsWindow(ui_settingsdlg.Ui_SettingsDialog, QtWidgets.QDialog): # pylint: disable=too-few-public-methods class DevListWidgetItem(QtWidgets.QListWidgetItem): def __init__(self, dev, unknown=False, parent=None): - super(DevListWidgetItem, self).__init__(parent) + super().__init__(parent) name = dev.ident.replace('_', ":") + ' ' + dev.description if unknown: name += ' (unknown)' diff --git a/qubesmanager/template_manager.py b/qubesmanager/template_manager.py index 7664eed..6ed44e0 100644 --- a/qubesmanager/template_manager.py +++ b/qubesmanager/template_manager.py @@ -35,7 +35,7 @@ class TemplateManagerWindow( def __init__(self, qt_app, qubes_app, dispatcher, parent=None): # pylint: disable=unused-argument - super(TemplateManagerWindow, self).__init__() + super().__init__() self.setupUi(self) self.qubes_app = qubes_app @@ -244,7 +244,7 @@ class TemplateManagerWindow( class VMNameItem(QtWidgets.QTableWidgetItem): # pylint: disable=too-few-public-methods def __init__(self, vm): - super(VMNameItem, self).__init__() + super().__init__() self.vm = vm self.setText(self.vm.name) @@ -253,7 +253,7 @@ class VMNameItem(QtWidgets.QTableWidgetItem): class StatusItem(QtWidgets.QTableWidgetItem): def __init__(self, vm): - super(StatusItem, self).__init__() + super().__init__() self.vm = vm self.state = None @@ -278,7 +278,7 @@ class StatusItem(QtWidgets.QTableWidgetItem): class CurrentTemplateItem(QtWidgets.QTableWidgetItem): # pylint: disable=too-few-public-methods def __init__(self, vm): - super(CurrentTemplateItem, self).__init__() + super().__init__() self.vm = vm self.setText(self.vm.template.name) @@ -291,7 +291,7 @@ class CurrentTemplateItem(QtWidgets.QTableWidgetItem): class NewTemplateItem(QtWidgets.QComboBox): def __init__(self, vm, templates, table_widget): - super(NewTemplateItem, self).__init__() + super().__init__() self.vm = vm self.table_widget = table_widget self.changed = False diff --git a/qubesmanager/utils.py b/qubesmanager/utils.py index 01cf041..7fb10ea 100644 --- a/qubesmanager/utils.py +++ b/qubesmanager/utils.py @@ -77,7 +77,7 @@ class SizeSpinBox(QtWidgets.QSpinBox): """A SpinBox subclass with extended handling for sizes in MB and GB""" # pylint: disable=invalid-name, no-self-use def __init__(self, *args, **kwargs): - super(SizeSpinBox, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) self.pattern = r'(\d+\.?\d?) ?(GB|MB)' self.regex = re.compile(self.pattern)