Pylint corrections

Removed errors discovered by pylint, or told it to be quiet when needed.
This commit is contained in:
Marta Marczykowska-Górecka 2018-01-08 03:06:42 +01:00
parent 41b8e6a4fb
commit 899ca6d394
No known key found for this signature in database
GPG Key ID: 9A752C30B26FD04B
4 changed files with 79 additions and 113 deletions

View File

@ -87,7 +87,7 @@ variable-rgx=[a-z_][a-z0-9_]{2,30}$
inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$ inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$
# Good variable names which should always be accepted, separated by a comma # Good variable names which should always be accepted, separated by a comma
good-names=e,i,j,k,m,p,v,ex,Run,_,log,vm,ok good-names=e,i,j,k,m,p,v,ex,Run,_,log,vm,ok,ip
# Bad variable names which should always be refused, separated by a comma # Bad variable names which should always be refused, separated by a comma
bad-names=foo,bar,baz,toto,tutu,tata bad-names=foo,bar,baz,toto,tutu,tata

View File

@ -20,10 +20,10 @@
# #
# #
from PyQt4 import QtCore from PyQt4 import QtCore # pylint: disable=import-error
from PyQt4 import QtGui from PyQt4 import QtGui # pylint: disable=import-error
from . import ui_logdlg from . import ui_logdlg # pylint: disable=no-name-in-module
from . import clipboard from . import clipboard
# Display only this size of log # Display only this size of log
@ -31,6 +31,7 @@ LOG_DISPLAY_SIZE = 1024*1024
class LogDialog(ui_logdlg.Ui_LogDialog, QtGui.QDialog): class LogDialog(ui_logdlg.Ui_LogDialog, QtGui.QDialog):
# pylint: disable=too-few-public-methods
def __init__(self, app, log_path, parent=None): def __init__(self, app, log_path, parent=None):
super(LogDialog, self).__init__(parent) super(LogDialog, self).__init__(parent)
@ -43,7 +44,7 @@ class LogDialog(ui_logdlg.Ui_LogDialog, QtGui.QDialog):
self.connect(self.copy_to_qubes_clipboard, self.connect(self.copy_to_qubes_clipboard,
QtCore.SIGNAL("clicked()"), QtCore.SIGNAL("clicked()"),
self.copy_to_qubes_clipboard_triggered) self.copy_to_clipboard_triggered)
self.__init_log_text__() self.__init_log_text__()
@ -61,5 +62,5 @@ class LogDialog(ui_logdlg.Ui_LogDialog, QtGui.QDialog):
log.close() log.close()
self.log_text.setPlainText(self.displayed_text) self.log_text.setPlainText(self.displayed_text)
def copy_to_qubes_clipboard_triggered(self): def copy_to_clipboard_triggered(self):
clipboard.copy_text_to_qubes_clipboard(self.displayed_text) clipboard.copy_text_to_qubes_clipboard(self.displayed_text)

View File

