Final corrections

Errors that my local pylint ignored and travis' pylint didn't.
This commit is contained in:
Marta Marczykowska-Górecka 2017-11-14 15:29:57 +01:00
parent c708830af2
commit 135060dfe7
No known key found for this signature in database
GPG Key ID: 9A752C30B26FD04B
10 changed files with 38 additions and 49 deletions

View File

@ -32,6 +32,7 @@ disable=
logging-format-interpolation, logging-format-interpolation,
missing-docstring, missing-docstring,
star-args, star-args,
useless-super-delegation,
wrong-import-order wrong-import-order
[REPORTS] [REPORTS]

View File

@ -21,7 +21,7 @@
import subprocess import subprocess
import PyQt4.QtGui import PyQt4.QtGui # pylint: disable=import-error
# TODO description in tooltip # TODO description in tooltip
# TODO icon # TODO icon

View File

@ -21,8 +21,8 @@ import sys
import subprocess import subprocess
from . import utils from . import utils
from . import firewall from . import firewall
from . import ui_bootfromdevice from . import ui_bootfromdevice # pylint: disable=no-name-in-module
from PyQt4 import QtGui, QtCore from PyQt4 import QtGui, QtCore # pylint: disable=import-error
import qubesadmin.tools.qvm_start as qvm_start import qubesadmin.tools.qvm_start as qvm_start

View File

@ -26,7 +26,7 @@ import threading
import time import time
import subprocess import subprocess
from PyQt4 import QtCore, QtGui from PyQt4 import QtCore, QtGui # pylint: disable=import-error
import qubesadmin import qubesadmin
import qubesadmin.tools import qubesadmin.tools
@ -34,7 +34,7 @@ import qubesadmin.exc
from . import utils from . import utils
from .ui_newappvmdlg import Ui_NewVMDlg from .ui_newappvmdlg import Ui_NewVMDlg # pylint: disable=import-error
from .thread_monitor import ThreadMonitor from .thread_monitor import ThreadMonitor
@ -75,7 +75,7 @@ class NewVmDlg(QtGui.QDialog, Ui_NewVMDlg):
self.name.selectAll() self.name.selectAll()
self.name.setFocus() self.name.setFocus()
if len(self.template_list) == 0: if not self.template_list:
QtGui.QMessageBox.warning(None, QtGui.QMessageBox.warning(None,
self.tr('No template available!'), self.tr('No template available!'),
self.tr('Cannot create a qube when no template exists.')) self.tr('Cannot create a qube when no template exists.'))

View File

