From 689dd64b0d406e1c8e1159edf07c9f1023bbf0c2 Mon Sep 17 00:00:00 2001 From: Wojtek Porczyk Date: Tue, 29 Dec 2015 22:04:00 +0100 Subject: [PATCH] qubes: misc pylint fixes --- qubes/tests/int/tools/qubes_create.py | 3 ++- qubes/tests/int/tools/qvm_run.py | 7 ++++--- qubes/tests/vm/qubesvm.py | 6 +++--- qubes/tools/__init__.py | 3 ++- qubes/tools/qubes_prefs.py | 2 -- qubes/tools/qvm_prefs.py | 2 -- qubes/tools/qvm_run.py | 11 ----------- qubes/vm/qubesvm.py | 14 +++++++------- 8 files changed, 18 insertions(+), 30 deletions(-) diff --git a/qubes/tests/int/tools/qubes_create.py b/qubes/tests/int/tools/qubes_create.py index 5d57b53a..c03e6454 100644 --- a/qubes/tests/int/tools/qubes_create.py +++ b/qubes/tests/int/tools/qubes_create.py @@ -29,7 +29,8 @@ import qubes.tools.qubes_create import qubes.tests @qubes.tests.skipUnlessDom0 -class TC_00_qubes_create(qubes.tests.SystemTestsMixin, qubes.tests.QubesTestCase): +class TC_00_qubes_create( + qubes.tests.SystemTestsMixin, qubes.tests.QubesTestCase): def test_000_basic(self): self.assertEqual(0, qubes.tools.qubes_create.main(( '--qubesxml', qubes.tests.XMLPATH))) diff --git a/qubes/tests/int/tools/qvm_run.py b/qubes/tests/int/tools/qvm_run.py index d75e8242..727731cd 100644 --- a/qubes/tests/int/tools/qvm_run.py +++ b/qubes/tests/int/tools/qvm_run.py @@ -132,9 +132,10 @@ class TC_00_qvm_run(qubes.tests.SystemTestsMixin, qubes.tests.QubesTestCase): self.sharedopts + ['--filter-escape-chars', self.vm1.name, r'printf \\033'])) - @unittest.skip('test not implemented') - def test_007_gui(self): - raise NotImplementedError() + + def test_007_gui(self): # pylint: disable=no-self-use + raise unittest.SkipTest('test not implemented') + #parser.add_argument('--gui', #parser.add_argument('--no-gui', '--nogui', diff --git a/qubes/tests/vm/qubesvm.py b/qubes/tests/vm/qubesvm.py index 2fa906a6..881fb0f9 100644 --- a/qubes/tests/vm/qubesvm.py +++ b/qubes/tests/vm/qubesvm.py @@ -116,7 +116,7 @@ class TC_90_QubesVM(qubes.tests.QubesTestCase): self.app = qubes.tests.vm.TestApp() def test_000_init(self): - vm = qubes.vm.qubesvm.QubesVM(self.app, None, + qubes.vm.qubesvm.QubesVM(self.app, None, qid=1, name=qubes.tests.VMPREFIX + 'test') def test_001_init_no_qid_or_name(self): @@ -131,8 +131,8 @@ class TC_90_QubesVM(qubes.tests.QubesTestCase): class TestVM2(qubes.vm.qubesvm.QubesVM): event_fired = False @qubes.events.handler('domain-init') - def on_domain_init(self, event): + def on_domain_init(self, event): # pylint: disable=unused-argument self.__class__.event_fired = True - vm = TestVM2(self.app, None, qid=1, name=qubes.tests.VMPREFIX + 'test') + TestVM2(self.app, None, qid=1, name=qubes.tests.VMPREFIX + 'test') self.assertTrue(TestVM2.event_fired) diff --git a/qubes/tools/__init__.py b/qubes/tools/__init__.py index 597a3f4d..c177fc77 100644 --- a/qubes/tools/__init__.py +++ b/qubes/tools/__init__.py @@ -29,6 +29,7 @@ import argparse import importlib import logging import os +import textwrap import qubes.log @@ -107,7 +108,7 @@ class HelpPropertiesAction(argparse.Action): help=help) # late import because of circular dependency - import qubes + import qubes # pylint: disable=redefined-outer-name self._klass = klass if klass is not None else qubes.Qubes diff --git a/qubes/tools/qubes_prefs.py b/qubes/tools/qubes_prefs.py index 649e050f..7228ba58 100644 --- a/qubes/tools/qubes_prefs.py +++ b/qubes/tools/qubes_prefs.py @@ -26,9 +26,7 @@ from __future__ import print_function -import argparse import sys -import textwrap import qubes import qubes.tools diff --git a/qubes/tools/qvm_prefs.py b/qubes/tools/qvm_prefs.py index 92b649bd..e1e9255f 100644 --- a/qubes/tools/qvm_prefs.py +++ b/qubes/tools/qvm_prefs.py @@ -26,9 +26,7 @@ from __future__ import print_function -import argparse import sys -import textwrap import qubes import qubes.tools diff --git a/qubes/tools/qvm_run.py b/qubes/tools/qvm_run.py index 92579337..f42d246f 100644 --- a/qubes/tools/qvm_run.py +++ b/qubes/tools/qvm_run.py @@ -78,17 +78,6 @@ parser.add_argument('--no-filter-escape-chars', parser.add_argument('cmd', metavar='COMMAND', help='command to run') -# -# parser.add_option ("-q", "--quiet", action="store_false", dest="verbose", default=True) -# parser.add_option ("--tray", action="store_true", dest="tray", default=False, -# help="Use tray notifications instead of stdout" ) -# parser.add_option ("--pause", action="store_true", dest="pause", default=False, -# help="Do 'xl pause' for the VM(s) (can be combined this with --all)") -# parser.add_option ("--unpause", action="store_true", dest="unpause", default=False, -# help="Do 'xl unpause' for the VM(s) (can be combined this with --all)") -# parser.add_option ("--nogui", action="store_false", dest="gui", default=True, -# help="Run command without gui") -## def main(args=None): args = parser.parse_args(args) diff --git a/qubes/vm/qubesvm.py b/qubes/vm/qubesvm.py index 99259fa8..70be7495 100644 --- a/qubes/vm/qubesvm.py +++ b/qubes/vm/qubesvm.py @@ -664,9 +664,9 @@ class QubesVM(qubes.vm.BaseVM): ['sudo', qubes.config.system_path['qubes_pciback_cmd'], pci]) subprocess.check_call( ['sudo', 'xl', 'pci-attach', str(self.xid), pci]) - except Exception as e: - print >>sys.stderr, "Failed to attach PCI device on the fly " \ - "(%s), changes will be seen after VM restart" % str(e) + except subprocess.CalledProcessError as e: + self.log.exception('Failed to attach PCI device {!r} on the fly,' + ' changes will be seen after VM restart.'.format(pci), e) @qubes.events.handler('device-pre-detached:pci') @@ -690,9 +690,9 @@ class QubesVM(qubes.vm.BaseVM): user="root", input="00:%s" % vmdev) subprocess.check_call( ['sudo', 'xl', 'pci-detach', str(self.xid), pci]) - except Exception as e: - print >>sys.stderr, "Failed to detach PCI device on the fly " \ - "(%s), changes will be seen after VM restart" % str(e) + except subprocess.CalledProcessError as e: + self.log.exception('Failed to detach PCI device {!r} on the fly,' + ' changes will be seen after VM restart.'.format(pci), e) # @@ -936,7 +936,7 @@ class QubesVM(qubes.vm.BaseVM): call_kwargs = {} if ignore_stderr or not passio: - null = open("/dev/null", "rw") + null = open("/dev/null", "r+") call_kwargs['stderr'] = null if not passio: call_kwargs['stdin'] = null