@ -31,11 +31,12 @@ from datetime import datetime, timedelta
import traceback import traceback
from qubesadmin import Qubes from qubesadmin import Qubes
from qubesadmin import exc
from PyQt4 import QtGui from PyQt4 import QtGui # pylint: disable=import-error
from PyQt4 import QtCore from PyQt4 import QtCore # pylint: disable=import-error
from . import ui_qubemanager from . import ui_qubemanager # pylint: disable=no-name-in-module
from . import thread_monitor from . import thread_monitor
from . import table_widgets from . import table_widgets
from . import settings from . import settings
@ -48,23 +49,17 @@ import threading
from qubesmanager.about import AboutDialog from qubesmanager.about import AboutDialog
class QMVmState:
ErrorMsg = 1
AudioRecAvailable = 2
AudioRecAllowed = 3
class SearchBox(QtGui.QLineEdit): class SearchBox(QtGui.QLineEdit):
def __init__(self, parent=None): def __init__(self, parent=None):
super(SearchBox, self).__init__(parent) super(SearchBox, self).__init__(parent)
self.focusing = False self.focusing = False
def focusInEvent(self, e): def focusInEvent(self, e): # pylint: disable=invalid-name
super(SearchBox, self).focusInEvent(e) super(SearchBox, self).focusInEvent(e)
self.selectAll() self.selectAll()
self.focusing = True self.focusing = True
def mousePressEvent(self, e): def mousePressEvent(self, e): # pylint: disable=invalid-name
super(SearchBox, self).mousePressEvent(e) super(SearchBox, self).mousePressEvent(e)
if self.focusing: if self.focusing:
self.selectAll() self.selectAll()
@ -72,6 +67,7 @@ class SearchBox(QtGui.QLineEdit):
class VmRowInTable(object): class VmRowInTable(object):
# pylint: disable=too-few-public-methods
def __init__(self, vm, row_no, table): def __init__(self, vm, row_no, table):
self.vm = vm self.vm = vm
@ -86,13 +82,13 @@ class VmRowInTable(object):
table.setCellWidget(row_no, VmManagerWindow.columns_indices['Type'], table.setCellWidget(row_no, VmManagerWindow.columns_indices['Type'],
self.type_widget) self.type_widget)
table.setItem(row_no, VmManagerWindow.columns_indices['Type'], table.setItem(row_no, VmManagerWindow.columns_indices['Type'],
self.type_widget.tableItem) self.type_widget.table_item)
self.label_widget = table_widgets.VmLabelWidget(vm) self.label_widget = table_widgets.VmLabelWidget(vm)
table.setCellWidget(row_no, VmManagerWindow.columns_indices['Label'], table.setCellWidget(row_no, VmManagerWindow.columns_indices['Label'],
self.label_widget) self.label_widget)
table.setItem(row_no, VmManagerWindow.columns_indices['Label'], table.setItem(row_no, VmManagerWindow.columns_indices['Label'],
self.label_widget.tableItem) self.label_widget.table_item)
self.name_widget = table_widgets.VmNameItem(vm) self.name_widget = table_widgets.VmNameItem(vm)
table.setItem(row_no, VmManagerWindow.columns_indices['Name'], table.setItem(row_no, VmManagerWindow.columns_indices['Name'],
@ -102,7 +98,7 @@ class VmRowInTable(object):
table.setCellWidget(row_no, VmManagerWindow.columns_indices['State'], table.setCellWidget(row_no, VmManagerWindow.columns_indices['State'],
self.info_widget) self.info_widget)
table.setItem(row_no, VmManagerWindow.columns_indices['State'], table.setItem(row_no, VmManagerWindow.columns_indices['State'],
self.info_widget.tableItem) self.info_widget.table_item)
self.template_widget = table_widgets.VmTemplateItem(vm) self.template_widget = table_widgets.VmTemplateItem(vm)
table.setItem(row_no, VmManagerWindow.columns_indices['Template'], table.setItem(row_no, VmManagerWindow.columns_indices['Template'],
@ -213,6 +209,7 @@ class VmShutdownMonitor(QtCore.QObject):
class VmManagerWindow(ui_qubemanager.Ui_VmManagerWindow, QtGui.QMainWindow): class VmManagerWindow(ui_qubemanager.Ui_VmManagerWindow, QtGui.QMainWindow):
# pylint: disable=too-many-instance-attributes
row_height = 30 row_height = 30
column_width = 200 column_width = 200
min_visible_rows = 10 min_visible_rows = 10
@ -233,6 +230,7 @@ class VmManagerWindow(ui_qubemanager.Ui_VmManagerWindow, QtGui.QMainWindow):
} }
def __init__(self, qubes_app, qt_app, parent=None): def __init__(self, qubes_app, qt_app, parent=None):
# pylint: disable=unused-argument
super(VmManagerWindow, self).__init__() super(VmManagerWindow, self).__init__()
self.setupUi(self) self.setupUi(self)
self.toolbar = self.toolBar self.toolbar = self.toolBar
@ -259,9 +257,6 @@ class VmManagerWindow(ui_qubemanager.Ui_VmManagerWindow, QtGui.QMainWindow):
self.vms_in_table = {} self.vms_in_table = {}
self.reload_table = False self.reload_table = False
self.vm_errors = {}
self.vm_rec = {}
self.frame_width = 0 self.frame_width = 0
self.frame_height = 0 self.frame_height = 0
@ -343,7 +338,7 @@ class VmManagerWindow(ui_qubemanager.Ui_VmManagerWindow, QtGui.QMainWindow):
self.connect( self.connect(
self.table.horizontalHeader(), self.table.horizontalHeader(),
QtCore.SIGNAL("sortIndicatorChanged(int, Qt::SortOrder)"), QtCore.SIGNAL("sortIndicatorChanged(int, Qt::SortOrder)"),
self.sortIndicatorChanged) self.sort_indicator_changed)
self.connect(self.table, self.connect(self.table,
QtCore.SIGNAL("customContextMenuRequested(const QPoint&)"), QtCore.SIGNAL("customContextMenuRequested(const QPoint&)"),
self.open_context_menu) self.open_context_menu)
@ -381,11 +376,11 @@ class VmManagerWindow(ui_qubemanager.Ui_VmManagerWindow, QtGui.QMainWindow):
def load_manager_settings(self): def load_manager_settings(self):
# visible columns # visible columns
for col in self.columns_indices.keys(): for col in self.columns_indices:
col_no = self.columns_indices[col] col_no = self.columns_indices[col]
visible = self.manager_settings.value( visible = self.manager_settings.value(
'columns/%s' % col, 'columns/%s' % col,
defaultValue=not self.table.isColumnHidden(col_no)) defaultValue="true")
self.columns_actions[col_no].setChecked(visible == "true") self.columns_actions[col_no].setChecked(visible == "true")
self.sort_by_column = str( self.sort_by_column = str(
@ -393,8 +388,7 @@ class VmManagerWindow(ui_qubemanager.Ui_VmManagerWindow, QtGui.QMainWindow):
defaultValue=self.sort_by_column)) defaultValue=self.sort_by_column))
self.sort_order = QtCore.Qt.SortOrder( self.sort_order = QtCore.Qt.SortOrder(
self.manager_settings.value("view/sort_order", self.manager_settings.value("view/sort_order",
defaultValue=self.sort_order)[ defaultValue=self.sort_order))
0])
self.table.sortItems(self.columns_indices[self.sort_by_column], self.table.sortItems(self.columns_indices[self.sort_by_column],
self.sort_order) self.sort_order)
if not self.manager_settings.value("view/menubar_visible", if not self.manager_settings.value("view/menubar_visible",
@ -478,13 +472,8 @@ class VmManagerWindow(ui_qubemanager.Ui_VmManagerWindow, QtGui.QMainWindow):
self.table_selection_changed() self.table_selection_changed()
# noinspection PyPep8Naming # noinspection PyPep8Naming
@QtCore.pyqtSlot(bool, str) def sort_indicator_changed(self, column, order):
def recAllowedChanged(self, state, vmname): self.sort_by_column = [name for name in self.columns_indices if
self.vm_rec[str(vmname)] = bool(state)
# noinspection PyPep8Naming
def sortIndicatorChanged(self, column, order):
self.sort_by_column = [name for name in self.columns_indices.keys() if
self.columns_indices[name] == column][0] self.columns_indices[name] == column][0]
self.sort_order = order self.sort_order = order
if self.settings_loaded: if self.settings_loaded:
@ -546,29 +535,9 @@ class VmManagerWindow(ui_qubemanager.Ui_VmManagerWindow, QtGui.QMainWindow):
self.action_run_command_in_vm.setEnabled(False) self.action_run_command_in_vm.setEnabled(False)
self.action_set_keyboard_layout.setEnabled(False) self.action_set_keyboard_layout.setEnabled(False)
def set_error(self, qid, message):
for vm in self.vms_list:
if vm.qid == qid:
vm.qubes_manager_state[QMVmState.ErrorMsg] = message
# Store error in separate dict to make it immune to VM list reload
self.vm_errors[qid] = str(message)
def clear_error(self, qid):
self.vm_errors.pop(qid, None)
for vm in self.vms_list:
if vm.qid == qid:
vm.qubes_manager_state[QMVmState.ErrorMsg] = None
def clear_error_exact(self, qid, message):
for vm in self.vms_list:
if vm.qid == qid:
if vm.qubes_manager_state[QMVmState.ErrorMsg] == message:
vm.qubes_manager_state[QMVmState.ErrorMsg] = None
self.vm_errors.pop(qid, None)
# noinspection PyArgumentList # noinspection PyArgumentList
@QtCore.pyqtSlot(name='on_action_createvm_triggered') @QtCore.pyqtSlot(name='on_action_createvm_triggered')
def action_createvm_triggered(self): def action_createvm_triggered(self): # pylint: disable=no-self-use
subprocess.check_call('qubes-vm-create') subprocess.check_call('qubes-vm-create')
def get_selected_vm(self): def get_selected_vm(self):
@ -665,7 +634,7 @@ class VmManagerWindow(ui_qubemanager.Ui_VmManagerWindow, QtGui.QMainWindow):
def do_remove_vm(vm, qubes_app, t_monitor): def do_remove_vm(vm, qubes_app, t_monitor):
try: try:
del qubes_app.domains[vm.name] del qubes_app.domains[vm.name]
except Exception as ex: except exc.QubesException as ex:
t_monitor.set_error_msg(str(ex)) t_monitor.set_error_msg(str(ex))
t_monitor.set_finished() t_monitor.set_finished()
@ -721,7 +690,7 @@ class VmManagerWindow(ui_qubemanager.Ui_VmManagerWindow, QtGui.QMainWindow):
dst_vm = None dst_vm = None
try: try:
dst_vm = qubes_app.clone_vm(src_vm, dst_name) dst_vm = qubes_app.clone_vm(src_vm, dst_name)
except Exception as ex: except exc.QubesException as ex:
t_monitor.set_error_msg(str(ex)) t_monitor.set_error_msg(str(ex))
if dst_vm: if dst_vm:
pass pass
@ -735,7 +704,7 @@ class VmManagerWindow(ui_qubemanager.Ui_VmManagerWindow, QtGui.QMainWindow):
if vm.get_power_state() in ["Paused", "Suspended"]: if vm.get_power_state() in ["Paused", "Suspended"]:
try: try:
vm.unpause() vm.unpause()
except Exception as ex: except exc.QubesException as ex:
QtGui.QMessageBox.warning( QtGui.QMessageBox.warning(
None, self.tr("Error unpausing Qube!"), None, self.tr("Error unpausing Qube!"),
self.tr("ERROR: {0}").format(ex)) self.tr("ERROR: {0}").format(ex))
@ -758,9 +727,10 @@ class VmManagerWindow(ui_qubemanager.Ui_VmManagerWindow, QtGui.QMainWindow):
time.sleep(0.1) time.sleep(0.1)
if not t_monitor.success: if not t_monitor.success:
self.set_error( QtGui.QMessageBox.warning(
vm.qid, None,
self.tr("Error starting Qube: %s") % t_monitor.error_msg) self.tr("Error starting Qube!"),
self.tr("ERROR: {0}").format(t_monitor.error_msg))
self.update_table() self.update_table()
@ -768,7 +738,7 @@ class VmManagerWindow(ui_qubemanager.Ui_VmManagerWindow, QtGui.QMainWindow):
def do_start_vm(vm, t_monitor): def do_start_vm(vm, t_monitor):
try: try:
vm.start() vm.start()
except Exception as ex: except exc.QubesException as ex:
t_monitor.set_error_msg(str(ex)) t_monitor.set_error_msg(str(ex))
t_monitor.set_finished() t_monitor.set_finished()
return return
@ -779,6 +749,7 @@ class VmManagerWindow(ui_qubemanager.Ui_VmManagerWindow, QtGui.QMainWindow):
@QtCore.pyqtSlot(name='on_action_startvm_tools_install_triggered') @QtCore.pyqtSlot(name='on_action_startvm_tools_install_triggered')
# TODO: replace with boot from device # TODO: replace with boot from device
def action_startvm_tools_install_triggered(self): def action_startvm_tools_install_triggered(self):
# pylint: disable=invalid-name
pass pass
@QtCore.pyqtSlot(name='on_action_pausevm_triggered') @QtCore.pyqtSlot(name='on_action_pausevm_triggered')
@ -788,7 +759,7 @@ class VmManagerWindow(ui_qubemanager.Ui_VmManagerWindow, QtGui.QMainWindow):
try: try:
vm.pause() vm.pause()
self.update_table() self.update_table()
except Exception as ex: except exc.QubesException as ex:
QtGui.QMessageBox.warning( QtGui.QMessageBox.warning(
None, None,
self.tr("Error pausing Qube!"), self.tr("Error pausing Qube!"),
@ -819,7 +790,7 @@ class VmManagerWindow(ui_qubemanager.Ui_VmManagerWindow, QtGui.QMainWindow):
check_time=vm_restart_check_timeout, and_restart=False): check_time=vm_restart_check_timeout, and_restart=False):
try: try:
vm.shutdown() vm.shutdown()
except Exception as ex: except exc.QubesException as ex:
QtGui.QMessageBox.warning( QtGui.QMessageBox.warning(
None, None,
self.tr("Error shutting down Qube!"), self.tr("Error shutting down Qube!"),
@ -873,7 +844,7 @@ class VmManagerWindow(ui_qubemanager.Ui_VmManagerWindow, QtGui.QMainWindow):
if reply == QtGui.QMessageBox.Yes: if reply == QtGui.QMessageBox.Yes:
try: try:
vm.force_shutdown() vm.force_shutdown()
except Exception as ex: except exc.QubesException as ex:
QtGui.QMessageBox.critical( QtGui.QMessageBox.critical(
None, self.tr("Error while killing Qube!"), None, self.tr("Error while killing Qube!"),
self.tr( self.tr(
@ -961,7 +932,7 @@ class VmManagerWindow(ui_qubemanager.Ui_VmManagerWindow, QtGui.QMainWindow):
vm.start() vm.start()
vm.run_service("qubes.InstallUpdatesGUI", vm.run_service("qubes.InstallUpdatesGUI",
user="root", wait=False) user="root", wait=False)
except Exception as ex: except (ChildProcessError, exc.QubesException) as ex:
t_monitor.set_error_msg(str(ex)) t_monitor.set_error_msg(str(ex))
t_monitor.set_finished() t_monitor.set_finished()
return return
@ -970,6 +941,7 @@ class VmManagerWindow(ui_qubemanager.Ui_VmManagerWindow, QtGui.QMainWindow):
# noinspection PyArgumentList # noinspection PyArgumentList
@QtCore.pyqtSlot(name='on_action_run_command_in_vm_triggered') @QtCore.pyqtSlot(name='on_action_run_command_in_vm_triggered')
def action_run_command_in_vm_triggered(self): def action_run_command_in_vm_triggered(self):
# pylint: disable=invalid-name
vm = self.get_selected_vm() vm = self.get_selected_vm()
(command_to_run, ok) = QtGui.QInputDialog.getText( (command_to_run, ok) = QtGui.QInputDialog.getText(
@ -997,13 +969,14 @@ class VmManagerWindow(ui_qubemanager.Ui_VmManagerWindow, QtGui.QMainWindow):
def do_run_command_in_vm(vm, command_to_run, t_monitor): def do_run_command_in_vm(vm, command_to_run, t_monitor):
try: try:
vm.run(command_to_run) vm.run(command_to_run)
except Exception as ex: except (ChildProcessError, exc.QubesException) as ex:
t_monitor.set_error_msg(str(ex)) t_monitor.set_error_msg(str(ex))
t_monitor.set_finished() t_monitor.set_finished()
# noinspection PyArgumentList # noinspection PyArgumentList
@QtCore.pyqtSlot(name='on_action_set_keyboard_layout_triggered') @QtCore.pyqtSlot(name='on_action_set_keyboard_layout_triggered')
def action_set_keyboard_layout_triggered(self): def action_set_keyboard_layout_triggered(self):
# pylint: disable=invalid-name
vm = self.get_selected_vm() vm = self.get_selected_vm()
vm.run('qubes-change-keyboard-layout') vm.run('qubes-change-keyboard-layout')
@ -1016,7 +989,7 @@ class VmManagerWindow(ui_qubemanager.Ui_VmManagerWindow, QtGui.QMainWindow):
# noinspection PyArgumentList # noinspection PyArgumentList
@QtCore.pyqtSlot(name='on_action_global_settings_triggered') @QtCore.pyqtSlot(name='on_action_global_settings_triggered')
def action_global_settings_triggered(self): def action_global_settings_triggered(self): # pylint: disable=invalid-name
global_settings_window = global_settings.GlobalSettingsWindow( global_settings_window = global_settings.GlobalSettingsWindow(
self.qt_app, self.qt_app,
self.qubes_app) self.qubes_app)
@ -1070,19 +1043,19 @@ class VmManagerWindow(ui_qubemanager.Ui_VmManagerWindow, QtGui.QMainWindow):
if self.visible_columns_count == 1: if self.visible_columns_count == 1:
# disable hiding the last one # disable hiding the last one
for c in self.columns_actions: for col in self.columns_actions:
if self.columns_actions[c].isChecked(): if self.columns_actions[col].isChecked():
self.columns_actions[c].setEnabled(False) self.columns_actions[col].setEnabled(False)
break break
elif self.visible_columns_count == 2 and val == 1: elif self.visible_columns_count == 2 and val == 1:
# enable hiding previously disabled column # enable hiding previously disabled column
for c in self.columns_actions: for col in self.columns_actions:
if not self.columns_actions[c].isEnabled(): if not self.columns_actions[col].isEnabled():
self.columns_actions[c].setEnabled(True) self.columns_actions[col].setEnabled(True)
break break
if self.settings_loaded: if self.settings_loaded:
col_name = [name for name in self.columns_indices.keys() if col_name = [name for name in self.columns_indices if
self.columns_indices[name] == col_num][0] self.columns_indices[name] == col_num][0]
self.manager_settings.setValue('columns/%s' % col_name, show) self.manager_settings.setValue('columns/%s' % col_name, show)
self.manager_settings.sync() self.manager_settings.sync()
@ -1122,11 +1095,11 @@ class VmManagerWindow(ui_qubemanager.Ui_VmManagerWindow, QtGui.QMainWindow):
# noinspection PyArgumentList # noinspection PyArgumentList
@QtCore.pyqtSlot(name='on_action_about_qubes_triggered') @QtCore.pyqtSlot(name='on_action_about_qubes_triggered')
def action_about_qubes_triggered(self): def action_about_qubes_triggered(self): # pylint: disable=no-self-use
about = AboutDialog() about = AboutDialog()
about.exec_() about.exec_()
def createPopupMenu(self): def createPopupMenu(self): # pylint: disable=invalid-name
menu = QtGui.QMenu() menu = QtGui.QMenu()
menu.addAction(self.action_toolbar) menu.addAction(self.action_toolbar)
menu.addAction(self.action_menubar) menu.addAction(self.action_menubar)

View File

@ -19,8 +19,9 @@
# You should have received a copy of the GNU Lesser General Public License along # You should have received a copy of the GNU Lesser General Public License along
# with this program; if not, see <http://www.gnu.org/licenses/>. # with this program; if not, see <http://www.gnu.org/licenses/>.
from PyQt4 import QtGui from PyQt4 import QtGui # pylint: disable=import-error
from PyQt4 import QtCore from PyQt4 import QtCore # pylint: disable=import-error
# pylint: disable=too-few-public-methods
power_order = QtCore.Qt.DescendingOrder power_order = QtCore.Qt.DescendingOrder
update_order = QtCore.Qt.AscendingOrder update_order = QtCore.Qt.AscendingOrder
@ -54,7 +55,7 @@ class VmIconWidget(QtGui.QWidget):
layout.setContentsMargins(0, 0, 0, 0) layout.setContentsMargins(0, 0, 0, 0)
self.setLayout(layout) self.setLayout(layout)
def setToolTip(self, tooltip): def setToolTip(self, tooltip): # pylint: disable=invalid-name
if tooltip is not None: if tooltip is not None:
self.label_icon.setToolTip(tooltip) self.label_icon.setToolTip(tooltip)
else: else:
@ -78,15 +79,14 @@ class VmTypeWidget(VmIconWidget):
return False return False
elif self.value == other.value: elif self.value == other.value:
return self.vm.name < other.vm.name return self.vm.name < other.vm.name
else: return self.value < other.value
return self.value < other.value
def __init__(self, vm, parent=None): def __init__(self, vm, parent=None):
(icon_path, tooltip) = self.get_vm_icon(vm) (icon_path, tooltip) = self.get_vm_icon(vm)
super(VmTypeWidget, self).__init__( super(VmTypeWidget, self).__init__(
icon_path, True, 0.8, tooltip, parent) icon_path, True, 0.8, tooltip, parent)
self.vm = vm self.vm = vm
self.tableItem = self.VmTypeItem(self.value, vm) self.table_item = self.VmTypeItem(self.value, vm)
self.value = None self.value = None
# TODO: add "provides network" column # TODO: add "provides network" column
@ -126,14 +126,13 @@ class VmLabelWidget(VmIconWidget):
return False return False
elif self.value == other.value: elif self.value == other.value:
return self.vm.name < other.vm.name return self.vm.name < other.vm.name
else: return self.value < other.value
return self.value < other.value
def __init__(self, vm, parent=None): def __init__(self, vm, parent=None):
icon_path = self.get_vm_icon_path(vm) icon_path = self.get_vm_icon_path(vm)
super(VmLabelWidget, self).__init__(icon_path, True, 0.8, None, parent) super(VmLabelWidget, self).__init__(icon_path, True, 0.8, None, parent)
self.vm = vm self.vm = vm
self.tableItem = self.VmLabelItem(self.value, vm) self.table_item = self.VmLabelItem(self.value, vm)
self.value = None self.value = None
def get_vm_icon_path(self, vm): def get_vm_icon_path(self, vm):
@ -141,7 +140,7 @@ class VmLabelWidget(VmIconWidget):
return vm.label.icon return vm.label.icon
class VmNameItem (QtGui.QTableWidgetItem): class VmNameItem(QtGui.QTableWidgetItem):
def __init__(self, vm): def __init__(self, vm):
super(VmNameItem, self).__init__() super(VmNameItem, self).__init__()
self.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) self.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
@ -186,14 +185,15 @@ class VmStatusIcon(QtGui.QLabel):
self.setFixedSize(icon_sz) self.setFixedSize(icon_sz)
class VmInfoWidget (QtGui.QWidget): class VmInfoWidget(QtGui.QWidget):
class VmInfoItem (QtGui.QTableWidgetItem): class VmInfoItem(QtGui.QTableWidgetItem):
def __init__(self, upd_info_item, vm): def __init__(self, upd_info_item, vm):
super(VmInfoWidget.VmInfoItem, self).__init__() super(VmInfoWidget.VmInfoItem, self).__init__()
self.upd_info_item = upd_info_item self.upd_info_item = upd_info_item
self.vm = vm self.vm = vm
def __lt__(self, other): def __lt__(self, other):
# pylint: disable=too-many-return-statements
if self.vm.qid == 0: if self.vm.qid == 0:
return True return True
elif other.vm.qid == 0: elif other.vm.qid == 0:
@ -209,8 +209,7 @@ class VmInfoWidget (QtGui.QWidget):
other_val += 1 if other.vm.is_running() else 0 other_val += 1 if other.vm.is_running() else 0
if self_val == other_val: if self_val == other_val:
return self.vm.name < other.vm.name return self.vm.name < other.vm.name
else: return self_val > other_val
return self_val > other_val
elif self.tableWidget().\ elif self.tableWidget().\
horizontalHeader().sortIndicatorOrder() == power_order: horizontalHeader().sortIndicatorOrder() == power_order:
# the result will be sorted by power state, # the result will be sorted by power state,
@ -221,8 +220,7 @@ class VmInfoWidget (QtGui.QWidget):
10*(1 if other.vm.is_running() else 0)) 10*(1 if other.vm.is_running() else 0))
if self_val == other_val: if self_val == other_val:
return self.vm.name < other.vm.name return self.vm.name < other.vm.name
else: return self_val > other_val
return self_val > other_val
else: else:
# it would be strange if this happened # it would be strange if this happened
return return
@ -254,14 +252,14 @@ class VmInfoWidget (QtGui.QWidget):
self.blk_icon.setVisible(False) self.blk_icon.setVisible(False)
self.error_icon.setVisible(False) self.error_icon.setVisible(False)
self.tableItem = self.VmInfoItem(self.upd_info.tableItem, vm) self.table_item = self.VmInfoItem(self.upd_info.table_item, vm)
def update_vm_state(self, vm): def update_vm_state(self, vm):
self.on_icon.update() self.on_icon.update()
self.upd_info.update_outdated(vm) self.upd_info.update_outdated(vm)
class VmTemplateItem (QtGui.QTableWidgetItem): class VmTemplateItem(QtGui.QTableWidgetItem):
def __init__(self, vm): def __init__(self, vm):
super(VmTemplateItem, self).__init__() super(VmTemplateItem, self).__init__()
self.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) self.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
@ -286,11 +284,10 @@ class VmTemplateItem (QtGui.QTableWidgetItem):
return False return False
elif self.text() == other.text(): elif self.text() == other.text():
return self.vm.name < other.vm.name return self.vm.name < other.vm.name
else: return super(VmTemplateItem, self).__lt__(other)
return super(VmTemplateItem, self).__lt__(other)
class VmNetvmItem (QtGui.QTableWidgetItem): class VmNetvmItem(QtGui.QTableWidgetItem):
def __init__(self, vm): def __init__(self, vm):
super(VmNetvmItem, self).__init__() super(VmNetvmItem, self).__init__()
self.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) self.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
@ -310,8 +307,7 @@ class VmNetvmItem (QtGui.QTableWidgetItem):
return False return False
elif self.text() == other.text(): elif self.text() == other.text():
return self.vm.name < other.vm.name return self.vm.name < other.vm.name
else: return super(VmNetvmItem, self).__lt__(other)
return super(VmNetvmItem, self).__lt__(other)
class VmInternalItem(QtGui.QTableWidgetItem): class VmInternalItem(QtGui.QTableWidgetItem):
@ -335,7 +331,7 @@ class VmInternalItem(QtGui.QTableWidgetItem):
# features man qvm-features # features man qvm-features
class VmUpdateInfoWidget(QtGui.QWidget): class VmUpdateInfoWidget(QtGui.QWidget):
class VmUpdateInfoItem (QtGui.QTableWidgetItem): class VmUpdateInfoItem(QtGui.QTableWidgetItem):
def __init__(self, value, vm): def __init__(self, value, vm):
super(VmUpdateInfoWidget.VmUpdateInfoItem, self).__init__() super(VmUpdateInfoWidget.VmUpdateInfoItem, self).__init__()
self.value = 0 self.value = 0
@ -357,8 +353,7 @@ class VmUpdateInfoWidget(QtGui.QWidget):
return False return False
elif self.value == other.value: elif self.value == other.value:
return self.vm.name < other.vm.name return self.vm.name < other.vm.name
else: return self.value < other.value
return self.value < other.value
def __init__(self, vm, show_text=True, parent=None): def __init__(self, vm, show_text=True, parent=None):
super(VmUpdateInfoWidget, self).__init__(parent) super(VmUpdateInfoWidget, self).__init__(parent)
@ -375,7 +370,7 @@ class VmUpdateInfoWidget(QtGui.QWidget):
self.previous_outdated_state = None self.previous_outdated_state = None
self.previous_update_recommended = None self.previous_update_recommended = None
self.value = None self.value = None
self.tableItem = VmUpdateInfoWidget.VmUpdateInfoItem(self.value, vm) self.table_item = VmUpdateInfoWidget.VmUpdateInfoItem(self.value, vm)
def update_outdated(self, vm): def update_outdated(self, vm):
@ -403,7 +398,7 @@ class VmUpdateInfoWidget(QtGui.QWidget):
def update_status_widget(self, state): def update_status_widget(self, state):
self.value = state self.value = state
self.tableItem.set_value(state) self.table_item.set_value(state)
if state == "update": if state == "update":
label_text = "<font color=\"#CCCC00\">Check updates</font>" label_text = "<font color=\"#CCCC00\">Check updates</font>"
icon_path = ":/update-recommended.png" icon_path = ":/update-recommended.png"
@ -438,7 +433,7 @@ class VmUpdateInfoWidget(QtGui.QWidget):
self.layout().addWidget(self.icon, alignment=QtCore.Qt.AlignCenter) self.layout().addWidget(self.icon, alignment=QtCore.Qt.AlignCenter)
class VmSizeOnDiskItem (QtGui.QTableWidgetItem): class VmSizeOnDiskItem(QtGui.QTableWidgetItem):
def __init__(self, vm): def __init__(self, vm):
super(VmSizeOnDiskItem, self).__init__() super(VmSizeOnDiskItem, self).__init__()
self.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) self.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
@ -463,8 +458,7 @@ class VmSizeOnDiskItem (QtGui.QTableWidgetItem):
return False return False
elif self.value == other.value: elif self.value == other.value:
return self.vm.name < other.vm.name return self.vm.name < other.vm.name
else: return self.value < other.value
return self.value < other.value
class VmIPItem(QtGui.QTableWidgetItem): class VmIPItem(QtGui.QTableWidgetItem):
@ -502,8 +496,7 @@ class VmIncludeInBackupsItem(QtGui.QTableWidgetItem):
return False return False
elif self.vm.include_in_backups == other.vm.include_in_backups: elif self.vm.include_in_backups == other.vm.include_in_backups:
return self.vm.name < other.vm.name return self.vm.name < other.vm.name
else: return self.vm.include_in_backups < other.vm.include_in_backups
return self.vm.include_in_backups < other.vm.include_in_backups
class VmLastBackupItem(QtGui.QTableWidgetItem): class VmLastBackupItem(QtGui.QTableWidgetItem):
@ -528,5 +521,4 @@ class VmLastBackupItem(QtGui.QTableWidgetItem):
return False return False
elif not other.vm.backup_timestamp: elif not other.vm.backup_timestamp:
return True return True
else: return self.vm.backup_timestamp < other.vm.backup_timestamp
return self.vm.backup_timestamp < other.vm.backup_timestamp