From 5f1e4803fe1691989215962a30da8dd2a9783489 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marta=20Marczykowska-G=C3=B3recka?= Date: Fri, 17 Nov 2017 17:34:38 +0100 Subject: [PATCH] Applied corrections from @marmarek --- .travis.yml | 1 - qubesmanager/bootfromdevice.py | 7 +++--- qubesmanager/firewall.py | 25 +++++++++------------ qubesmanager/global_settings.py | 2 +- qubesmanager/settings.py | 3 ++- test-packages/qubesadmin/DEFAULT.py | 1 - test-packages/qubesadmin/__init__.py | 4 +++- test-packages/qubesadmin/devices.py | 2 +- test-packages/qubesadmin/exc.py | 2 +- test-packages/qubesadmin/firewall.py | 2 +- test-packages/qubesadmin/tools/qvm_start.py | 2 +- test-packages/qubesadmin/utils.py | 2 +- 12 files changed, 25 insertions(+), 28 deletions(-) delete mode 100644 test-packages/qubesadmin/DEFAULT.py diff --git a/.travis.yml b/.travis.yml index 49c5808..e868fbe 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,6 @@ language: python python: - '3.5' install: - - sudo apt-get install python-qt4 pyqt4-dev-tools - pip install --quiet -r ci/requirements.txt - git clone https://github.com/QubesOS/qubes-builder ~/qubes-builder script: diff --git a/qubesmanager/bootfromdevice.py b/qubesmanager/bootfromdevice.py index 975364e..ab54b98 100644 --- a/qubesmanager/bootfromdevice.py +++ b/qubesmanager/bootfromdevice.py @@ -20,10 +20,9 @@ import sys import subprocess from . import utils -from . import firewall from . import ui_bootfromdevice # pylint: disable=no-name-in-module from PyQt4 import QtGui, QtCore # pylint: disable=import-error -import qubesadmin.tools.qvm_start as qvm_start +from qubesadmin import tools class VMBootFromDeviceWindow(ui_bootfromdevice.Ui_BootDialog, QtGui.QDialog): @@ -63,7 +62,7 @@ class VMBootFromDeviceWindow(ui_bootfromdevice.Ui_BootDialog, QtGui.QDialog): self.tr("ERROR!"), self.tr("No file or block device selected; please select one.")) return - qvm_start.main(['--cdrom', cdrom_location, self.vm.name]) + tools.qvm_start.main(['--cdrom', cdrom_location, self.vm.name]) def __init_buttons__(self): self.fileVM.setEnabled(False) @@ -111,7 +110,7 @@ class VMBootFromDeviceWindow(ui_bootfromdevice.Ui_BootDialog, QtGui.QDialog): self.pathText.setText(new_path) -parser = firewall.qubesadmin.tools.QubesArgumentParser(vmname_nargs=1) +parser = tools.QubesArgumentParser(vmname_nargs=1) def main(args=None): args = parser.parse_args(args) diff --git a/qubesmanager/firewall.py b/qubesmanager/firewall.py index 88ef311..d8a3d1c 100644 --- a/qubesmanager/firewall.py +++ b/qubesmanager/firewall.py @@ -148,14 +148,13 @@ class QubesFirewallRulesModel(QtCore.QAbstractItemModel): r"(?P[a-z][a-z0-9-]+)\s+(?P[0-9]+)/" r"(?P[a-z]+)", re.IGNORECASE) - file = open('/etc/services', 'r') - for line in file: - match = pattern.match(line) - if match is not None: - service = match.groupdict() - self.__services.append( - (service["name"], int(service["port"]),)) - file.close() + with open('/etc/services', 'r') as file: + for line in file: + match = pattern.match(line) + if match is not None: + service = match.groupdict() + self.__services.append( + (service["name"], int(service["port"]),)) self.fw_changed = False self.allow = None # is the default policy allow or deny @@ -165,8 +164,8 @@ class QubesFirewallRulesModel(QtCore.QAbstractItemModel): def sort(self, idx, order): rev = (order == QtCore.Qt.AscendingOrder) - self.children.sort(key=lambda x: self.get_column_string(idx, x) - , reverse=rev) + self.children.sort(key=lambda x: self.get_column_string(idx, x), + reverse=rev) index1 = self.createIndex(0, 0) index2 = self.createIndex(len(self) - 1, len(self.__column_names) - 1) @@ -388,7 +387,7 @@ class QubesFirewallRulesModel(QtCore.QAbstractItemModel): self.tr("Invalid port or service"), self.tr("Port number or service '{0}' is invalid.") .format(service)) - elif service is not None and service != "": + elif service: try: rule.dstports = service except (TypeError, ValueError): @@ -425,9 +424,7 @@ class QubesFirewallRulesModel(QtCore.QAbstractItemModel): # pylint: disable=invalid-name,no-self-use def hasChildren(self, index=QtCore.QModelIndex()): parent_item = index.internalPointer() - if parent_item is not None: - return False - return True + return parent_item is None def data(self, index, role=QtCore.Qt.DisplayRole): if index.isValid() and role == QtCore.Qt.DisplayRole: diff --git a/qubesmanager/global_settings.py b/qubesmanager/global_settings.py index 0526546..c779326 100644 --- a/qubesmanager/global_settings.py +++ b/qubesmanager/global_settings.py @@ -158,7 +158,7 @@ class GlobalSettingsWindow(ui_globalsettingsdlg.Ui_GlobalSettings, def __init_kernel_defaults__(self): kernel_list = [] # TODO system_path["qubes_kernels_base_dir"] - # idea: qubes.pulls['linux-kernel'].volumes + # idea: qubes.pools['linux-kernel'].volumes for k in os.listdir('/var/lib/qubes/vm-kernels'): kernel_list.append(k) diff --git a/qubesmanager/settings.py b/qubesmanager/settings.py index 6fb75f2..fa1305b 100755 --- a/qubesmanager/settings.py +++ b/qubesmanager/settings.py @@ -31,6 +31,7 @@ import traceback import os import sys from qubesadmin.tools import QubesArgumentParser +from qubesadmin import devices import qubesadmin.exc from . import utils @@ -665,7 +666,7 @@ class VMSettingsWindow(ui_settingsdlg.Ui_SettingsDialog, QtGui.QDialog): for i in range(self.dev_list.selected_list.count())] for ident in new: if ident not in old: - ass = firewall.qubesadmin.devices.DeviceAssignment( + ass = devices.DeviceAssignment( self.vm.app.domains['dom0'], ident.replace(':', '_'), persistent=True) diff --git a/test-packages/qubesadmin/DEFAULT.py b/test-packages/qubesadmin/DEFAULT.py deleted file mode 100644 index c3b69bd..0000000 --- a/test-packages/qubesadmin/DEFAULT.py +++ /dev/null @@ -1 +0,0 @@ -### mock qubesadmin.DEFAULT module \ No newline at end of file diff --git a/test-packages/qubesadmin/__init__.py b/test-packages/qubesadmin/__init__.py index d9c1b4d..1801453 100644 --- a/test-packages/qubesadmin/__init__.py +++ b/test-packages/qubesadmin/__init__.py @@ -1,2 +1,4 @@ class Qubes(object): - pass \ No newline at end of file + pass + +DEFAULT = object() diff --git a/test-packages/qubesadmin/devices.py b/test-packages/qubesadmin/devices.py index e31e5c3..be5de38 100644 --- a/test-packages/qubesadmin/devices.py +++ b/test-packages/qubesadmin/devices.py @@ -1,4 +1,4 @@ ### mock qubesadmin.devices module class DeviceAssignment(object): - pass \ No newline at end of file + pass diff --git a/test-packages/qubesadmin/exc.py b/test-packages/qubesadmin/exc.py index 78835e2..087af2a 100644 --- a/test-packages/qubesadmin/exc.py +++ b/test-packages/qubesadmin/exc.py @@ -1,4 +1,4 @@ ### mock qubesadmin.exc module class QubesException(BaseException): - pass \ No newline at end of file + pass diff --git a/test-packages/qubesadmin/firewall.py b/test-packages/qubesadmin/firewall.py index 07a5151..e83c19f 100644 --- a/test-packages/qubesadmin/firewall.py +++ b/test-packages/qubesadmin/firewall.py @@ -1,4 +1,4 @@ ### mock qubesadmin.firewall module class Rule(object): - pass \ No newline at end of file + pass diff --git a/test-packages/qubesadmin/tools/qvm_start.py b/test-packages/qubesadmin/tools/qvm_start.py index 4385323..f04be20 100644 --- a/test-packages/qubesadmin/tools/qvm_start.py +++ b/test-packages/qubesadmin/tools/qvm_start.py @@ -1,4 +1,4 @@ ### mock qvm_start module def main(*args, **kwargs): - pass \ No newline at end of file + pass diff --git a/test-packages/qubesadmin/utils.py b/test-packages/qubesadmin/utils.py index bcf4711..afb7725 100644 --- a/test-packages/qubesadmin/utils.py +++ b/test-packages/qubesadmin/utils.py @@ -4,4 +4,4 @@ def parse_size(*args, **kwargs): return args[0] def updates_vms_status(*args, **kwargs): - return args[0] \ No newline at end of file + return args[0]