@ -21,16 +21,17 @@
import datetime import datetime
import re import re
from PyQt4 import QtCore, QtGui from PyQt4 import QtCore, QtGui # pylint: disable=import-error
import qubesadmin.firewall import qubesadmin.firewall
from . import ui_newfwruledlg from . import ui_newfwruledlg # pylint: disable=no-name-in-module
class FirewallModifiedOutsideError(ValueError): class FirewallModifiedOutsideError(ValueError):
pass pass
class QIPAddressValidator(QtGui.QValidator): class QIPAddressValidator(QtGui.QValidator):
# pylint: disable=too-few-public-methods
def __init__(self, parent=None): def __init__(self, parent=None):
super(QIPAddressValidator, self).__init__(parent) super(QIPAddressValidator, self).__init__(parent)
@ -38,7 +39,7 @@ class QIPAddressValidator(QtGui.QValidator):
# pylint: disable=too-many-return-statements,no-self-use # pylint: disable=too-many-return-statements,no-self-use
hostname = str(input_string) hostname = str(input_string)
if len(hostname) > 255 or len(hostname) == 0: if len(hostname) > 255 or not hostname:
return (QtGui.QValidator.Intermediate, input_string, pos) return (QtGui.QValidator.Intermediate, input_string, pos)
if hostname == "*": if hostname == "*":
@ -89,7 +90,7 @@ class NewFwRuleDlg(QtGui.QDialog, ui_newfwruledlg.Ui_NewFwRuleDlg):
def accept(self): def accept(self):
if self.tcp_radio.isChecked() or self.udp_radio.isChecked(): if self.tcp_radio.isChecked() or self.udp_radio.isChecked():
if len(self.serviceComboBox.currentText()) == 0: if not self.serviceComboBox.currentText():
msg = QtGui.QMessageBox() msg = QtGui.QMessageBox()
msg.warning(self, self.tr("Firewall rule"), msg.warning(self, self.tr("Firewall rule"),
self.tr("You need to fill service " self.tr("You need to fill service "
@ -163,8 +164,6 @@ class QubesFirewallRulesModel(QtCore.QAbstractItemModel):
self.__children = None # list of rules in the FW self.__children = None # list of rules in the FW
def sort(self, idx, order): def sort(self, idx, order):
from operator import attrgetter
rev = (order == QtCore.Qt.AscendingOrder) rev = (order == QtCore.Qt.AscendingOrder)
self.children.sort(key=lambda x: self.get_column_string(idx, x) self.children.sort(key=lambda x: self.get_column_string(idx, x)
, reverse=rev) , reverse=rev)
@ -192,30 +191,24 @@ class QubesFirewallRulesModel(QtCore.QAbstractItemModel):
if col == 0: if col == 0:
if rule.dsthost is None: if rule.dsthost is None:
return "*" return "*"
else: if rule.dsthost.type == 'dst4' and rule.dsthost.prefixlen == '32':
if rule.dsthost.type == 'dst4'\
and rule.dsthost.prefixlen == '32':
return str(rule.dsthost)[:-3] return str(rule.dsthost)[:-3]
elif rule.dsthost.type == 'dst6'\ if rule.dsthost.type == 'dst6' and rule.dsthost.prefixlen == '128':
and rule.dsthost.prefixlen == '128':
return str(rule.dsthost)[:-4] return str(rule.dsthost)[:-4]
else:
return str(rule.dsthost) return str(rule.dsthost)
# Service # Service
if col == 1: if col == 1:
if rule.dstports is None: if rule.dstports is None:
return "any" return "any"
elif rule.dstports.range[0] != rule.dstports.range[1]: if rule.dstports.range[0] != rule.dstports.range[1]:
return str(rule.dstports) return str(rule.dstports)
else:
return self.get_service_name(rule.dstports) return self.get_service_name(rule.dstports)
# Protocol # Protocol
if col == 2: if col == 2:
if rule.proto is None: if rule.proto is None:
return "any" return "any"
else:
return str(rule.proto) return str(rule.proto)
return "unknown" return "unknown"
@ -434,7 +427,6 @@ class QubesFirewallRulesModel(QtCore.QAbstractItemModel):
parent_item = index.internalPointer() parent_item = index.internalPointer()
if parent_item is not None: if parent_item is not None:
return False return False
else:
return True return True
def data(self, index, role=QtCore.Qt.DisplayRole): def data(self, index, role=QtCore.Qt.DisplayRole):
@ -484,4 +476,3 @@ class QubesFirewallRulesModel(QtCore.QAbstractItemModel):
def __len__(self): def __len__(self):
return len(self.children) return len(self.children)

View File

@ -24,12 +24,12 @@ import sys
import os import os
import os.path import os.path
import traceback import traceback
from PyQt4 import QtCore, QtGui from PyQt4 import QtCore, QtGui # pylint: disable=import-error
from qubesadmin import Qubes from qubesadmin import Qubes
from qubesadmin.utils import parse_size, updates_vms_status from qubesadmin.utils import parse_size, updates_vms_status
from . import ui_globalsettingsdlg from . import ui_globalsettingsdlg # pylint: disable=no-name-in-module
from configparser import ConfigParser from configparser import ConfigParser
@ -181,7 +181,6 @@ class GlobalSettingsWindow(ui_globalsettingsdlg.Ui_GlobalSettings,
def __init_mem_defaults__(self): def __init_mem_defaults__(self):
# pylint: disable=redefined-variable-type
#qmemman settings #qmemman settings
self.qmemman_config = ConfigParser() self.qmemman_config = ConfigParser()
self.vm_min_mem_val = '200MiB' #str(qmemman_algo.MIN_PREFMEM) self.vm_min_mem_val = '200MiB' #str(qmemman_algo.MIN_PREFMEM)

View File

@ -1,5 +1,5 @@
from PyQt4 import QtCore, QtGui from PyQt4 import QtCore, QtGui # pylint: disable=import-error
from . import ui_multiselectwidget from . import ui_multiselectwidget # pylint: disable=no-name-in-module
class MultiSelectWidget( class MultiSelectWidget(
ui_multiselectwidget.Ui_MultiSelectWidget, QtGui.QWidget): ui_multiselectwidget.Ui_MultiSelectWidget, QtGui.QWidget):
@ -65,4 +65,3 @@ class MultiSelectWidget(
def clear(self): def clear(self):
self.available_list.clear() self.available_list.clear()
self.selected_list.clear() self.selected_list.clear()

View File

@ -39,9 +39,9 @@ from . import thread_monitor
from .appmenu_select import AppmenuSelectManager from .appmenu_select import AppmenuSelectManager
from . import firewall from . import firewall
from PyQt4 import QtCore, QtGui from PyQt4 import QtCore, QtGui # pylint: disable=import-error
from . import ui_settingsdlg from . import ui_settingsdlg #pylint: disable=no-name-in-module
# pylint: disable=too-many-instance-attributes # pylint: disable=too-many-instance-attributes
class VMSettingsWindow(ui_settingsdlg.Ui_SettingsDialog, QtGui.QDialog): class VMSettingsWindow(ui_settingsdlg.Ui_SettingsDialog, QtGui.QDialog):
@ -177,16 +177,16 @@ class VMSettingsWindow(ui_settingsdlg.Ui_SettingsDialog, QtGui.QDialog):
ret = [] ret = []
try: try:
ret_tmp = self.__apply_basic_tab__() ret_tmp = self.__apply_basic_tab__()
if len(ret_tmp) > 0: if ret_tmp:
ret += ["Basic tab:"] + ret_tmp ret += ["Basic tab:"] + ret_tmp
ret_tmp = self.__apply_advanced_tab__() ret_tmp = self.__apply_advanced_tab__()
if len(ret_tmp) > 0: if ret_tmp:
ret += ["Advanced tab:"] + ret_tmp ret += ["Advanced tab:"] + ret_tmp
ret_tmp = self.__apply_devices_tab__() ret_tmp = self.__apply_devices_tab__()
if len(ret_tmp) > 0: if ret_tmp:
ret += ["Devices tab:"] + ret_tmp ret += ["Devices tab:"] + ret_tmp
ret_tmp = self.__apply_services_tab__() ret_tmp = self.__apply_services_tab__()
if len(ret_tmp) > 0: if ret_tmp:
ret += ["Sevices tab:"] + ret_tmp ret += ["Sevices tab:"] + ret_tmp
except qubesadmin.exc.QubesException as qex: except qubesadmin.exc.QubesException as qex:
ret.append(self.tr('Error while saving changes: ') + str(qex)) ret.append(self.tr('Error while saving changes: ') + str(qex))
@ -212,7 +212,7 @@ class VMSettingsWindow(ui_settingsdlg.Ui_SettingsDialog, QtGui.QDialog):
except Exception as ex: # pylint: disable=broad-except except Exception as ex: # pylint: disable=broad-except
ret += [self.tr("Applications tab:"), repr(ex)] ret += [self.tr("Applications tab:"), repr(ex)]
if len(ret) > 0: if ret:
t_monitor.set_error_msg('\n'.join(ret)) t_monitor.set_error_msg('\n'.join(ret))
utils.debug('\n'.join(ret)) utils.debug('\n'.join(ret))
@ -899,7 +899,7 @@ class VMSettingsWindow(ui_settingsdlg.Ui_SettingsDialog, QtGui.QDialog):
selected = self.rulesTreeView.selectedIndexes() selected = self.rulesTreeView.selectedIndexes()
if len(selected) > 0: if selected:
dialog = firewall.NewFwRuleDlg() dialog = firewall.NewFwRuleDlg()
dialog.set_ok_state(True) dialog.set_ok_state(True)
row = self.rulesTreeView.selectedIndexes().pop().row() row = self.rulesTreeView.selectedIndexes().pop().row()
@ -923,7 +923,7 @@ def handle_exception(exc_type, exc_value, exc_traceback):
strace = "" strace = ""
stacktrace = traceback.extract_tb(exc_traceback) stacktrace = traceback.extract_tb(exc_traceback)
while len(stacktrace) > 0: while stacktrace:
(filename, line, func, txt) = stacktrace.pop() (filename, line, func, txt) = stacktrace.pop()
strace += "----\n" strace += "----\n"
strace += "line: %s\n" %txt strace += "line: %s\n" %txt

View File

@ -20,7 +20,7 @@
# #
import PyQt4.QtCore import PyQt4.QtCore # pylint: disable=import-error
import threading import threading
@ -40,4 +40,3 @@ class ThreadMonitor(PyQt4.QtCore.QObject):
def set_finished(self): def set_finished(self):
self.event_finished.set() self.event_finished.set()

View File

@ -24,7 +24,7 @@ import os
import re import re
import qubesadmin import qubesadmin
from PyQt4.QtGui import QIcon from PyQt4.QtGui import QIcon # pylint: disable=import-error
def _filter_internal(vm): def _filter_internal(vm):
return (not vm.klass == 'AdminVM' return (not vm.klass == 'AdminVM'
@ -65,7 +65,7 @@ def prepare_choice(widget, holder, propname, choice, default,
choice_list = filter(_filter_internal, choice_list) choice_list = filter(_filter_internal, choice_list)
if filter_function is not None: if filter_function is not None:
choice_list = filter(filter_function, choice_list) choice_list = filter(filter_function, choice_list)
choice_list = list(choice_list) # pylint: disable=redefined-variable-type choice_list = list(choice_list)
if allow_default: if allow_default:
choice_list.insert(0, qubesadmin.DEFAULT) choice_list.insert(0, qubesadmin.DEFAULT)
@ -154,7 +154,7 @@ def get_path_from_vm(vm, service_name):
untrusted_path = stdout.decode(encoding='ascii')[:path_max_len] untrusted_path = stdout.decode(encoding='ascii')[:path_max_len]
if len(untrusted_path) == 0: if not untrusted_path:
return None return None
if path_re.match(untrusted_path): if path_re.match(untrusted_path):
assert '../' not in untrusted_path assert '../' not in untrusted_path