From e4851f9b2c6eb227be67956cc4e90c6390617952 Mon Sep 17 00:00:00 2001 From: Bastian Stender Date: Wed, 30 May 2018 18:53:13 +0200 Subject: [PATCH 01/45] examples/strategy/test_barebox_strategy: fix missing import of NoDriverFoundError Signed-off-by: Bastian Stender --- examples/strategy/test_barebox_strategy.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/strategy/test_barebox_strategy.py b/examples/strategy/test_barebox_strategy.py index 600cbfee9..260344480 100644 --- a/examples/strategy/test_barebox_strategy.py +++ b/examples/strategy/test_barebox_strategy.py @@ -1,5 +1,7 @@ import pytest +from labgrid.exceptions import NoDriverFoundError + @pytest.fixture() def strategy(target): From 4bc04ad255c350250c65660656eb4018ff34533d Mon Sep 17 00:00:00 2001 From: Bastian Stender Date: Wed, 30 May 2018 18:53:56 +0200 Subject: [PATCH 02/45] examples/usbpower/test_example: fix missing import of NoDriverFoundError Signed-off-by: Bastian Stender --- examples/usbpower/test_example.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/usbpower/test_example.py b/examples/usbpower/test_example.py index 9ceb41690..443db89cc 100644 --- a/examples/usbpower/test_example.py +++ b/examples/usbpower/test_example.py @@ -1,5 +1,7 @@ import pytest +from labgrid.exceptions import NoDriverFoundError + @pytest.fixture() def strategy(target): From 6049f903f90e03f39da5ca3a09c8c4815723b992 Mon Sep 17 00:00:00 2001 From: Bastian Stender Date: Wed, 30 May 2018 18:54:48 +0200 Subject: [PATCH 03/45] driver/infodriver: fix missing import of ExecutionError Signed-off-by: Bastian Stender --- labgrid/driver/infodriver.py | 1 + 1 file changed, 1 insertion(+) diff --git a/labgrid/driver/infodriver.py b/labgrid/driver/infodriver.py index 4b9a0d6ca..10e16fdf3 100644 --- a/labgrid/driver/infodriver.py +++ b/labgrid/driver/infodriver.py @@ -7,6 +7,7 @@ from ..step import step from ..protocol import InfoProtocol, CommandProtocol from .common import Driver +from .exception import ExecutionError @target_factory.reg_driver @attr.s(cmp=False) From 328eb23e2cbe026a77b5f3bef253bcdbeef721d6 Mon Sep 17 00:00:00 2001 From: Bastian Stender Date: Wed, 30 May 2018 18:55:33 +0200 Subject: [PATCH 04/45] driver/usbsdmuxdriver: fix missing import of ExecutionError Signed-off-by: Bastian Stender --- labgrid/driver/usbsdmuxdriver.py | 1 + 1 file changed, 1 insertion(+) diff --git a/labgrid/driver/usbsdmuxdriver.py b/labgrid/driver/usbsdmuxdriver.py index 1bed9464d..984bfd3d4 100644 --- a/labgrid/driver/usbsdmuxdriver.py +++ b/labgrid/driver/usbsdmuxdriver.py @@ -7,6 +7,7 @@ from ..resource.remote import NetworkUSBSDMuxDevice from ..resource.udev import USBSDMuxDevice from ..step import step +from .exception import ExecutionError @target_factory.reg_driver @attr.s(cmp=False) From dfaebccfd1405bb65eae9501f303c282096e769f Mon Sep 17 00:00:00 2001 From: Bastian Stender Date: Wed, 30 May 2018 18:56:15 +0200 Subject: [PATCH 05/45] driver/usbstorage: fix missing import of time() from time Signed-off-by: Bastian Stender --- labgrid/driver/usbstorage.py | 1 + 1 file changed, 1 insertion(+) diff --git a/labgrid/driver/usbstorage.py b/labgrid/driver/usbstorage.py index 7667da317..72505e017 100644 --- a/labgrid/driver/usbstorage.py +++ b/labgrid/driver/usbstorage.py @@ -1,6 +1,7 @@ # pylint: disable=no-member import attr import os +from time import time from ..factory import target_factory from ..protocol import BootstrapProtocol From 822b51d81b48e9d7335f5908c00c119d7ed2d0cc Mon Sep 17 00:00:00 2001 From: Bastian Stender Date: Tue, 29 May 2018 19:48:54 +0200 Subject: [PATCH 06/45] resources/udev: remove already defined control_path The attr property is a duplicate of the property method with the same name. As this property is not intended to be given to the init method, remove it. Signed-off-by: Bastian Stender --- labgrid/resource/udev.py | 1 - 1 file changed, 1 deletion(-) diff --git a/labgrid/resource/udev.py b/labgrid/resource/udev.py index 333f08bc0..0a63d8db2 100644 --- a/labgrid/resource/udev.py +++ b/labgrid/resource/udev.py @@ -266,7 +266,6 @@ class USBSDMuxDevice(USBResource): """The USBSDMuxDevice describes an attached USBSDMux device, it is identified via USB using udev """ - control_path = attr.ib(default=None) def __attrs_post_init__(self): self.match['ID_VENDOR_ID'] = '0424' self.match['ID_MODEL_ID'] = '4041' From 7ade3bd7eec66302d32bbf9259e46a7ba9cfd778 Mon Sep 17 00:00:00 2001 From: Bastian Stender Date: Wed, 30 May 2018 13:46:49 +0200 Subject: [PATCH 07/45] resource/ethernetport: rename vars to variables Prevent overwriting built-in function vars(). Signed-off-by: Bastian Stender --- labgrid/resource/ethernetport.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/labgrid/resource/ethernetport.py b/labgrid/resource/ethernetport.py index 2232f0fba..cd9fbaae5 100644 --- a/labgrid/resource/ethernetport.py +++ b/labgrid/resource/ethernetport.py @@ -53,7 +53,7 @@ def _get_ports(self): """ from pysnmp import hlapi - vars = [ + variables = [ (hlapi.ObjectType(hlapi.ObjectIdentity('IF-MIB', 'ifIndex')),'index'), (hlapi.ObjectType(hlapi.ObjectIdentity('IF-MIB', 'ifDescr')), 'descr'), (hlapi.ObjectType(hlapi.ObjectIdentity('IF-MIB', 'ifSpeed')), 'speed'), @@ -70,7 +70,7 @@ def _get_ports(self): hlapi.UdpTransportTarget((self.hostname, 161)), hlapi.ContextData(), 0, 20, - *[x[0] for x in vars], + *[x[0] for x in variables], lexicographicMode=False): if errorIndication: Exception("snmp error {}".format(errorIndication)) @@ -78,8 +78,7 @@ def _get_ports(self): Exception("snmp error {}".format(errorStatus)) else: port = {} - for (key, val), (base, label) in zip(varBindTable, vars): - index = key.getMibSymbol()[-1][0].prettyPrint() + for (key, val), (base, label) in zip(varBindTable, variables): val = val.prettyPrint() if label == 'status': val = val.strip("'") From 145e32bdec036feeb2f69a1c2e8e2abc14e7b595 Mon Sep 17 00:00:00 2001 From: Bastian Stender Date: Wed, 30 May 2018 13:55:42 +0200 Subject: [PATCH 08/45] resource/remote: remove duplicate class NetworkMXSUSBLoader Signed-off-by: Bastian Stender --- labgrid/resource/remote.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/labgrid/resource/remote.py b/labgrid/resource/remote.py index 639855065..ba99a67c6 100644 --- a/labgrid/resource/remote.py +++ b/labgrid/resource/remote.py @@ -128,12 +128,6 @@ def __attrs_post_init__(self): self.timeout = 10.0 super().__attrs_post_init__() -@target_factory.reg_resource -@attr.s(cmp=False) -class NetworkMXSUSBLoader(RemoteUSBResource): - def __attrs_post_init__(self): - self.timeout = 10.0 - super().__attrs_post_init__() @target_factory.reg_resource @attr.s(cmp=False) From 1efbcd8f13ad04078469009d95f8d361de312cd6 Mon Sep 17 00:00:00 2001 From: Bastian Stender Date: Wed, 30 May 2018 13:59:10 +0200 Subject: [PATCH 09/45] binding: target: remove unused "name" arg from on_supplier_bound Signed-off-by: Bastian Stender --- labgrid/binding.py | 2 +- labgrid/target.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/labgrid/binding.py b/labgrid/binding.py index 7b4606735..2cccee24c 100644 --- a/labgrid/binding.py +++ b/labgrid/binding.py @@ -66,7 +66,7 @@ def display_name(self): self.__class__.__name__, self.target.name ) - def on_supplier_bound(self, supplier, name): + def on_supplier_bound(self, supplier): """Called by the Target after a new supplier has been bound""" pass diff --git a/labgrid/target.py b/labgrid/target.py index ac165a5e4..35e96060c 100644 --- a/labgrid/target.py +++ b/labgrid/target.py @@ -370,7 +370,7 @@ def bind_driver(self, client): for supplier in bound_suppliers: supplier.clients.add(client) client.suppliers.add(supplier) - client.on_supplier_bound(supplier, name) + client.on_supplier_bound(supplier) supplier.on_client_bound(client) client.state = BindingState.bound From 73a940ece0dc61e8ef0384bce3a91c9d2cde7d98 Mon Sep 17 00:00:00 2001 From: Bastian Stender Date: Wed, 30 May 2018 14:01:36 +0200 Subject: [PATCH 10/45] target: enforce string arg in _class_from_string Signed-off-by: Bastian Stender --- labgrid/target.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/labgrid/target.py b/labgrid/target.py index 35e96060c..660073f35 100644 --- a/labgrid/target.py +++ b/labgrid/target.py @@ -450,9 +450,8 @@ def cleanup(self): for res in reversed(self.resources): self.deactivate(res) - def _class_from_string(self, string): - if type(string) is str: - try: - return self._lookup_table[string] - except KeyError: - raise KeyError("No such driver/resource/protocol in lookup table, perhaps not bound?") + def _class_from_string(self, string: str): + try: + return self._lookup_table[string] + except KeyError: + raise KeyError("No such driver/resource/protocol in lookup table, perhaps not bound?") From 5113bf65190115a8b22b8f6d52301210870c4975 Mon Sep 17 00:00:00 2001 From: Bastian Stender Date: Wed, 30 May 2018 15:25:58 +0200 Subject: [PATCH 11/45] step: fix _invalidate() by setting resource to None This was propably a copy/paste error. Signed-off-by: Bastian Stender --- labgrid/step.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/labgrid/step.py b/labgrid/step.py index f0d69ac15..95db007c5 100644 --- a/labgrid/step.py +++ b/labgrid/step.py @@ -67,7 +67,7 @@ def _invalidate(self): self.ts = None self.step = None self.data = None - self.resource = resource + self.resource = None self.stream = None def merge(self, other): From 194c3ef1a35e880727a3f8e3de7bbfe29dfb0df8 Mon Sep 17 00:00:00 2001 From: Bastian Stender Date: Wed, 30 May 2018 11:32:36 +0200 Subject: [PATCH 12/45] external/hawkbit: fix typo: HawkbiError -> HawkbitError Signed-off-by: Bastian Stender --- labgrid/external/hawkbit.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/labgrid/external/hawkbit.py b/labgrid/external/hawkbit.py index 625e20211..48415a6f1 100644 --- a/labgrid/external/hawkbit.py +++ b/labgrid/external/hawkbit.py @@ -134,7 +134,7 @@ def post(self, endpoint: str): auth=(self.username, self.password), ) if req.status_code != 200 and req.status_code != 201: - raise HawkbiError( + raise HawkbitError( 'Wrong statuscode, got {} instead of 200/201'. format(req.status_code) ) @@ -150,7 +150,7 @@ def post_json(self, endpoint: str, data: dict): json=data ) if req.status_code != 200 and req.status_code != 201: - raise HawkbiError( + raise HawkbitError( 'Wrong statuscode, got {} instead of 200/201, with error {}'. format(req.status_code, req.json()) ) @@ -166,7 +166,7 @@ def post_binary(self, endpoint: str, filename: str): files=files ) if req.status_code != 201: - raise HawkbiError( + raise HawkbitError( 'Wrong statuscode, got {} instead of 201, with error {}'. format(req.status_code, req.json()) ) @@ -180,7 +180,7 @@ def delete(self, endpoint: str): auth=(self.username, self.password), ) if req.status_code != 200: - raise HawkbiError( + raise HawkbitError( 'Wrong statuscode, got {} instead of 200, with error {}'. format(req.status_code, req.json()) ) @@ -195,7 +195,7 @@ def get_endpoint(self, endpoint: str): auth=(self.username, self.password) ) if req.status_code != 200: - raise HawkbiError( + raise HawkbitError( 'Wrong statuscode, got {} instead of 200, with error {}'. format(req.status_code, req.json()) ) @@ -203,5 +203,5 @@ def get_endpoint(self, endpoint: str): @attr.s(cmp=False) -class HawkbiError(Exception): +class HawkbitError(Exception): msg = attr.ib() From 41c46d8c275b4867b71d7cdde7afd8b6b9e4297a Mon Sep 17 00:00:00 2001 From: Bastian Stender Date: Wed, 30 May 2018 15:53:17 +0200 Subject: [PATCH 13/45] autoinstall/main: handle not found target in run() Signed-off-by: Bastian Stender --- labgrid/autoinstall/main.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/labgrid/autoinstall/main.py b/labgrid/autoinstall/main.py index 0bc230c7f..e637f0d0f 100644 --- a/labgrid/autoinstall/main.py +++ b/labgrid/autoinstall/main.py @@ -71,6 +71,8 @@ def run(self): try: self.target = self.env.get_target(self.name) self.context['target'] = self.target + if self.target is None: + raise KeyError except: self.log.exception("target creation failed") return From d68786d942826cde2c314dfee0348dd3d359c98d Mon Sep 17 00:00:00 2001 From: Bastian Stender Date: Wed, 30 May 2018 16:07:25 +0200 Subject: [PATCH 14/45] remote/client: explicitly use nonlocal session in start_session subscope Signed-off-by: Bastian Stender --- labgrid/remote/client.py | 1 + 1 file changed, 1 insertion(+) diff --git a/labgrid/remote/client.py b/labgrid/remote/client.py index 648787eef..deac4bad1 100755 --- a/labgrid/remote/client.py +++ b/labgrid/remote/client.py @@ -930,6 +930,7 @@ def connected(session): session = [None] def create(): + nonlocal session cfg = ComponentConfig(realm, extra) session[0] = ClientSession(cfg) return session[0] From 97701a4a309e54e45cc2a839d0b695ee40e72989 Mon Sep 17 00:00:00 2001 From: Bastian Stender Date: Tue, 29 May 2018 19:22:59 +0200 Subject: [PATCH 15/45] remote/client: add missing argument to UserError string Signed-off-by: Bastian Stender --- labgrid/remote/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/labgrid/remote/client.py b/labgrid/remote/client.py index deac4bad1..bb9ea7c35 100755 --- a/labgrid/remote/client.py +++ b/labgrid/remote/client.py @@ -522,7 +522,7 @@ def allow(self): host, user = place.acquired.split('/') if user != getuser(): raise UserError( - "place {} is acquired by a different user ({})".format(place.name) + "place {} is acquired by a different user ({})".format(place.name, place.acquired) ) if not '/' in self.args.user: raise UserError( From 870c247e2f3e56e4713828d16e6f8991a0defc67 Mon Sep 17 00:00:00 2001 From: Bastian Stender Date: Thu, 31 May 2018 10:17:02 +0200 Subject: [PATCH 16/45] remote/client: rename env method to print_env This avoids name collision with the "env" attribute in the ClientSession class. Signed-off-by: Bastian Stender --- labgrid/remote/client.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/labgrid/remote/client.py b/labgrid/remote/client.py index bb9ea7c35..f9a0f8cb9 100755 --- a/labgrid/remote/client.py +++ b/labgrid/remote/client.py @@ -567,7 +567,7 @@ def get_target_config(self, place): resources.append({resource.cls: args}) return config - def env(self): + def print_env(self): place = self.get_acquired_place() env = {'targets': {place.name: self.get_target_config(place)}} print(dump(env)) @@ -1104,7 +1104,7 @@ def main(): subparser = subparsers.add_parser('env', help="generate a labgrid environment file for a place") - subparser.set_defaults(func=ClientSession.env) + subparser.set_defaults(func=ClientSession.print_env) subparser = subparsers.add_parser('power', aliases=('pw',), From e6bd6387858f0006000ca8444a552bd5546ba41c Mon Sep 17 00:00:00 2001 From: Bastian Stender Date: Thu, 31 May 2018 10:20:38 +0200 Subject: [PATCH 17/45] remote/client: rename monitor method to do_monitor This avoids name collision with the "monitor" attribute in the ClientSession class. Signed-off-by: Bastian Stender --- labgrid/remote/client.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/labgrid/remote/client.py b/labgrid/remote/client.py index f9a0f8cb9..06fc2e859 100755 --- a/labgrid/remote/client.py +++ b/labgrid/remote/client.py @@ -147,7 +147,7 @@ def on_place_changed(self, name, config): self.places[name] = place @asyncio.coroutine - def monitor(self): + def do_monitor(self): self.monitor = True while True: yield from asyncio.sleep(3600.0) @@ -1026,7 +1026,7 @@ def main(): subparser = subparsers.add_parser('monitor', help="monitor events from the coordinator") - subparser.set_defaults(func=ClientSession.monitor) + subparser.set_defaults(func=ClientSession.do_monitor) subparser = subparsers.add_parser('resources', aliases=('r',), help="list available resources") From ad9bc5a1213dd91bbe578d186600a1b9652d2409 Mon Sep 17 00:00:00 2001 From: Bastian Stender Date: Wed, 30 May 2018 16:56:15 +0200 Subject: [PATCH 18/45] remote/exporter: enable loop debugging when debug logging is enabled Signed-off-by: Bastian Stender --- labgrid/remote/exporter.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/labgrid/remote/exporter.py b/labgrid/remote/exporter.py index 34597fe02..7ef817a9d 100755 --- a/labgrid/remote/exporter.py +++ b/labgrid/remote/exporter.py @@ -529,7 +529,8 @@ def main(): print("resource config file: {}".format(extra['resources'])) extra['loop'] = loop = asyncio.get_event_loop() - #loop.set_debug(True) + if args.debug: + loop.set_debug(True) runner = ApplicationRunner(url=crossbar_url, realm=crossbar_realm, extra=extra) runner.run(ExporterSession, log_level=level) if reexec: From 0e915f0195ee62cf3983e7f1b8778cdfc210cbd2 Mon Sep 17 00:00:00 2001 From: Bastian Stender Date: Tue, 29 May 2018 14:44:03 +0200 Subject: [PATCH 19/45] driver/power: rename {get,set} to power_{get,set} This prevents overwriting of the built-in set() constructor. Signed-off-by: Bastian Stender --- labgrid/driver/power/apc.py | 4 ++-- labgrid/driver/power/digipower.py | 4 ++-- labgrid/driver/power/gude.py | 4 ++-- labgrid/driver/power/gude24.py | 4 ++-- labgrid/driver/power/netio.py | 5 ++--- labgrid/driver/power/netio_kshell.py | 4 ++-- labgrid/driver/power/simplerest.py | 4 ++-- labgrid/driver/powerdriver.py | 6 +++--- 8 files changed, 17 insertions(+), 18 deletions(-) diff --git a/labgrid/driver/power/apc.py b/labgrid/driver/power/apc.py index 3182e63d1..47b7eda46 100644 --- a/labgrid/driver/power/apc.py +++ b/labgrid/driver/power/apc.py @@ -28,7 +28,7 @@ def _snmp_set(host, oid, value): raise ExecutionError("failed to set SNMP value") from e -def set(host, index, value): +def power_set(host, index, value): index = int(index) value = 1 if value else 2 assert 1 <= index <= 8 @@ -36,7 +36,7 @@ def set(host, index, value): _snmp_set(host, "{}.{}".format(OID, index), "int {}".format(value)) -def get(host, index): +def power_get(host, index): index = int(index) assert 1 <= index <= 8 diff --git a/labgrid/driver/power/digipower.py b/labgrid/driver/power/digipower.py index 13ffbfcb7..9b7be252d 100644 --- a/labgrid/driver/power/digipower.py +++ b/labgrid/driver/power/digipower.py @@ -3,7 +3,7 @@ import requests -def set(host, index, value): +def power_set(host, index, value): index = int(index) assert 1 <= index <= 8 @@ -30,7 +30,7 @@ def set(host, index, value): r.raise_for_status() -def get(host, index): +def power_get(host, index): index = int(index) assert 1 <= index <= 8 diff --git a/labgrid/driver/power/gude.py b/labgrid/driver/power/gude.py index 842adc46c..accc683d6 100644 --- a/labgrid/driver/power/gude.py +++ b/labgrid/driver/power/gude.py @@ -5,7 +5,7 @@ import requests -def set(host, index, value): +def power_set(host, index, value): index = int(index) assert 1 <= index <= 8 # access the web interface... @@ -16,7 +16,7 @@ def set(host, index, value): r.raise_for_status() -def get(host, index): +def power_get(host, index): index = int(index) assert 1 <= index <= 8 # get the contents of the main page diff --git a/labgrid/driver/power/gude24.py b/labgrid/driver/power/gude24.py index 0ada5a414..1d521a731 100644 --- a/labgrid/driver/power/gude24.py +++ b/labgrid/driver/power/gude24.py @@ -12,7 +12,7 @@ # Driver has been tested with: # * Gude Expert Power Control 8080 -def set(host, index, value): +def power_set(host, index, value): # The gude web-interface uses different pages for the three groups of # switches. The web-interface always uses the 'correct' page to set a # value. But commands for all pages are accepted on all pages. @@ -26,7 +26,7 @@ def set(host, index, value): r.raise_for_status() -def get(host, index): +def power_get(host, index): # The status of the ports is made available via a html -tag using the # following format: # diff --git a/labgrid/driver/power/netio.py b/labgrid/driver/power/netio.py index 8d0dcd061..50cf1a640 100644 --- a/labgrid/driver/power/netio.py +++ b/labgrid/driver/power/netio.py @@ -1,10 +1,9 @@ import sys import re - import requests -def set(host, index, value): +def power_set(host, index, value): index = int(index) assert 1 <= index <= 4 # access the web interface... @@ -19,7 +18,7 @@ def set(host, index, value): r.raise_for_status() -def get(host, index): +def power_get(host, index): index = int(index) assert 1 <= index <= 4 # get the contents of the main page diff --git a/labgrid/driver/power/netio_kshell.py b/labgrid/driver/power/netio_kshell.py index a607d8c78..83f10f5e8 100644 --- a/labgrid/driver/power/netio_kshell.py +++ b/labgrid/driver/power/netio_kshell.py @@ -4,7 +4,7 @@ import telnetlib -def set(host, index, value): +def power_set(host, index, value): index = int(index) assert 1 <= index <= 4 value = "1" if value else "0" @@ -18,7 +18,7 @@ def set(host, index, value): tn.close() -def get(host, index): +def power_get(host, index): index = int(index) assert 1 <= index <= 4 tn = telnetlib.Telnet(host, 1234, 1) diff --git a/labgrid/driver/power/simplerest.py b/labgrid/driver/power/simplerest.py index 36be24e75..78cc2185f 100644 --- a/labgrid/driver/power/simplerest.py +++ b/labgrid/driver/power/simplerest.py @@ -12,12 +12,12 @@ import requests -def set(host, index, value): +def power_set(host, index, value): index = int(index) value = 1 if value else 0 r = requests.get(host.format(value=value,index=index)) -def get(host, index): +def power_get(host, index): index = int(index) # remove trailing / r = requests.get(host.format(value='',index=index).rstrip('/')) diff --git a/labgrid/driver/powerdriver.py b/labgrid/driver/powerdriver.py index e77515a3f..39e7304a0 100644 --- a/labgrid/driver/powerdriver.py +++ b/labgrid/driver/powerdriver.py @@ -114,12 +114,12 @@ def __attrs_post_init__(self): @Driver.check_active @step() def on(self): - self.backend.set(self.port.host, self.port.index, True) + self.backend.power_set(self.port.host, self.port.index, True) @Driver.check_active @step() def off(self): - self.backend.set(self.port.host, self.port.index, False) + self.backend.power_set(self.port.host, self.port.index, False) @Driver.check_active @step() @@ -130,7 +130,7 @@ def cycle(self): @Driver.check_active def get(self): - return self.backend.get(self.port.host, self.port.index) + return self.backend.power_get(self.port.host, self.port.index) @target_factory.reg_driver @attr.s(cmp=False) From a6631783f5003ac27ad680d1ee6241019ec5c42f Mon Sep 17 00:00:00 2001 From: Bastian Stender Date: Wed, 30 May 2018 13:18:45 +0200 Subject: [PATCH 20/45] driver/shelldriver: rename argument key to keyfile_path This prevents overriding the argument in loops lateron, because "key" is used as loop variable there. This also clarifies that the argument contains the path to the keyfile. Signed-off-by: Bastian Stender --- labgrid/driver/shelldriver.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/labgrid/driver/shelldriver.py b/labgrid/driver/shelldriver.py index f48805be7..de5ccc588 100644 --- a/labgrid/driver/shelldriver.py +++ b/labgrid/driver/shelldriver.py @@ -197,15 +197,15 @@ def _inject_run(self): ) self.console.expect(self.prompt) - @step(args=['key']) - def _put_ssh_key(self, key): + @step(args=['keyfile_path']) + def _put_ssh_key(self, keyfile_path): """Upload an SSH Key to a target""" regex = re.compile( r"""ssh-rsa # Only match RSA Keys \s+(?P[a-zA-Z0-9/+=]+) # Match Keystring \s+(?P.*) # Match comment""", re.X ) - with open(key) as keyfile: + with open(keyfile_path) as keyfile: keyline = keyfile.readline() self.logger.debug("Read Keyline: %s", keyline) match = regex.match(keyline) @@ -265,8 +265,8 @@ def _put_ssh_key(self, key): self.logger.warning("Could not bind mount ~/.ssh directory: %s %s", out, err) @Driver.check_active - def put_ssh_key(self, key): - self._put_ssh_key(key) + def put_ssh_key(self, keyfile_path): + self._put_ssh_key(keyfile_path) def _xmodem_getc(self, size, timeout=10): """ called by the xmodem.XMODEM instance to read protocol data from the console """ From 3db139d2e3edfd71953624e2caa3682170ef0e3e Mon Sep 17 00:00:00 2001 From: Bastian Stender Date: Wed, 30 May 2018 13:30:08 +0200 Subject: [PATCH 21/45] driver/sigrok: use already defined command string There is no need to use the list type constructor for "args". "args" is alreay a list. Signed-off-by: Bastian Stender --- labgrid/driver/sigrokdriver.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/labgrid/driver/sigrokdriver.py b/labgrid/driver/sigrokdriver.py index 0e7c53424..3b5c3e0c3 100644 --- a/labgrid/driver/sigrokdriver.py +++ b/labgrid/driver/sigrokdriver.py @@ -229,10 +229,8 @@ def analyze(self, args, filename=None): args.append("--protocol-decoder-samplenum") args.append("-l") args.append("4") - combined = self._get_sigrok_prefix() + list(args) - output = subprocess.check_output( - self._get_sigrok_prefix() + list(args), - ) + combined = self._get_sigrok_prefix() + args + output = subprocess.check_output(combined) return [ match.groupdict() for match in re.finditer(annotation_regex, output.decode("utf-8")) From bf2d0e204b6d1261eca19806d40719137cbfa260 Mon Sep 17 00:00:00 2001 From: Bastian Stender Date: Wed, 30 May 2018 11:09:23 +0200 Subject: [PATCH 22/45] driver/usbstorage: replace print with logging Signed-off-by: Bastian Stender --- labgrid/driver/usbstorage.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/labgrid/driver/usbstorage.py b/labgrid/driver/usbstorage.py index 72505e017..d1d716c69 100644 --- a/labgrid/driver/usbstorage.py +++ b/labgrid/driver/usbstorage.py @@ -1,4 +1,5 @@ # pylint: disable=no-member +import logging import attr import os from time import time @@ -18,6 +19,7 @@ class USBStorageDriver(Driver): def __attrs_post_init__(self): super().__attrs_post_init__() + self.logger = logging.getLogger("{}:{}".format(self, self.target)) def on_activate(self): pass @@ -45,7 +47,7 @@ def write_image(self, filename): count += len(data) if time() > stat: stat += 3 - print("writing image {:.0%}".format(count/size)) + self.logger.info("writing image %.0f%%", count*100/size) dst.flush() os.fsync(dst.fileno()) From 4b376a482bb4b670e1e167939e31ea246bd5536c Mon Sep 17 00:00:00 2001 From: Bastian Stender Date: Wed, 30 May 2018 16:09:48 +0200 Subject: [PATCH 23/45] driver/externalconsoledriver: log output of subprocess on close() This is useful for debugging. Signed-off-by: Bastian Stender --- labgrid/driver/externalconsoledriver.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/labgrid/driver/externalconsoledriver.py b/labgrid/driver/externalconsoledriver.py index 50a71e4f6..2ce4d1ed9 100644 --- a/labgrid/driver/externalconsoledriver.py +++ b/labgrid/driver/externalconsoledriver.py @@ -62,6 +62,11 @@ def close(self): self._child.kill() outs, errs = self._child.communicate() + if outs: + self.logger.info("child stdout while closing: %s", outs) + if errs: + self.logger.warning("child error while closing: %s", errs) + def _read(self, size: int=1024, timeout: int=0): """ Reads 'size' bytes from the serialport From 977426dbe1549fd12da8bcede3806192adc1750c Mon Sep 17 00:00:00 2001 From: Bastian Stender Date: Wed, 30 May 2018 16:12:26 +0200 Subject: [PATCH 24/45] driver/networkusbstoragedriver: log pwd instead of printing it Signed-off-by: Bastian Stender --- labgrid/driver/networkusbstoragedriver.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/labgrid/driver/networkusbstoragedriver.py b/labgrid/driver/networkusbstoragedriver.py index 0c8e1073b..c6c9a1b50 100644 --- a/labgrid/driver/networkusbstoragedriver.py +++ b/labgrid/driver/networkusbstoragedriver.py @@ -1,5 +1,6 @@ # pylint: disable=no-member import attr +import logging import subprocess import os @@ -16,6 +17,7 @@ class NetworkUSBStorageDriver(Driver): def __attrs_post_init__(self): super().__attrs_post_init__() + self.logger = logging.getLogger("{}:{}".format(self, self.target)) def on_activate(self): pass @@ -27,7 +29,7 @@ def on_deactivate(self): def write_image(self, filename): filename = os.path.abspath(filename) check_file(filename, command_prefix=self.storage.command_prefix) - print("pwd: %s" % os.getcwd()) + self.logger.info("pwd: %s", os.getcwd()) subprocess.check_call( self.storage.command_prefix+["dd", "if=%s" % filename, "of=%s status=progress bs=4M conv=fdatasync" % self.storage.path] ) From b244d2123b1db2acf44b4db2a0de6884af75ba8c Mon Sep 17 00:00:00 2001 From: Bastian Stender Date: Wed, 30 May 2018 16:25:41 +0200 Subject: [PATCH 25/45] driver/serialdigitaloutput: raise error on unexpected arg in get() Signed-off-by: Bastian Stender --- labgrid/driver/serialdigitaloutput.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/labgrid/driver/serialdigitaloutput.py b/labgrid/driver/serialdigitaloutput.py index e5a79c2e6..08ba4bb75 100644 --- a/labgrid/driver/serialdigitaloutput.py +++ b/labgrid/driver/serialdigitaloutput.py @@ -51,6 +51,8 @@ def get(self): elif self.signal == "rts": return self._p.rts + raise ValueError("Expected signal to be dtr or rts") + @Driver.check_active @step() def set(self, value): From 18e938a8a8045f1d0b82291e53d44364fc03e800 Mon Sep 17 00:00:00 2001 From: Bastian Stender Date: Wed, 30 May 2018 11:30:51 +0200 Subject: [PATCH 26/45] drop python3.4 support Signed-off-by: Bastian Stender --- .travis.yml | 1 - labgrid/remote/client.py | 102 ++++++++++---------------- labgrid/remote/coordinator.py | 119 +++++++++++++------------------ labgrid/remote/exporter.py | 58 +++++++-------- labgrid/resource/ethernetport.py | 19 +++-- labgrid/step.py | 5 +- setup.py | 2 +- tox.ini | 2 +- 8 files changed, 122 insertions(+), 186 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3dad8eced..b2c934f6b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,5 @@ language: python python: - - "3.4" - "3.5" - "3.6" before_install: diff --git a/labgrid/remote/client.py b/labgrid/remote/client.py index 06fc2e859..ca66c0dab 100755 --- a/labgrid/remote/client.py +++ b/labgrid/remote/client.py @@ -64,38 +64,34 @@ def onConnect(self): def onChallenge(self, challenge): return "dummy-ticket" - @asyncio.coroutine - def onJoin(self, details): + async def onJoin(self, details): # FIXME race condition? - resources = yield from self.call( + resources = await self.call( 'org.labgrid.coordinator.get_resources' ) self.resources = {} for exporter, groups in resources.items(): for group_name, group in sorted(groups.items()): for resource_name, resource in sorted(group.items()): - yield from self.on_resource_changed( + await self.on_resource_changed( exporter, group_name, resource_name, resource ) - places = yield from self.call('org.labgrid.coordinator.get_places') + places = await self.call('org.labgrid.coordinator.get_places') self.places = {} for placename, config in places.items(): - yield from self.on_place_changed(placename, config) + await self.on_place_changed(placename, config) - yield from self.subscribe( + await self.subscribe( self.on_resource_changed, 'org.labgrid.coordinator.resource_changed' ) - yield from self.subscribe( + await self.subscribe( self.on_place_changed, 'org.labgrid.coordinator.place_changed' ) - yield from self.connected(self) + await self.connected(self) - @asyncio.coroutine - def on_resource_changed( - self, exporter, group_name, resource_name, resource - ): + async def on_resource_changed(self, exporter, group_name, resource_name, resource): group = self.resources.setdefault(exporter, {}).setdefault(group_name, {}) # Do not replace the ResourceEntry object, as other components may keep @@ -121,8 +117,7 @@ def on_resource_changed( print("Resource {}/{}/{} deleted".format( exporter, group_name, resource_name)) - @asyncio.coroutine - def on_place_changed(self, name, config): + async def on_place_changed(self, name, config): if not config: del self.places[name] if self.monitor: @@ -146,14 +141,12 @@ def on_place_changed(self, name, config): print(" {}: {} -> {}".format(k, v_old, v_new)) self.places[name] = place - @asyncio.coroutine - def do_monitor(self): + async def do_monitor(self): self.monitor = True while True: - yield from asyncio.sleep(3600.0) + await asyncio.sleep(3600.0) - @asyncio.coroutine - def complete(self): + async def complete(self): if self.args.type == 'resources': for exporter, groups in sorted(self.resources.items()): for group_name, group in sorted(groups.items()): @@ -163,8 +156,7 @@ def complete(self): for name, place in sorted(self.places.items()): print(name) - @asyncio.coroutine - def print_resources(self): + async def print_resources(self): """Print out the resources""" match = ResourceMatch.fromstr(self.args.match) if self.args.match else None @@ -199,8 +191,7 @@ def print_resources(self): for resource_name, resource in sorted(group.items()): print("{}/{}/{}".format(exporter, group_name, resource.cls)) - @asyncio.coroutine - def print_places(self): + async def print_places(self): """Print out the places""" for name, place in sorted(self.places.items()): if self.args.acquired and place.acquired is None: @@ -285,8 +276,7 @@ def get_acquired_place(self, place=None): raise UserError("place {} is not acquired on this computer, acquired on {}".format(place.name, host)) return place - @asyncio.coroutine - def print_place(self): + async def print_place(self): """Print out the current place and related resources""" place = self.get_place() print("Place '{}':".format(place.name)) @@ -318,34 +308,31 @@ def print_place(self): name, exporter, group_name, resource.cls, resource_name)) print(indent(pformat(resource.asdict()), prefix=" ")) - @asyncio.coroutine - def add_place(self): + async def add_place(self): """Add a place to the coordinator""" name = self.args.place if not name: raise UserError("missing place name. Set with -p or via env var $PLACE") if name in self.places: raise UserError("{} already exists".format(name)) - res = yield from self.call('org.labgrid.coordinator.add_place', name) + res = await self.call('org.labgrid.coordinator.add_place', name) if not res: raise ServerError("failed to add place {}".format(name)) return res - @asyncio.coroutine - def del_place(self): + async def del_place(self): """Delete a place from the coordinator""" name = self.args.place if not name: raise UserError("missing place name. Set with -p or via env var $PLACE") if name not in self.places: raise UserError("{} does not exist".format(name)) - res = yield from self.call('org.labgrid.coordinator.del_place', name) + res = await self.call('org.labgrid.coordinator.del_place', name) if not res: raise ServerError("failed to delete place {}".format(name)) return res - @asyncio.coroutine - def add_alias(self): + async def add_alias(self): """Add an alias for a place on the coordinator""" place = self.get_idle_place() alias = self.args.alias @@ -353,7 +340,7 @@ def add_alias(self): raise UserError( "place {} already has alias {}".format(place.name, alias) ) - res = yield from self.call( + res = await self.call( 'org.labgrid.coordinator.add_place_alias', place.name, alias ) if not res: @@ -362,14 +349,13 @@ def add_alias(self): ) return res - @asyncio.coroutine - def del_alias(self): + async def del_alias(self): """Delete an alias for a place from the coordinator""" place = self.get_idle_place() alias = self.args.alias if alias not in place.aliases: raise UserError("place {} has no alias {}".format(place.name, alias)) - res = yield from self.call( + res = await self.call( 'org.labgrid.coordinator.del_place_alias', place.name, alias ) if not res: @@ -378,12 +364,11 @@ def del_alias(self): ) return res - @asyncio.coroutine - def set_comment(self): + async def set_comment(self): """Set the comment on a place""" place = self.get_place() comment = ' '.join(self.args.comment) - res = yield from self.call( + res = await self.call( 'org.labgrid.coordinator.set_place_comment', place.name, comment ) if not res: @@ -392,8 +377,7 @@ def set_comment(self): ) return res - @asyncio.coroutine - def add_match(self): + async def add_match(self): """Add a match for a place, making fuzzy matching available to the client""" place = self.get_idle_place() @@ -408,7 +392,7 @@ def add_match(self): "invalid pattern format '{}' (use 'exporter/group/cls/name')". format(pattern) ) - res = yield from self.call( + res = await self.call( 'org.labgrid.coordinator.add_place_match', place.name, pattern ) if not res: @@ -416,8 +400,7 @@ def add_match(self): "failed to add match {} for place {}".format(pattern, place.name) ) - @asyncio.coroutine - def del_match(self): + async def del_match(self): """Delete a match for a place""" place = self.get_idle_place() if place.acquired: @@ -431,7 +414,7 @@ def del_match(self): "invalid pattern format '{}' (use 'exporter/group/cls/name')". format(pattern) ) - res = yield from self.call( + res = await self.call( 'org.labgrid.coordinator.del_place_match', place.name, pattern ) if not res: @@ -440,8 +423,7 @@ def del_match(self): format(pattern, place.name) ) - @asyncio.coroutine - def add_named_match(self): + async def add_named_match(self): """Add a named match for a place. Fuzzy matching is not allowed to avoid accidental names conflicts.""" @@ -467,7 +449,7 @@ def add_named_match(self): "invalid name '{}'". format(name) ) - res = yield from self.call( + res = await self.call( 'org.labgrid.coordinator.add_place_match', place.name, pattern, name ) if not res: @@ -475,8 +457,7 @@ def add_named_match(self): "failed to add match {} for place {}".format(pattern, place.name) ) - @asyncio.coroutine - def acquire(self): + async def acquire(self): """Acquire a place, marking it unavailable for other clients""" place = self.get_place() if place.acquired: @@ -484,7 +465,7 @@ def acquire(self): "place {} is already acquired by {}". format(place.name, place.acquired) ) - res = yield from self.call( + res = await self.call( 'org.labgrid.coordinator.acquire_place', place.name ) if not res: @@ -492,8 +473,7 @@ def acquire(self): else: print("acquired place {}".format(place.name)) - @asyncio.coroutine - def release(self): + async def release(self): """Release a previously acquired place""" place = self.get_place() if not place.acquired: @@ -505,7 +485,7 @@ def release(self): "place {} is acquired by a different user ({}), use --kick if you are sure".format(place.name, place.acquired) ) print("warning: kicking user ({})".format(place.acquired)) - res = yield from self.call( + res = await self.call( 'org.labgrid.coordinator.release_place', place.name ) if not res: @@ -513,8 +493,7 @@ def release(self): else: print("released place {}".format(place.name)) - @asyncio.coroutine - def allow(self): + async def allow(self): """Allow another use access to a previously acquired place""" place = self.get_place() if not place.acquired: @@ -528,9 +507,7 @@ def allow(self): raise UserError( "user {} must be in / format".format(self.args.user) ) - res = yield from self.call( - 'org.labgrid.coordinator.allow_place', place.name, self.args.user - ) + res = await self.call('org.labgrid.coordinator.allow_place', place.name, self.args.user) if not res: raise ServerError("failed to allow {} for place {}".format(self.args.user, place.name)) else: @@ -918,8 +895,7 @@ def start_session(url, realm, extra): loop = asyncio.get_event_loop() ready = asyncio.Event() - @asyncio.coroutine - def connected(session): + async def connected(session): # pylint: disable=unused-argument ready.set() if not extra: diff --git a/labgrid/remote/coordinator.py b/labgrid/remote/coordinator.py index 922bf52a6..9e3f1e887 100644 --- a/labgrid/remote/coordinator.py +++ b/labgrid/remote/coordinator.py @@ -94,8 +94,7 @@ class ClientSession(RemoteSession): class CoordinatorComponent(ApplicationSession): - @asyncio.coroutine - def onConnect(self): + async def onConnect(self): self.sessions = {} self.places = {} self.poll_task = None @@ -110,67 +109,66 @@ def onConnect(self): def onChallenge(self, challenge): return "dummy-ticket" - @asyncio.coroutine - def onJoin(self, details): - yield from self.subscribe(self.on_session_join, 'wamp.session.on_join') - yield from self.subscribe( + async def onJoin(self, details): + await self.subscribe(self.on_session_join, 'wamp.session.on_join') + await self.subscribe( self.on_session_leave, 'wamp.session.on_leave' ) - yield from self.register( + await self.register( self.attach, 'org.labgrid.coordinator.attach', options=RegisterOptions(details_arg='details') ) # resources - yield from self.register( + await self.register( self.set_resource, 'org.labgrid.coordinator.set_resource', options=RegisterOptions(details_arg='details') ) - yield from self.register( + await self.register( self.get_resources, 'org.labgrid.coordinator.get_resources' ) # places - yield from self.register( + await self.register( self.add_place, 'org.labgrid.coordinator.add_place' ) - yield from self.register( + await self.register( self.del_place, 'org.labgrid.coordinator.del_place' ) - yield from self.register( + await self.register( self.add_place_alias, 'org.labgrid.coordinator.add_place_alias' ) - yield from self.register( + await self.register( self.del_place_alias, 'org.labgrid.coordinator.del_place_alias' ) - yield from self.register( + await self.register( self.set_place_comment, 'org.labgrid.coordinator.set_place_comment' ) - yield from self.register( + await self.register( self.add_place_match, 'org.labgrid.coordinator.add_place_match' ) - yield from self.register( + await self.register( self.del_place_match, 'org.labgrid.coordinator.del_place_match' ) - yield from self.register( + await self.register( self.acquire_place, 'org.labgrid.coordinator.acquire_place', options=RegisterOptions(details_arg='details') ) - yield from self.register( + await self.register( self.release_place, 'org.labgrid.coordinator.release_place', options=RegisterOptions(details_arg='details') ) - yield from self.register( + await self.register( self.allow_place, 'org.labgrid.coordinator.allow_place', options=RegisterOptions(details_arg='details') ) - yield from self.register( + await self.register( self.get_places, 'org.labgrid.coordinator.get_places' ) @@ -178,24 +176,21 @@ def onJoin(self, details): print("Coordinator ready.") - @asyncio.coroutine - def onLeave(self, details): + async def onLeave(self, details): self.save() if self.poll_task: self.poll_task.cancel() - yield from asyncio.wait([self.poll_task]) + await asyncio.wait([self.poll_task]) super().onLeave(details) - @asyncio.coroutine - def onDisconnect(self): + async def onDisconnect(self): self.save() if self.poll_task: self.poll_task.cancel() - yield from asyncio.wait([self.poll_task]) - yield from asyncio.sleep(0.5) # give others a chance to clean up + await asyncio.wait([self.poll_task]) + await asyncio.sleep(0.5) # give others a chance to clean up - @asyncio.coroutine - def _poll_step(self): + async def _poll_step(self): # save changes if self.save_scheduled: self.save() @@ -205,10 +200,10 @@ def _poll_step(self): fut = self.call( 'org.labgrid.exporter.{}.version'.format(session.name) ) - done, pending = yield from asyncio.wait([fut], timeout=5) + done, pending = await asyncio.wait([fut], timeout=5) if not done: print('kicking exporter ({}/{})'.format(session.key, session.name)) - yield from self.on_session_leave(session.key) + await self.on_session_leave(session.key) continue try: session.version = done.pop().result() @@ -220,13 +215,12 @@ def _poll_step(self): else: raise - @asyncio.coroutine - def poll(self): + async def poll(self): loop = asyncio.get_event_loop() while not loop.is_closed(): try: - yield from asyncio.sleep(15.0) - yield from self._poll_step() + await asyncio.sleep(15.0) + await self._poll_step() except asyncio.CancelledError: break except: @@ -279,8 +273,7 @@ def _add_default_place(self, name): )) self.places[name] = place - @asyncio.coroutine - def _update_acquired_places(self, action, resource_path): + async def _update_acquired_places(self, action, resource_path): """Update acquired places when resources are added or removed.""" if action not in [Action.ADD, Action.DEL]: return # currently nothing needed for Action.UPD @@ -297,8 +290,7 @@ def _update_acquired_places(self, action, resource_path): 'org.labgrid.coordinator.place_changed', placename, place.asdict() ) - @asyncio.coroutine - def on_session_join(self, session_details): + async def on_session_join(self, session_details): print('join') pprint(session_details) session = session_details['session'] @@ -311,8 +303,7 @@ def on_session_join(self, session_details): return self.sessions[session.key] = session - @asyncio.coroutine - def on_session_leave(self, session_id): + async def on_session_leave(self, session_id): print('leave ({})'.format(session_id)) try: session = self.sessions.pop(session_id) @@ -322,19 +313,17 @@ def on_session_leave(self, session_id): for groupname, group in session.groups.items(): for resourcename in group.copy(): action, resource_path = session.set_resource(groupname, resourcename, {}) - yield from self._update_acquired_places(action, resource_path) + await self._update_acquired_places(action, resource_path) # pylint: disable=not-an-iterable self.save_later() - @asyncio.coroutine - def attach(self, name, details=None): + async def attach(self, name, details=None): # TODO check if name is in use session = self.sessions[details.caller] session_details = self.sessions[session] session_details['name'] = name self.exporters[name] = defaultdict(dict) - @asyncio.coroutine - def set_resource(self, groupname, resourcename, resource, details=None): + async def set_resource(self, groupname, resourcename, resource, details=None): session = self.sessions.get(details.caller) if session is None: return @@ -348,7 +337,7 @@ def set_resource(self, groupname, resourcename, resource, details=None): action, resource_path = session.set_resource(groupname, resourcename, resource) if action is Action.ADD: self._add_default_place(groupname) - yield from self._update_acquired_places(action, resource_path) + await self._update_acquired_places(action, resource_path) self.save_later() def _get_resources(self): @@ -358,12 +347,10 @@ def _get_resources(self): result[session.name] = session.get_resources() return result - @asyncio.coroutine - def get_resources(self, details=None): + async def get_resources(self, details=None): return self._get_resources() - @asyncio.coroutine - def add_place(self, name, details=None): + async def add_place(self, name, details=None): if not name or not isinstance(name, str): return False if name in self.places: @@ -376,8 +363,7 @@ def add_place(self, name, details=None): self.save_later() return True - @asyncio.coroutine - def del_place(self, name, details=None): + async def del_place(self, name, details=None): if not name or not isinstance(name, str): return False if name not in self.places: @@ -389,8 +375,7 @@ def del_place(self, name, details=None): self.save_later() return True - @asyncio.coroutine - def add_place_alias(self, placename, alias, details=None): + async def add_place_alias(self, placename, alias, details=None): try: place = self.places[placename] except KeyError: @@ -403,8 +388,7 @@ def add_place_alias(self, placename, alias, details=None): self.save_later() return True - @asyncio.coroutine - def del_place_alias(self, placename, alias, details=None): + async def del_place_alias(self, placename, alias, details=None): try: place = self.places[placename] except KeyError: @@ -420,8 +404,7 @@ def del_place_alias(self, placename, alias, details=None): self.save_later() return True - @asyncio.coroutine - def set_place_comment(self, placename, comment, details=None): + async def set_place_comment(self, placename, comment, details=None): try: place = self.places[placename] except KeyError: @@ -434,8 +417,7 @@ def set_place_comment(self, placename, comment, details=None): self.save_later() return True - @asyncio.coroutine - def add_place_match(self, placename, pattern, rename=None, details=None): + async def add_place_match(self, placename, pattern, rename=None, details=None): try: place = self.places[placename] except KeyError: @@ -451,8 +433,7 @@ def add_place_match(self, placename, pattern, rename=None, details=None): self.save_later() return True - @asyncio.coroutine - def del_place_match(self, placename, pattern, rename=None, details=None): + async def del_place_match(self, placename, pattern, rename=None, details=None): try: place = self.places[placename] except KeyError: @@ -469,8 +450,7 @@ def del_place_match(self, placename, pattern, rename=None, details=None): self.save_later() return True - @asyncio.coroutine - def acquire_place(self, name, details=None): + async def acquire_place(self, name, details=None): print(details) try: place = self.places[name] @@ -495,8 +475,7 @@ def acquire_place(self, name, details=None): self.save_later() return True - @asyncio.coroutine - def release_place(self, name, details=None): + async def release_place(self, name, details=None): print(details) try: place = self.places[name] @@ -514,8 +493,7 @@ def release_place(self, name, details=None): self.save_later() return True - @asyncio.coroutine - def allow_place(self, name, user, details=None): + async def allow_place(self, name, user, details=None): try: place = self.places[name] except KeyError: @@ -535,8 +513,7 @@ def allow_place(self, name, user, details=None): def _get_places(self): return {k: v.asdict() for k, v in self.places.items()} - @asyncio.coroutine - def get_places(self, details=None): + async def get_places(self, details=None): return self._get_places() diff --git a/labgrid/remote/exporter.py b/labgrid/remote/exporter.py index 7ef817a9d..a30d23da4 100755 --- a/labgrid/remote/exporter.py +++ b/labgrid/remote/exporter.py @@ -338,8 +338,7 @@ def onChallenge(self, challenge): at the moment, authentication is not supported yet""" return "dummy-ticket" - @asyncio.coroutine - def onJoin(self, details): + async def onJoin(self, details): """On successful join: - export available resources - bail out if we are unsuccessful @@ -354,7 +353,7 @@ def onJoin(self, details): if params is None: continue cls = params.pop('cls', resource_name) - yield from self.add_resource( + await self.add_resource( group_name, resource_name, cls, params ) @@ -366,47 +365,41 @@ def onJoin(self, details): self.poll_task = self.loop.create_task(self.poll()) prefix = 'org.labgrid.exporter.{}'.format(self.name) - yield from self.register(self.acquire, '{}.acquire'.format(prefix)) - yield from self.register(self.release, '{}.release'.format(prefix)) - yield from self.register(self.version, '{}.version'.format(prefix)) + await self.register(self.acquire, '{}.acquire'.format(prefix)) + await self.register(self.release, '{}.release'.format(prefix)) + await self.register(self.version, '{}.version'.format(prefix)) - @asyncio.coroutine - def onLeave(self, details): + async def onLeave(self, details): """Cleanup after leaving the coordinator connection""" if self.poll_task: self.poll_task.cancel() - yield from asyncio.wait([self.poll_task]) + await asyncio.wait([self.poll_task]) super().onLeave(details) - @asyncio.coroutine - def onDisconnect(self): + async def onDisconnect(self): print("connection lost") global reexec reexec = True if self.poll_task: self.poll_task.cancel() - yield from asyncio.wait([self.poll_task]) - yield from asyncio.sleep(0.5) # give others a chance to clean up + await asyncio.wait([self.poll_task]) + await asyncio.sleep(0.5) # give others a chance to clean up self.loop.stop() - @asyncio.coroutine - def acquire(self, group_name, resource_name): + async def acquire(self, group_name, resource_name): resource = self.groups[group_name][resource_name] #resource.acquire() - yield from self.update_resource(group_name, resource_name) + await self.update_resource(group_name, resource_name) - @asyncio.coroutine - def release(self, group_name, resource_name): + async def release(self, group_name, resource_name): resource = self.groups[group_name][resource_name] #resource.release() - yield from self.update_resource(group_name, resource_name) + await self.update_resource(group_name, resource_name) - @asyncio.coroutine - def version(self): + async def version(self): return __version__ - @asyncio.coroutine - def _poll_step(self): + async def _poll_step(self): for group_name, group in self.groups.items(): for resource_name, resource in group.items(): if not isinstance(resource, ResourceExport): @@ -421,24 +414,22 @@ def _poll_step(self): # resource has changed data = resource.asdict() print(data) - yield from self.call( + await self.call( 'org.labgrid.coordinator.set_resource', group_name, resource_name, data ) - @asyncio.coroutine - def poll(self): + async def poll(self): while True: try: - yield from asyncio.sleep(1.0) - yield from self._poll_step() + await asyncio.sleep(1.0) + await self._poll_step() except asyncio.CancelledError: break except: traceback.print_exc() - @asyncio.coroutine - def add_resource(self, group_name, resource_name, cls, params): + async def add_resource(self, group_name, resource_name, cls, params): """Add a resource to the exporter and update status on the coordinator""" print( "add resource {}/{}: {}/{}". @@ -456,15 +447,14 @@ def add_resource(self, group_name, resource_name, cls, params): group[resource_name] = export_cls(config, host=self.hostname) else: group[resource_name] = export_cls(config) - yield from self.update_resource(group_name, resource_name) + await self.update_resource(group_name, resource_name) - @asyncio.coroutine - def update_resource(self, group_name, resource_name): + async def update_resource(self, group_name, resource_name): """Update status on the coordinator""" resource = self.groups[group_name][resource_name] data = resource.asdict() print(data) - yield from self.call( + await self.call( 'org.labgrid.coordinator.set_resource', group_name, resource_name, data ) diff --git a/labgrid/resource/ethernetport.py b/labgrid/resource/ethernetport.py index cd9fbaae5..0e1951106 100644 --- a/labgrid/resource/ethernetport.py +++ b/labgrid/resource/ethernetport.py @@ -218,15 +218,13 @@ def _start(self): if self.poll_tasks: return - @asyncio.coroutine - def poll_neighbour(self): + async def poll_neighbour(self): self.logger.debug("polling neighbor table") self.neighbors = self._get_neigh() - yield from asyncio.sleep(1.0) + await asyncio.sleep(1.0) - @asyncio.coroutine - def poll_switches(self): + async def poll_switches(self): current = set(resource.switch for resource in self.resources) removed = set(self.switches) - current new = current - set(self.switches) @@ -236,16 +234,15 @@ def poll_switches(self): self.switches[switch] = SNMPSwitch(switch) for switch in current: self.switches[switch].update() - yield from asyncio.sleep(1.0) + await asyncio.sleep(1.0) - yield from asyncio.sleep(2.0) + await asyncio.sleep(2.0) - @asyncio.coroutine - def poll(self, handler): + async def poll(self, handler): while True: try: - yield from asyncio.sleep(1.0) - yield from handler(self) + await asyncio.sleep(1.0) + await handler(self) except asyncio.CancelledError: break except: diff --git a/labgrid/step.py b/labgrid/step.py index 95db007c5..88ad51045 100644 --- a/labgrid/step.py +++ b/labgrid/step.py @@ -193,10 +193,7 @@ def decorator(func): @wraps(func) def wrapper(*_args, **_kwargs): bound = signature.bind_partial(*_args, **_kwargs) - # TODO: replace this by bound.apply_defaults() when deprecating - # python3.4 support - for name, param in signature.parameters.items(): - bound.arguments.setdefault(name, param.default) + bound.apply_defaults() source = bound.arguments.get('self') step = steps.get_new(title, tag, source) # optionally pass the step object diff --git a/setup.py b/setup.py index ff3a34ae3..4c8b7fb3d 100755 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ data_files=[('share/man/1', ['man/labgrid-client.1', 'man/labgrid-exporter.1', 'man/labgrid-device-config.1'])], - python_requires='>=3.4', + python_requires='>=3.5', extras_require={ 'onewire': ['onewire>=0.2'], 'snmp': ['pysnmp', 'pysnmp-mibs'], diff --git a/tox.ini b/tox.ini index 8a2cf9373..9df517982 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py34, py35, py36 +envlist = py35, py36 [testenv] deps = -rdev-requirements.txt From 7021d8db4308f6a75283ba6a2b267b50f700496f Mon Sep 17 00:00:00 2001 From: Bastian Stender Date: Fri, 25 May 2018 14:53:51 +0200 Subject: [PATCH 27/45] linting: remove unused imports Signed-off-by: Bastian Stender --- examples/hawkbit/test_hawkbit.py | 1 - examples/shell/test_hwclock.py | 1 - examples/strategy/test_uboot_strategy.py | 1 - labgrid/config.py | 1 - labgrid/driver/bareboxdriver.py | 4 +--- labgrid/driver/consoleexpectmixin.py | 4 ---- labgrid/driver/fastbootdriver.py | 1 - labgrid/driver/modbusdriver.py | 1 - labgrid/driver/onewiredriver.py | 2 -- labgrid/driver/openocddriver.py | 1 - labgrid/driver/power/apc.py | 1 - labgrid/driver/power/digipower.py | 2 -- labgrid/driver/power/gude.py | 2 -- labgrid/driver/power/gude24.py | 2 -- labgrid/driver/power/netio.py | 1 - labgrid/driver/powerdriver.py | 1 - labgrid/driver/serialdigitaloutput.py | 8 -------- labgrid/driver/shelldriver.py | 7 ++----- labgrid/driver/smallubootdriver.py | 7 ------- labgrid/driver/sshdriver.py | 5 ++--- labgrid/driver/ubootdriver.py | 1 - labgrid/driver/usbloader.py | 1 - labgrid/driver/usbstorage.py | 2 -- labgrid/driver/usbtmcdriver.py | 1 - labgrid/environment.py | 1 - labgrid/external/hawkbit.py | 2 -- labgrid/protocol/linuxbootprotocol.py | 2 -- labgrid/remote/authenticator.py | 2 -- labgrid/remote/client.py | 1 - labgrid/remote/coordinator.py | 2 +- labgrid/resource/ethernetport.py | 2 +- labgrid/resource/remote.py | 2 +- labgrid/strategy/common.py | 2 +- labgrid/target.py | 2 +- labgrid/util/agentwrapper.py | 1 - labgrid/util/expect.py | 3 --- labgrid/util/qmp.py | 3 +-- setup.py | 1 - tests/conftest.py | 5 +---- tests/test_autoinstall.py | 2 +- tests/test_bareboxdriver.py | 4 +--- tests/test_environment.py | 1 - tests/test_ethernetport.py | 2 -- tests/test_externalconsoledriver.py | 2 -- tests/test_factory.py | 1 - tests/test_hawkbit.py | 2 -- tests/test_powerdriver.py | 2 -- tests/test_resource.py | 2 +- tests/test_strategy.py | 5 ----- tests/test_target.py | 2 +- tests/test_usbemulator.py | 2 -- tests/test_usbtmc.py | 2 -- tests/test_usbvideo.py | 2 -- 53 files changed, 16 insertions(+), 104 deletions(-) diff --git a/examples/hawkbit/test_hawkbit.py b/examples/hawkbit/test_hawkbit.py index 76d437a64..2f9c65b3c 100644 --- a/examples/hawkbit/test_hawkbit.py +++ b/examples/hawkbit/test_hawkbit.py @@ -2,7 +2,6 @@ import time from labgrid.external import HawkbitTestClient -from labgrid.driver import InfoDriver @pytest.fixture() def hawkbit(): diff --git a/examples/shell/test_hwclock.py b/examples/shell/test_hwclock.py index da6c73d70..b464d0870 100644 --- a/examples/shell/test_hwclock.py +++ b/examples/shell/test_hwclock.py @@ -1,4 +1,3 @@ -import time from datetime import datetime diff --git a/examples/strategy/test_uboot_strategy.py b/examples/strategy/test_uboot_strategy.py index ac235074f..59ce20c66 100644 --- a/examples/strategy/test_uboot_strategy.py +++ b/examples/strategy/test_uboot_strategy.py @@ -1,5 +1,4 @@ import pytest -import logging @pytest.fixture() diff --git a/labgrid/config.py b/labgrid/config.py index 6ba144aa6..85b67e995 100644 --- a/labgrid/config.py +++ b/labgrid/config.py @@ -4,7 +4,6 @@ """ import attr -import logging import os from .exceptions import NoConfigFoundError, InvalidConfigError diff --git a/labgrid/driver/bareboxdriver.py b/labgrid/driver/bareboxdriver.py index 382ad677f..3262d79ff 100644 --- a/labgrid/driver/bareboxdriver.py +++ b/labgrid/driver/bareboxdriver.py @@ -2,7 +2,6 @@ import logging import re import shlex -from time import sleep import attr from pexpect import TIMEOUT @@ -10,10 +9,9 @@ from ..factory import target_factory from ..protocol import CommandProtocol, ConsoleProtocol, LinuxBootProtocol from ..step import step -from ..util import gen_marker, Timeout +from ..util import gen_marker from .common import Driver from .commandmixin import CommandMixin -from .exception import ExecutionError @target_factory.reg_driver diff --git a/labgrid/driver/consoleexpectmixin.py b/labgrid/driver/consoleexpectmixin.py index fb66c50ff..221b5498b 100644 --- a/labgrid/driver/consoleexpectmixin.py +++ b/labgrid/driver/consoleexpectmixin.py @@ -1,9 +1,5 @@ from time import sleep -import attr - -from pexpect import TIMEOUT - from ..util import PtxExpect from ..step import step from .common import Driver diff --git a/labgrid/driver/fastbootdriver.py b/labgrid/driver/fastbootdriver.py index e0d3f96d5..65bcedb88 100644 --- a/labgrid/driver/fastbootdriver.py +++ b/labgrid/driver/fastbootdriver.py @@ -8,7 +8,6 @@ from ..resource.udev import AndroidFastboot from ..step import step from .common import Driver, check_file -from .exception import ExecutionError @target_factory.reg_driver diff --git a/labgrid/driver/modbusdriver.py b/labgrid/driver/modbusdriver.py index 0940769c5..3b5dbf78b 100644 --- a/labgrid/driver/modbusdriver.py +++ b/labgrid/driver/modbusdriver.py @@ -1,4 +1,3 @@ -import logging from importlib import import_module import attr diff --git a/labgrid/driver/onewiredriver.py b/labgrid/driver/onewiredriver.py index 0c1cdcce1..91d37b531 100644 --- a/labgrid/driver/onewiredriver.py +++ b/labgrid/driver/onewiredriver.py @@ -1,5 +1,3 @@ -import logging - import attr from ..factory import target_factory diff --git a/labgrid/driver/openocddriver.py b/labgrid/driver/openocddriver.py index 4f27718c6..f36a23382 100644 --- a/labgrid/driver/openocddriver.py +++ b/labgrid/driver/openocddriver.py @@ -9,7 +9,6 @@ from ..resource.udev import AlteraUSBBlaster from ..step import step from .common import Driver, check_file -from .exception import ExecutionError @target_factory.reg_driver diff --git a/labgrid/driver/power/apc.py b/labgrid/driver/power/apc.py index 47b7eda46..0f4a3db57 100644 --- a/labgrid/driver/power/apc.py +++ b/labgrid/driver/power/apc.py @@ -1,4 +1,3 @@ -import sys import subprocess from ..exception import ExecutionError diff --git a/labgrid/driver/power/digipower.py b/labgrid/driver/power/digipower.py index 9b7be252d..32375c1fa 100644 --- a/labgrid/driver/power/digipower.py +++ b/labgrid/driver/power/digipower.py @@ -1,5 +1,3 @@ -import sys - import requests diff --git a/labgrid/driver/power/gude.py b/labgrid/driver/power/gude.py index accc683d6..a8e18bf89 100644 --- a/labgrid/driver/power/gude.py +++ b/labgrid/driver/power/gude.py @@ -1,5 +1,3 @@ -import sys - from ..exception import ExecutionError import requests diff --git a/labgrid/driver/power/gude24.py b/labgrid/driver/power/gude24.py index 1d521a731..5411a3a2b 100644 --- a/labgrid/driver/power/gude24.py +++ b/labgrid/driver/power/gude24.py @@ -1,5 +1,3 @@ -import sys - from ..exception import ExecutionError import requests diff --git a/labgrid/driver/power/netio.py b/labgrid/driver/power/netio.py index 50cf1a640..e090104c3 100644 --- a/labgrid/driver/power/netio.py +++ b/labgrid/driver/power/netio.py @@ -1,4 +1,3 @@ -import sys import re import requests diff --git a/labgrid/driver/powerdriver.py b/labgrid/driver/powerdriver.py index 39e7304a0..218b3f386 100644 --- a/labgrid/driver/powerdriver.py +++ b/labgrid/driver/powerdriver.py @@ -14,7 +14,6 @@ from ..step import step from .common import Driver from .exception import ExecutionError -from .onewiredriver import OneWirePIODriver @attr.s(cmp=False) diff --git a/labgrid/driver/serialdigitaloutput.py b/labgrid/driver/serialdigitaloutput.py index 08ba4bb75..331a7c794 100644 --- a/labgrid/driver/serialdigitaloutput.py +++ b/labgrid/driver/serialdigitaloutput.py @@ -1,18 +1,10 @@ -import shlex -import subprocess -import time -from importlib import import_module -import serial - import attr from ..factory import target_factory from ..protocol import DigitalOutputProtocol from ..step import step -from ..resource import SerialPort from .common import Driver from . import SerialDriver -from .onewiredriver import OneWirePIODriver @target_factory.reg_driver @attr.s(cmp=False) diff --git a/labgrid/driver/shelldriver.py b/labgrid/driver/shelldriver.py index de5ccc588..f2c7eeb80 100644 --- a/labgrid/driver/shelldriver.py +++ b/labgrid/driver/shelldriver.py @@ -3,10 +3,8 @@ InfoProtocol on top of a SerialPort.""" import io import logging -import os import re import shlex -from time import sleep import attr from pexpect import TIMEOUT @@ -16,10 +14,9 @@ import xmodem from ..factory import target_factory -from ..protocol import (CommandProtocol, ConsoleProtocol, FileTransferProtocol, - InfoProtocol) +from ..protocol import CommandProtocol, ConsoleProtocol, FileTransferProtocol from ..step import step -from ..util import Timeout, gen_marker +from ..util import gen_marker from .commandmixin import CommandMixin from .common import Driver from .exception import ExecutionError diff --git a/labgrid/driver/smallubootdriver.py b/labgrid/driver/smallubootdriver.py index fe813b1b6..5cc10aa5e 100644 --- a/labgrid/driver/smallubootdriver.py +++ b/labgrid/driver/smallubootdriver.py @@ -1,16 +1,9 @@ -import logging -import re - import attr -from pexpect import TIMEOUT from ..factory import target_factory -from ..protocol import CommandProtocol, ConsoleProtocol, LinuxBootProtocol from ..util import gen_marker from ..step import step from .common import Driver -from .commandmixin import CommandMixin -from .exception import ExecutionError from .ubootdriver import UBootDriver diff --git a/labgrid/driver/sshdriver.py b/labgrid/driver/sshdriver.py index e0be34fcd..650eca1b9 100644 --- a/labgrid/driver/sshdriver.py +++ b/labgrid/driver/sshdriver.py @@ -9,13 +9,12 @@ import attr from ..factory import target_factory -from ..protocol import CommandProtocol, FileTransferProtocol, InfoProtocol +from ..protocol import CommandProtocol, FileTransferProtocol from ..resource import NetworkService from .commandmixin import CommandMixin -from ..util import Timeout from .common import Driver from ..step import step -from .exception import CleanUpError, ExecutionError +from .exception import ExecutionError @target_factory.reg_driver diff --git a/labgrid/driver/ubootdriver.py b/labgrid/driver/ubootdriver.py index 125298a10..a67ff2885 100644 --- a/labgrid/driver/ubootdriver.py +++ b/labgrid/driver/ubootdriver.py @@ -12,7 +12,6 @@ from ..step import step from .common import Driver from .commandmixin import CommandMixin -from .exception import ExecutionError @target_factory.reg_driver diff --git a/labgrid/driver/usbloader.py b/labgrid/driver/usbloader.py index 825bd5a25..a3a5f5d1c 100644 --- a/labgrid/driver/usbloader.py +++ b/labgrid/driver/usbloader.py @@ -9,7 +9,6 @@ from ..resource.udev import MXSUSBLoader, IMXUSBLoader from ..step import step from .common import Driver, check_file -from .exception import ExecutionError @target_factory.reg_driver diff --git a/labgrid/driver/usbstorage.py b/labgrid/driver/usbstorage.py index d1d716c69..05b131892 100644 --- a/labgrid/driver/usbstorage.py +++ b/labgrid/driver/usbstorage.py @@ -5,11 +5,9 @@ from time import time from ..factory import target_factory -from ..protocol import BootstrapProtocol from ..resource.udev import USBMassStorage, USBSDMuxDevice from ..step import step from .common import Driver -from .exception import ExecutionError @target_factory.reg_driver diff --git a/labgrid/driver/usbtmcdriver.py b/labgrid/driver/usbtmcdriver.py index 22c547c69..f32e4e9d0 100644 --- a/labgrid/driver/usbtmcdriver.py +++ b/labgrid/driver/usbtmcdriver.py @@ -1,6 +1,5 @@ # pylint: disable=no-member import attr -import subprocess from importlib import import_module from decimal import Decimal diff --git a/labgrid/environment.py b/labgrid/environment.py index 468cb8bac..51afeae19 100644 --- a/labgrid/environment.py +++ b/labgrid/environment.py @@ -1,6 +1,5 @@ import attr import os -import yaml from .target import Target from .config import Config diff --git a/labgrid/external/hawkbit.py b/labgrid/external/hawkbit.py index 48415a6f1..f287077fb 100644 --- a/labgrid/external/hawkbit.py +++ b/labgrid/external/hawkbit.py @@ -1,5 +1,3 @@ -import json - import attr import requests as r diff --git a/labgrid/protocol/linuxbootprotocol.py b/labgrid/protocol/linuxbootprotocol.py index cff64d4ea..e72635458 100644 --- a/labgrid/protocol/linuxbootprotocol.py +++ b/labgrid/protocol/linuxbootprotocol.py @@ -1,7 +1,5 @@ import abc -import attr - class LinuxBootProtocol(abc.ABC): @abc.abstractmethod diff --git a/labgrid/remote/authenticator.py b/labgrid/remote/authenticator.py index 256dce1e1..e018b8f9c 100644 --- a/labgrid/remote/authenticator.py +++ b/labgrid/remote/authenticator.py @@ -1,10 +1,8 @@ -import os from pprint import pprint from twisted.internet.defer import inlineCallbacks from autobahn.twisted.wamp import ApplicationSession -from autobahn.wamp.exception import ApplicationError class AuthenticatorSession(ApplicationSession): diff --git a/labgrid/remote/client.py b/labgrid/remote/client.py index ca66c0dab..5a5b6349a 100755 --- a/labgrid/remote/client.py +++ b/labgrid/remote/client.py @@ -813,7 +813,6 @@ def video(self): quality = self.args.quality target = self._get_target(place) from ..driver.usbvideodriver import USBVideoDriver - from ..resource.remote import NetworkUSBVideo drv = None try: drv = target.get_driver(USBVideoDriver) diff --git a/labgrid/remote/coordinator.py b/labgrid/remote/coordinator.py index 9e3f1e887..4e96af2f0 100644 --- a/labgrid/remote/coordinator.py +++ b/labgrid/remote/coordinator.py @@ -11,7 +11,7 @@ import yaml from autobahn import wamp from autobahn.asyncio.wamp import ApplicationRunner, ApplicationSession -from autobahn.wamp.types import RegisterOptions, SubscribeOptions +from autobahn.wamp.types import RegisterOptions from .common import ResourceEntry, ResourceMatch, Place, enable_tcp_nodelay diff --git a/labgrid/resource/ethernetport.py b/labgrid/resource/ethernetport.py index 0e1951106..f0e083647 100644 --- a/labgrid/resource/ethernetport.py +++ b/labgrid/resource/ethernetport.py @@ -4,7 +4,7 @@ from time import time from ..factory import target_factory -from .common import Resource, ManagedResource, ResourceManager +from .common import ManagedResource, ResourceManager @attr.s class SNMPSwitch: diff --git a/labgrid/resource/remote.py b/labgrid/resource/remote.py index ba99a67c6..09eba5af5 100644 --- a/labgrid/resource/remote.py +++ b/labgrid/resource/remote.py @@ -3,7 +3,7 @@ import os from ..factory import target_factory -from .common import Resource, NetworkResource, ManagedResource, ResourceManager +from .common import NetworkResource, ManagedResource, ResourceManager @attr.s(cmp=False) diff --git a/labgrid/strategy/common.py b/labgrid/strategy/common.py index 4dd51666c..b9ea59a9c 100644 --- a/labgrid/strategy/common.py +++ b/labgrid/strategy/common.py @@ -1,6 +1,6 @@ import attr -from ..binding import BindingError, BindingMixin +from ..binding import BindingError from ..driver import Driver diff --git a/labgrid/target.py b/labgrid/target.py index 660073f35..0fa15ca90 100644 --- a/labgrid/target.py +++ b/labgrid/target.py @@ -8,7 +8,7 @@ from .binding import BindingError, BindingState from .driver import Driver from .exceptions import NoSupplierFoundError, NoDriverFoundError, NoResourceFoundError -from .resource import Resource, ManagedResource +from .resource import Resource from .strategy import Strategy from .util import Timeout diff --git a/labgrid/util/agentwrapper.py b/labgrid/util/agentwrapper.py index 0796d470c..8e3354254 100644 --- a/labgrid/util/agentwrapper.py +++ b/labgrid/util/agentwrapper.py @@ -3,7 +3,6 @@ import json import os.path import subprocess -import time def b2s(b): return base64.b85encode(b).decode('ascii') diff --git a/labgrid/util/expect.py b/labgrid/util/expect.py index 4f0c6bc1c..ce55a284a 100644 --- a/labgrid/util/expect.py +++ b/labgrid/util/expect.py @@ -1,8 +1,5 @@ import pexpect -from ..protocol import ConsoleProtocol -from .exceptions import NoValidDriverError - class PtxExpect(pexpect.spawn): """labgrid Wrapper of the pexpect module. diff --git a/labgrid/util/qmp.py b/labgrid/util/qmp.py index 645f47ad2..1a3d5fef0 100644 --- a/labgrid/util/qmp.py +++ b/labgrid/util/qmp.py @@ -1,8 +1,7 @@ import json -import socket import attr import logging -from os import close + @attr.s(cmp=False) class QMPMonitor: diff --git a/setup.py b/setup.py index 4c8b7fb3d..9ec3a1ab0 100755 --- a/setup.py +++ b/setup.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -import fastentrypoints from setuptools import setup diff --git a/tests/conftest.py b/tests/conftest.py index ce02a57a6..b94e6ac5f 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,13 +1,10 @@ from importlib.util import find_spec -import attr import pytest import pexpect -from py.path import local -from labgrid import Target, target_factory +from labgrid import Target from labgrid.driver import SerialDriver -from labgrid.protocol import CommandProtocol, ConsoleProtocol from labgrid.resource import RawSerialPort, NetworkSerialPort from labgrid.driver.fake import FakeConsoleDriver diff --git a/tests/test_autoinstall.py b/tests/test_autoinstall.py index 2c2968fbd..468732dff 100644 --- a/tests/test_autoinstall.py +++ b/tests/test_autoinstall.py @@ -1,6 +1,6 @@ -import pytest import pexpect + def test_autoinstall_help(): with pexpect.spawn('python -m labgrid.autoinstall.main --help') as spawn: spawn.expect("usage") diff --git a/tests/test_bareboxdriver.py b/tests/test_bareboxdriver.py index b02ea6867..ebf943a1b 100644 --- a/tests/test_bareboxdriver.py +++ b/tests/test_bareboxdriver.py @@ -1,11 +1,9 @@ -import attr import pytest from labgrid import Target from labgrid.driver import BareboxDriver from labgrid.driver.fake import FakeConsoleDriver -from labgrid.protocol import (CommandProtocol, ConsoleProtocol, - LinuxBootProtocol) +from labgrid.protocol import CommandProtocol, LinuxBootProtocol from labgrid.driver import ExecutionError diff --git a/tests/test_environment.py b/tests/test_environment.py index 355560dcb..97d73d047 100644 --- a/tests/test_environment.py +++ b/tests/test_environment.py @@ -2,7 +2,6 @@ from labgrid import Environment from labgrid.exceptions import NoConfigFoundError, InvalidConfigError -from labgrid.driver.fake import FakeConsoleDriver, FakePowerDriver from labgrid.protocol import ConsoleProtocol from labgrid.resource import RawSerialPort diff --git a/tests/test_ethernetport.py b/tests/test_ethernetport.py index dde8dd415..447c22b34 100644 --- a/tests/test_ethernetport.py +++ b/tests/test_ethernetport.py @@ -1,5 +1,3 @@ -import pytest - from labgrid.resource import SNMPEthernetPort def test_instance(target): diff --git a/tests/test_externalconsoledriver.py b/tests/test_externalconsoledriver.py index 33f08a7f0..4878ed60d 100644 --- a/tests/test_externalconsoledriver.py +++ b/tests/test_externalconsoledriver.py @@ -1,7 +1,5 @@ import time -import pytest - from labgrid.driver import ExternalConsoleDriver diff --git a/tests/test_factory.py b/tests/test_factory.py index a940e8e68..19163f26d 100644 --- a/tests/test_factory.py +++ b/tests/test_factory.py @@ -3,7 +3,6 @@ import pytest from labgrid import Target, target_factory -from labgrid.driver.fake import FakeConsoleDriver from labgrid.exceptions import InvalidConfigError from labgrid.resource import SerialPort from labgrid.util.yaml import load diff --git a/tests/test_hawkbit.py b/tests/test_hawkbit.py index f84739b8b..086c0266d 100644 --- a/tests/test_hawkbit.py +++ b/tests/test_hawkbit.py @@ -1,5 +1,3 @@ -import pytest - from labgrid.external import HawkbitTestClient diff --git a/tests/test_powerdriver.py b/tests/test_powerdriver.py index e0d0d757d..e30a39e2c 100644 --- a/tests/test_powerdriver.py +++ b/tests/test_powerdriver.py @@ -1,5 +1,3 @@ -import pytest - from labgrid.resource import NetworkPowerPort from labgrid.driver.powerdriver import ExternalPowerDriver, ManualPowerDriver, NetworkPowerDriver diff --git a/tests/test_resource.py b/tests/test_resource.py index d9cd546cc..2b2b10468 100644 --- a/tests/test_resource.py +++ b/tests/test_resource.py @@ -1,4 +1,4 @@ -from labgrid.resource import ManagedResource, Resource, ResourceManager +from labgrid.resource import ManagedResource, Resource def test_create_resource(target): diff --git a/tests/test_strategy.py b/tests/test_strategy.py index 39bc71a5c..e28db93a0 100644 --- a/tests/test_strategy.py +++ b/tests/test_strategy.py @@ -1,12 +1,7 @@ -import pytest - from labgrid.binding import BindingState from labgrid.driver import BareboxDriver, UBootDriver, ShellDriver from labgrid.driver.fake import FakeConsoleDriver, FakePowerDriver -from labgrid.protocol import (CommandProtocol, ConsoleProtocol, - LinuxBootProtocol) from labgrid.strategy import Strategy, BareboxStrategy, UBootStrategy -from labgrid.exceptions import NoDriverFoundError def test_create_barebox(target): diff --git a/tests/test_target.py b/tests/test_target.py index f2fe202cc..3269c5cba 100644 --- a/tests/test_target.py +++ b/tests/test_target.py @@ -3,7 +3,7 @@ import attr import pytest -from labgrid import Target, target_factory +from labgrid import Target from labgrid.binding import BindingError from labgrid.resource import Resource from labgrid.driver import Driver diff --git a/tests/test_usbemulator.py b/tests/test_usbemulator.py index b46a7941f..e9ed2be71 100644 --- a/tests/test_usbemulator.py +++ b/tests/test_usbemulator.py @@ -1,5 +1,3 @@ -import pytest - from labgrid.driver.fake import FakeCommandDriver, FakeFileTransferDriver from labgrid.external import USBStick diff --git a/tests/test_usbtmc.py b/tests/test_usbtmc.py index 6bd2beeb5..362398807 100644 --- a/tests/test_usbtmc.py +++ b/tests/test_usbtmc.py @@ -1,5 +1,3 @@ -import pytest - from labgrid.resource.remote import NetworkUSBTMC from labgrid.driver.usbtmcdriver import USBTMCDriver diff --git a/tests/test_usbvideo.py b/tests/test_usbvideo.py index 5f66f7c93..41447c372 100644 --- a/tests/test_usbvideo.py +++ b/tests/test_usbvideo.py @@ -1,5 +1,3 @@ -import pytest - from labgrid.resource.remote import NetworkUSBVideo from labgrid.driver.usbvideodriver import USBVideoDriver From d8b8612e5e216e7e0f63e6d375e60a4cdf13af65 Mon Sep 17 00:00:00 2001 From: Bastian Stender Date: Wed, 30 May 2018 15:21:19 +0200 Subject: [PATCH 28/45] linting: strategy/graphstrategy: no empty list as arg default Do not use mutable values as dangerous default values for arguments. See pylint W0102 error message. Signed-off-by: Bastian Stender --- labgrid/strategy/graphstrategy.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/labgrid/strategy/graphstrategy.py b/labgrid/strategy/graphstrategy.py index 99aa76898..060d2884e 100644 --- a/labgrid/strategy/graphstrategy.py +++ b/labgrid/strategy/graphstrategy.py @@ -99,7 +99,8 @@ def invalidate(self): self.path = [] @step(args=['state']) - def transition(self, state, via=[]): + def transition(self, state, via=None): + via = via or [] try: # check if another transition is running if self.__transition_running: @@ -144,7 +145,8 @@ def transition(self, state, via=[]): # unlock transition self.__transition_running = False - def find_abs_path(self, state, via=[]): + def find_abs_path(self, state, via=None): + via = via or [] via = via[::-1] path = [state, ] current_state = self.states[state] From 0b3f89b2aee6fdfa1782374c5e2d107597d4ca07 Mon Sep 17 00:00:00 2001 From: Bastian Stender Date: Mon, 4 Jun 2018 09:34:27 +0200 Subject: [PATCH 29/45] linting: strategy/graphstrategy: simplify dict iteration in graph() It is enough to just iterate through the dictionary itself, as in: for key in dictionary: pass Signed-off-by: Bastian Stender --- labgrid/strategy/graphstrategy.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/labgrid/strategy/graphstrategy.py b/labgrid/strategy/graphstrategy.py index 060d2884e..77b576e75 100644 --- a/labgrid/strategy/graphstrategy.py +++ b/labgrid/strategy/graphstrategy.py @@ -208,7 +208,7 @@ def graph(self): dg.attr('edge', style='dashed', arrowhead='empty') - for node_name in self.states.keys(): + for node_name in self.states: if node_name not in self.path: dg.node(node_name) From 933232ad55d895eee1097f79ce4eede64e56e6cc Mon Sep 17 00:00:00 2001 From: Bastian Stender Date: Tue, 29 May 2018 20:01:11 +0200 Subject: [PATCH 30/45] linting: remote/client: do not rely on loop variable "resource" should only be used in the loop and not lateron. Use the resource name from the method argument instead. Signed-off-by: Bastian Stender --- labgrid/remote/client.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/labgrid/remote/client.py b/labgrid/remote/client.py index 5a5b6349a..8132eca1e 100755 --- a/labgrid/remote/client.py +++ b/labgrid/remote/client.py @@ -639,13 +639,8 @@ def digital_io(self): raise UserError("target has no compatible resource available") target.activate(drv) if action == 'get': - print( - "digital IO {} for place {} is {}".format( - resource.name, - place.name, - 'high' if drv.get() else 'low', - ) - ) + print("digital IO {} for place {} is {}".format( + name, place.name, 'high' if drv.get() else 'low')) elif action == 'high': drv.set(True) elif action == 'low': From 0e12f84ac10d55c7f33d34f49082d760a7ff2df6 Mon Sep 17 00:00:00 2001 From: Bastian Stender Date: Tue, 29 May 2018 20:32:58 +0200 Subject: [PATCH 31/45] linting: target: use isinstance() rather than type() for typecheck See pylint error messag C0123. Signed-off-by: Bastian Stender --- labgrid/target.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/labgrid/target.py b/labgrid/target.py index 0fa15ca90..35f31ca75 100644 --- a/labgrid/target.py +++ b/labgrid/target.py @@ -109,7 +109,7 @@ def get_resource(self, cls, *, name=None, await=True): """ found = [] other_names = [] - if type(cls) is str: + if isinstance(cls, str): cls = self._class_from_string(cls) for res in self.resources: @@ -142,7 +142,7 @@ def _get_driver(self, cls, *, name=None, activate=True, active=False): found = [] other_names = [] - if type(cls) is str: + if isinstance(cls, str): cls = self._class_from_string(cls) for drv in self.drivers: @@ -231,7 +231,7 @@ def __getitem__(self, key): cls = key elif len(key) == 2: cls, name = key - if type(cls) is str: + if isinstance(cls, str): cls = self._class_from_string(cls) if not issubclass(cls, (Driver, abc.ABC)): # all Protocols derive from ABC raise NoDriverFoundError( @@ -422,7 +422,7 @@ def deactivate(self, client): This is needed to ensure that no client has an inactive supplier. """ - if type(client) is str: + if isinstance(client, str): client = self._class_from_string(client) if client.state is BindingState.bound: From c7cefc2c0dd790644a9eea3e265317bd16da2019 Mon Sep 17 00:00:00 2001 From: Bastian Stender Date: Wed, 30 May 2018 10:43:28 +0200 Subject: [PATCH 32/45] linting: organize imports Order imports: standard libraries followed by external libraries followed by local imports Signed-off-by: Bastian Stender --- examples/hawkbit/test_hawkbit.py | 2 +- examples/library/test.py | 3 ++- labgrid/config.py | 4 ++-- labgrid/consoleloggingreporter.py | 2 +- labgrid/driver/common.py | 2 +- labgrid/driver/fastbootdriver.py | 2 +- labgrid/driver/modbusdriver.py | 1 - labgrid/driver/networkusbstoragedriver.py | 2 +- labgrid/driver/openocddriver.py | 2 +- labgrid/driver/power/gude.py | 4 ++-- labgrid/driver/power/gude24.py | 3 ++- labgrid/driver/quartushpsdriver.py | 2 +- labgrid/driver/shelldriver.py | 5 +---- labgrid/driver/usbloader.py | 2 +- labgrid/driver/usbsdmuxdriver.py | 2 +- labgrid/driver/usbstorage.py | 2 +- labgrid/driver/usbtmcdriver.py | 2 +- labgrid/driver/usbvideodriver.py | 2 +- labgrid/environment.py | 2 +- labgrid/external/__init__.py | 2 +- labgrid/pytestplugin/fixtures.py | 2 +- labgrid/remote/authenticator.py | 2 -- labgrid/remote/client.py | 8 ++++---- labgrid/remote/exporter.py | 2 -- labgrid/resource/ethernetport.py | 2 +- labgrid/resource/remote.py | 2 +- labgrid/resource/udev.py | 5 ++--- labgrid/strategy/__init__.py | 2 +- labgrid/util/qmp.py | 2 +- 29 files changed, 34 insertions(+), 41 deletions(-) diff --git a/examples/hawkbit/test_hawkbit.py b/examples/hawkbit/test_hawkbit.py index 2f9c65b3c..3272ea63f 100644 --- a/examples/hawkbit/test_hawkbit.py +++ b/examples/hawkbit/test_hawkbit.py @@ -1,5 +1,5 @@ -import pytest import time +import pytest from labgrid.external import HawkbitTestClient diff --git a/examples/library/test.py b/examples/library/test.py index acd3a124d..500afc6ce 100755 --- a/examples/library/test.py +++ b/examples/library/test.py @@ -2,12 +2,13 @@ """Power-cycle a target until the /dev/nand0 device is missing.""" import sys +import logging from labgrid import Environment, StepReporter from labgrid.strategy.bareboxstrategy import Status + # enable debug logging -import logging logging.basicConfig( level=logging.DEBUG, format='%(levelname)7s: %(message)s', diff --git a/labgrid/config.py b/labgrid/config.py index 85b67e995..0fac3fb0b 100644 --- a/labgrid/config.py +++ b/labgrid/config.py @@ -3,12 +3,12 @@ This class encapsulates access functions to the environment configuration """ -import attr import os +from yaml import YAMLError +import attr from .exceptions import NoConfigFoundError, InvalidConfigError from .util.yaml import load, resolve_templates -from yaml import YAMLError @attr.s(cmp=False) class Config: diff --git a/labgrid/consoleloggingreporter.py b/labgrid/consoleloggingreporter.py index 8fc977d70..dbb73684f 100644 --- a/labgrid/consoleloggingreporter.py +++ b/labgrid/consoleloggingreporter.py @@ -1,8 +1,8 @@ import os import sys +from datetime import datetime from .step import steps -from datetime import datetime class ConsoleLoggingReporter: diff --git a/labgrid/driver/common.py b/labgrid/driver/common.py index efd223822..ffcf1d3f7 100644 --- a/labgrid/driver/common.py +++ b/labgrid/driver/common.py @@ -1,5 +1,5 @@ -import attr import subprocess +import attr from ..binding import BindingError, BindingMixin from .exception import ExecutionError diff --git a/labgrid/driver/fastbootdriver.py b/labgrid/driver/fastbootdriver.py index 65bcedb88..b05f8f93c 100644 --- a/labgrid/driver/fastbootdriver.py +++ b/labgrid/driver/fastbootdriver.py @@ -1,7 +1,7 @@ # pylint: disable=no-member -import attr import subprocess import os.path +import attr from ..factory import target_factory from ..resource.remote import NetworkAndroidFastboot diff --git a/labgrid/driver/modbusdriver.py b/labgrid/driver/modbusdriver.py index 3b5dbf78b..d943239b7 100644 --- a/labgrid/driver/modbusdriver.py +++ b/labgrid/driver/modbusdriver.py @@ -1,5 +1,4 @@ from importlib import import_module - import attr from ..factory import target_factory diff --git a/labgrid/driver/networkusbstoragedriver.py b/labgrid/driver/networkusbstoragedriver.py index c6c9a1b50..ac4ef5a10 100644 --- a/labgrid/driver/networkusbstoragedriver.py +++ b/labgrid/driver/networkusbstoragedriver.py @@ -1,8 +1,8 @@ # pylint: disable=no-member -import attr import logging import subprocess import os +import attr from ..factory import target_factory from ..resource.udev import USBMassStorage, USBSDMuxDevice diff --git a/labgrid/driver/openocddriver.py b/labgrid/driver/openocddriver.py index f36a23382..5c309eda7 100644 --- a/labgrid/driver/openocddriver.py +++ b/labgrid/driver/openocddriver.py @@ -1,7 +1,7 @@ # pylint: disable=no-member -import attr import subprocess import os.path +import attr from ..factory import target_factory from ..protocol import BootstrapProtocol diff --git a/labgrid/driver/power/gude.py b/labgrid/driver/power/gude.py index a8e18bf89..7c77332c5 100644 --- a/labgrid/driver/power/gude.py +++ b/labgrid/driver/power/gude.py @@ -1,7 +1,7 @@ -from ..exception import ExecutionError - import requests +from ..exception import ExecutionError + def power_set(host, index, value): index = int(index) diff --git a/labgrid/driver/power/gude24.py b/labgrid/driver/power/gude24.py index 5411a3a2b..349581474 100644 --- a/labgrid/driver/power/gude24.py +++ b/labgrid/driver/power/gude24.py @@ -1,6 +1,7 @@ +import requests + from ..exception import ExecutionError -import requests # This driver implements a power port for Gude Power Switches with up to # 24 ports. diff --git a/labgrid/driver/quartushpsdriver.py b/labgrid/driver/quartushpsdriver.py index ba550d162..13710ba1d 100644 --- a/labgrid/driver/quartushpsdriver.py +++ b/labgrid/driver/quartushpsdriver.py @@ -1,8 +1,8 @@ # pylint: disable=no-member -import attr import subprocess import os.path import re +import attr from ..factory import target_factory from ..resource.remote import NetworkAlteraUSBBlaster diff --git a/labgrid/driver/shelldriver.py b/labgrid/driver/shelldriver.py index f2c7eeb80..25d3e9e12 100644 --- a/labgrid/driver/shelldriver.py +++ b/labgrid/driver/shelldriver.py @@ -4,13 +4,10 @@ import io import logging import re +import time import shlex - import attr from pexpect import TIMEOUT - -import time - import xmodem from ..factory import target_factory diff --git a/labgrid/driver/usbloader.py b/labgrid/driver/usbloader.py index a3a5f5d1c..552c17be5 100644 --- a/labgrid/driver/usbloader.py +++ b/labgrid/driver/usbloader.py @@ -1,7 +1,7 @@ # pylint: disable=no-member -import attr import subprocess import os.path +import attr from ..factory import target_factory from ..protocol import BootstrapProtocol diff --git a/labgrid/driver/usbsdmuxdriver.py b/labgrid/driver/usbsdmuxdriver.py index 984bfd3d4..8e41ef668 100644 --- a/labgrid/driver/usbsdmuxdriver.py +++ b/labgrid/driver/usbsdmuxdriver.py @@ -1,6 +1,6 @@ # pylint: disable=no-member -import attr import subprocess +import attr from .common import Driver from ..factory import target_factory diff --git a/labgrid/driver/usbstorage.py b/labgrid/driver/usbstorage.py index 05b131892..1ec2c5e4a 100644 --- a/labgrid/driver/usbstorage.py +++ b/labgrid/driver/usbstorage.py @@ -1,8 +1,8 @@ # pylint: disable=no-member import logging -import attr import os from time import time +import attr from ..factory import target_factory from ..resource.udev import USBMassStorage, USBSDMuxDevice diff --git a/labgrid/driver/usbtmcdriver.py b/labgrid/driver/usbtmcdriver.py index f32e4e9d0..95917988a 100644 --- a/labgrid/driver/usbtmcdriver.py +++ b/labgrid/driver/usbtmcdriver.py @@ -1,7 +1,7 @@ # pylint: disable=no-member -import attr from importlib import import_module from decimal import Decimal +import attr from .common import Driver from ..factory import target_factory diff --git a/labgrid/driver/usbvideodriver.py b/labgrid/driver/usbvideodriver.py index 61be7f312..97d0b32c3 100644 --- a/labgrid/driver/usbvideodriver.py +++ b/labgrid/driver/usbvideodriver.py @@ -1,6 +1,6 @@ # pylint: disable=no-member -import attr import subprocess +import attr from .common import Driver from ..factory import target_factory diff --git a/labgrid/environment.py b/labgrid/environment.py index 51afeae19..12138c76d 100644 --- a/labgrid/environment.py +++ b/labgrid/environment.py @@ -1,5 +1,5 @@ -import attr import os +import attr from .target import Target from .config import Config diff --git a/labgrid/external/__init__.py b/labgrid/external/__init__.py index f964a09c3..7585829e1 100644 --- a/labgrid/external/__init__.py +++ b/labgrid/external/__init__.py @@ -1,2 +1,2 @@ -from .hawkbit import * +from .hawkbit import HawkbitTestClient from .usbstick import USBStick diff --git a/labgrid/pytestplugin/fixtures.py b/labgrid/pytestplugin/fixtures.py index 37c38ad91..7e7f7aac0 100644 --- a/labgrid/pytestplugin/fixtures.py +++ b/labgrid/pytestplugin/fixtures.py @@ -1,6 +1,6 @@ import os -import pytest import subprocess +import pytest from .. import Environment from ..exceptions import NoResourceFoundError diff --git a/labgrid/remote/authenticator.py b/labgrid/remote/authenticator.py index e018b8f9c..d59abaa4f 100644 --- a/labgrid/remote/authenticator.py +++ b/labgrid/remote/authenticator.py @@ -1,7 +1,5 @@ from pprint import pprint - from twisted.internet.defer import inlineCallbacks - from autobahn.twisted.wamp import ApplicationSession diff --git a/labgrid/remote/client.py b/labgrid/remote/client.py index 8132eca1e..e7694ebc4 100755 --- a/labgrid/remote/client.py +++ b/labgrid/remote/client.py @@ -2,20 +2,19 @@ coordinator, acquire a place and interact with the connected resources""" import argparse import asyncio -import txaio import os import subprocess import traceback import logging import sys -from pprint import pformat from textwrap import indent from socket import gethostname from getpass import getuser from collections import defaultdict, OrderedDict from time import sleep from datetime import datetime - +from pprint import pformat +import txaio from autobahn.asyncio.wamp import ApplicationSession from .common import ResourceEntry, ResourceMatch, Place, enable_tcp_nodelay @@ -707,7 +706,8 @@ def bootstrap(self): target = self._get_target(place) from ..driver.usbloader import IMXUSBDriver, MXSUSBDriver from ..driver.openocddriver import OpenOCDDriver - from ..resource.remote import NetworkMXSUSBLoader, NetworkIMXUSBLoader, NetworkAlteraUSBBlaster + from ..resource.remote import (NetworkMXSUSBLoader, NetworkIMXUSBLoader, + NetworkAlteraUSBBlaster) drv = None for resource in target.resources: if isinstance(resource, NetworkIMXUSBLoader): diff --git a/labgrid/remote/exporter.py b/labgrid/remote/exporter.py index a30d23da4..6b12249b8 100755 --- a/labgrid/remote/exporter.py +++ b/labgrid/remote/exporter.py @@ -9,9 +9,7 @@ import subprocess from socket import gethostname, socket, AF_INET, SOCK_STREAM from contextlib import closing - import attr - from autobahn.asyncio.wamp import ApplicationRunner, ApplicationSession from .config import ResourceConfig diff --git a/labgrid/resource/ethernetport.py b/labgrid/resource/ethernetport.py index f0e083647..d47838b20 100644 --- a/labgrid/resource/ethernetport.py +++ b/labgrid/resource/ethernetport.py @@ -1,7 +1,7 @@ import logging import subprocess -import attr from time import time +import attr from ..factory import target_factory from .common import ManagedResource, ResourceManager diff --git a/labgrid/resource/remote.py b/labgrid/resource/remote.py index 09eba5af5..338680c63 100644 --- a/labgrid/resource/remote.py +++ b/labgrid/resource/remote.py @@ -1,6 +1,6 @@ import logging -import attr import os +import attr from ..factory import target_factory from .common import NetworkResource, ManagedResource, ResourceManager diff --git a/labgrid/resource/udev.py b/labgrid/resource/udev.py index 0a63d8db2..75983b55f 100644 --- a/labgrid/resource/udev.py +++ b/labgrid/resource/udev.py @@ -1,10 +1,9 @@ from functools import partial - -import attr import logging import os -import pyudev import warnings +import attr +import pyudev from ..factory import target_factory from .common import ManagedResource, ResourceManager diff --git a/labgrid/strategy/__init__.py b/labgrid/strategy/__init__.py index 64b878557..e84f558d4 100644 --- a/labgrid/strategy/__init__.py +++ b/labgrid/strategy/__init__.py @@ -2,4 +2,4 @@ from .bareboxstrategy import BareboxStrategy from .shellstrategy import ShellStrategy from .ubootstrategy import UBootStrategy -from .graphstrategy import * +from .graphstrategy import * # pylint: disable=wildcard-import diff --git a/labgrid/util/qmp.py b/labgrid/util/qmp.py index 1a3d5fef0..55fdbf0c8 100644 --- a/labgrid/util/qmp.py +++ b/labgrid/util/qmp.py @@ -1,6 +1,6 @@ import json -import attr import logging +import attr @attr.s(cmp=False) From 533cec4c061d4fd83132856fbf0b37154292fea0 Mon Sep 17 00:00:00 2001 From: Bastian Stender Date: Wed, 30 May 2018 22:27:06 +0200 Subject: [PATCH 33/45] linting: do miscellaneous linting Signed-off-by: Bastian Stender --- examples/hawkbit/test_hawkbit.py | 3 +- examples/strategy/bareboxrebootstrategy.py | 2 +- examples/usb/test_usb_mxs.py | 1 - examples/usbpower/cycle.py | 7 +- labgrid/autoinstall/main.py | 20 +++--- labgrid/config.py | 2 +- labgrid/consoleloggingreporter.py | 5 +- labgrid/driver/bareboxdriver.py | 2 +- labgrid/driver/commandmixin.py | 2 +- labgrid/driver/consoleexpectmixin.py | 2 +- labgrid/driver/exception.py | 10 ++- labgrid/driver/externalconsoledriver.py | 2 +- labgrid/driver/infodriver.py | 2 +- labgrid/driver/modbusdriver.py | 4 +- labgrid/driver/networkusbstoragedriver.py | 22 +++++-- labgrid/driver/onewiredriver.py | 2 +- labgrid/driver/openocddriver.py | 10 ++- labgrid/driver/power/gude.py | 5 +- labgrid/driver/power/netio.py | 2 +- labgrid/driver/power/netio_kshell.py | 2 +- labgrid/driver/power/simplerest.py | 4 +- labgrid/driver/powerdriver.py | 16 ++--- labgrid/driver/quartushpsdriver.py | 12 +++- labgrid/driver/serialdigitaloutput.py | 4 +- labgrid/driver/serialdriver.py | 2 +- labgrid/driver/shelldriver.py | 20 +++--- labgrid/driver/sigrokdriver.py | 16 ++--- labgrid/driver/smallubootdriver.py | 2 +- labgrid/driver/sshdriver.py | 19 +++--- labgrid/driver/ubootdriver.py | 2 +- labgrid/driver/usbsdmuxdriver.py | 9 ++- labgrid/driver/usbvideodriver.py | 18 ++--- labgrid/environment.py | 4 +- labgrid/exceptions.py | 5 +- labgrid/external/hawkbit.py | 2 +- labgrid/protocol/commandprotocol.py | 1 - labgrid/protocol/infoprotocol.py | 2 +- labgrid/pytestplugin/reporter.py | 2 +- labgrid/remote/client.py | 77 ++++++++++------------ labgrid/remote/common.py | 4 +- labgrid/remote/coordinator.py | 7 +- labgrid/remote/exporter.py | 14 ++-- labgrid/resource/ethernetport.py | 4 +- labgrid/resource/remote.py | 14 +++- labgrid/resource/serialport.py | 2 +- labgrid/resource/udev.py | 5 +- labgrid/resource/ykushpowerport.py | 2 +- labgrid/target.py | 4 +- labgrid/util/agent.py | 4 +- labgrid/util/agentwrapper.py | 1 - labgrid/util/dict.py | 3 +- labgrid/util/qmp.py | 2 +- tests/test_ethernetport.py | 1 + tests/test_usbtmc.py | 1 + tests/test_usbvideo.py | 1 + 55 files changed, 206 insertions(+), 187 deletions(-) diff --git a/examples/hawkbit/test_hawkbit.py b/examples/hawkbit/test_hawkbit.py index 3272ea63f..97d916176 100644 --- a/examples/hawkbit/test_hawkbit.py +++ b/examples/hawkbit/test_hawkbit.py @@ -3,13 +3,14 @@ from labgrid.external import HawkbitTestClient + @pytest.fixture() def hawkbit(): # Requires a hawkbit server instance to be running. # See: https://github.com/eclipse/hawkbit on how to set up # a test instance of hawkbit client = HawkbitTestClient("localhost", "8080", "admin", "admin") - assert(isinstance(client, HawkbitTestClient)) + assert isinstance(client, HawkbitTestClient) return client def test_upgrade(hawkbit): diff --git a/examples/strategy/bareboxrebootstrategy.py b/examples/strategy/bareboxrebootstrategy.py index 5f102fc1f..a9b1a298d 100644 --- a/examples/strategy/bareboxrebootstrategy.py +++ b/examples/strategy/bareboxrebootstrategy.py @@ -24,7 +24,7 @@ class Status(enum.Enum): @attr.s(cmp=False) class BareboxRebootStrategy(Strategy): """A Strategy to switch to barebox or shell and back via reboot - + In your env.yaml, simply instantiate the strategy without parameters, for example: .. code-block:: yaml diff --git a/examples/usb/test_usb_mxs.py b/examples/usb/test_usb_mxs.py index e71ec993e..96578eb3e 100644 --- a/examples/usb/test_usb_mxs.py +++ b/examples/usb/test_usb_mxs.py @@ -6,4 +6,3 @@ def test_usb(target): def test_mxs_load(target): bp = target.get_driver('BootstrapProtocol') bp.load() - diff --git a/examples/usbpower/cycle.py b/examples/usbpower/cycle.py index 02317f501..bf6ff4716 100644 --- a/examples/usbpower/cycle.py +++ b/examples/usbpower/cycle.py @@ -2,11 +2,10 @@ from labgrid.resource import USBPowerPort from labgrid.driver import USBPowerDriver + t = Target(name='main') -upp = USBPowerPort(t, - name=None, - match={'ID_PATH': 'pci-0000:00:14.0-usb-0:2:1.0'}, - index=1) +upp = USBPowerPort(t, name=None, + match={'ID_PATH': 'pci-0000:00:14.0-usb-0:2:1.0'}, index=1) upd = USBPowerDriver(t, name=None) t.activate(upd) diff --git a/labgrid/autoinstall/main.py b/labgrid/autoinstall/main.py index e637f0d0f..d1ba5eda5 100644 --- a/labgrid/autoinstall/main.py +++ b/labgrid/autoinstall/main.py @@ -90,7 +90,7 @@ def run_once(self): try: if self.initial_resource: self.log.info("waiting until %s is available", - self.initial_resource.display_name) + self.initial_resource.display_name) while True: self.target.update_resources() if self.initial_resource.avail: @@ -101,13 +101,13 @@ def run_once(self): self.target.update_resources() result = self.handler() if result is not None: - self.log.warn("unexpected return value from handler: %s", - repr(result)) + self.log.warning("unexpected return value from handler: %s", + repr(result)) self.log.info("completed handler") if self.initial_resource: self.log.info("waiting until %s is unavailable", - self.initial_resource.display_name) + self.initial_resource.display_name) while True: self.target.update_resources() if not self.initial_resource.avail: @@ -117,10 +117,10 @@ def run_once(self): except NoResourceFoundError as e: if e.filter and len(e.filter) > 1: self.log.warning("resources %s not found, restarting", - e.filter) + e.filter) elif e.filter: self.log.warning("resource %s not found, restarting", - next(iter(e.filter))) + next(iter(e.filter))) else: self.log.warning("resource not found, restarting") except: @@ -144,22 +144,22 @@ def __init__(self, env, args): def configure(self): if not 'autoinstall' in self.env.config.data: self.log.error("no 'autoinstall' section found in '%s'", - self.env.config_file) + self.env.config_file) return False if not 'handler' in self.env.config.data['autoinstall']: self.log.error("no 'handler' definition found in '%s'", - self.env.config_file) + self.env.config_file) return False self.handlers = {} for target_name in self.config.data.get('targets', {}).keys(): self.handlers[target_name] = Handler(self.env, self.args, - target_name) + target_name) if not self.handlers: self.log.error("no targets found in '%s'", - self.env.config_file) + self.env.config_file) return False return True diff --git a/labgrid/config.py b/labgrid/config.py index 0fac3fb0b..dd1139474 100644 --- a/labgrid/config.py +++ b/labgrid/config.py @@ -33,7 +33,7 @@ def __attrs_post_init__(self): # map LG_* variables from OS environment into YAML config file using !template $LG_* # Only map LG_*, to protect from weird things in environment for x in os.environ.keys(): - if x.startswith( "LG_" ): + if x.startswith("LG_"): substitutions[x] = os.environ[x] try: diff --git a/labgrid/consoleloggingreporter.py b/labgrid/consoleloggingreporter.py index dbb73684f..3e511ba67 100644 --- a/labgrid/consoleloggingreporter.py +++ b/labgrid/consoleloggingreporter.py @@ -52,9 +52,8 @@ def get_logfile(self, event): name = 'console_{}'.format(source.target.name) name = os.path.join(self.logpath, name) try: - log = self._logcache[source] = open( - name, mode='ab', buffering=0 - ) + log = self._logcache[source] = open(name, mode='ab', + buffering=0) except PermissionError: print("failed to open log file {}".format(name), file=sys.stderr) log = self._logcache[source] = None diff --git a/labgrid/driver/bareboxdriver.py b/labgrid/driver/bareboxdriver.py index 3262d79ff..89cb64d90 100644 --- a/labgrid/driver/bareboxdriver.py +++ b/labgrid/driver/bareboxdriver.py @@ -30,7 +30,7 @@ class BareboxDriver(CommandMixin, Driver, CommandProtocol, LinuxBootProtocol): autoboot = attr.ib(default="stop autoboot", validator=attr.validators.instance_of(str)) interrupt = attr.ib(default="\n", validator=attr.validators.instance_of(str)) startstring = attr.ib(default=r"[\n]barebox 20\d+", validator=attr.validators.instance_of(str)) - bootstring = attr.ib(default="Linux version \d", validator=attr.validators.instance_of(str)) + bootstring = attr.ib(default=r"Linux version \d", validator=attr.validators.instance_of(str)) def __attrs_post_init__(self): super().__attrs_post_init__() diff --git a/labgrid/driver/commandmixin.py b/labgrid/driver/commandmixin.py index d369a54a2..2ea368634 100644 --- a/labgrid/driver/commandmixin.py +++ b/labgrid/driver/commandmixin.py @@ -52,4 +52,4 @@ def run_check(self, cmd: str, timeout=30): Returns: List[str]: stdout of the executed command """ - return self._run_check(cmd,timeout) + return self._run_check(cmd, timeout) diff --git a/labgrid/driver/consoleexpectmixin.py b/labgrid/driver/consoleexpectmixin.py index 221b5498b..cc45eaeff 100644 --- a/labgrid/driver/consoleexpectmixin.py +++ b/labgrid/driver/consoleexpectmixin.py @@ -22,7 +22,7 @@ def __attrs_post_init__(self): def read(self, size=1, timeout=0.0): res = self._read(size=size, timeout=timeout) self.logger.debug("Read %i bytes: %s, timeout %.2f, requested size %i", - len(res), res, timeout, size) + len(res), res, timeout, size) return res @Driver.check_active diff --git a/labgrid/driver/exception.py b/labgrid/driver/exception.py index d7856cba1..98874dc0e 100644 --- a/labgrid/driver/exception.py +++ b/labgrid/driver/exception.py @@ -4,8 +4,14 @@ @attr.s(cmp=False) class ExecutionError(Exception): msg = attr.ib(validator=attr.validators.instance_of(str)) - stdout = attr.ib(default=None, validator=attr.validators.optional(attr.validators.instance_of(list))) - stderr = attr.ib(default=None, validator=attr.validators.optional(attr.validators.instance_of(list))) + stdout = attr.ib( + default=None, + validator=attr.validators.optional(attr.validators.instance_of(list)) + ) + stderr = attr.ib( + default=None, + validator=attr.validators.optional(attr.validators.instance_of(list)) + ) @attr.s(cmp=False) diff --git a/labgrid/driver/externalconsoledriver.py b/labgrid/driver/externalconsoledriver.py index 2ce4d1ed9..9ac9eae08 100644 --- a/labgrid/driver/externalconsoledriver.py +++ b/labgrid/driver/externalconsoledriver.py @@ -67,7 +67,7 @@ def close(self): if errs: self.logger.warning("child error while closing: %s", errs) - def _read(self, size: int=1024, timeout: int=0): + def _read(self, size: int = 1024, timeout: int = 0): """ Reads 'size' bytes from the serialport diff --git a/labgrid/driver/infodriver.py b/labgrid/driver/infodriver.py index 10e16fdf3..fc568f128 100644 --- a/labgrid/driver/infodriver.py +++ b/labgrid/driver/infodriver.py @@ -18,7 +18,7 @@ class InfoDriver(Driver, InfoProtocol): # TODO: rework CommandProtocol binding to select correct underlying driver # (No UBoot/BareboxDriver, SSH > Serial,…) - bindings = { 'command': CommandProtocol } + bindings = {'command': CommandProtocol} def __attrs_post_init__(self): super().__attrs_post_init__() diff --git a/labgrid/driver/modbusdriver.py b/labgrid/driver/modbusdriver.py index d943239b7..054df058a 100644 --- a/labgrid/driver/modbusdriver.py +++ b/labgrid/driver/modbusdriver.py @@ -18,8 +18,8 @@ def __attrs_post_init__(self): host = self.coil.host if ':' in host: host, port = host.split(':', 1) - self.client = self._module.ModbusClient(host=host, - port=int(port), auto_open=True, auto_close=True) + self.client = self._module.ModbusClient( + host=host, port=int(port), auto_open=True, auto_close=True) @Driver.check_active def set(self, status): diff --git a/labgrid/driver/networkusbstoragedriver.py b/labgrid/driver/networkusbstoragedriver.py index ac4ef5a10..fe5c0ea5a 100644 --- a/labgrid/driver/networkusbstoragedriver.py +++ b/labgrid/driver/networkusbstoragedriver.py @@ -13,7 +13,14 @@ @target_factory.reg_driver @attr.s(cmp=False) class NetworkUSBStorageDriver(Driver): - bindings = {"storage": {USBMassStorage, NetworkUSBMassStorage, USBSDMuxDevice, NetworkUSBSDMuxDevice}, } + bindings = { + "storage": { + USBMassStorage, + NetworkUSBMassStorage, + USBSDMuxDevice, + NetworkUSBSDMuxDevice + }, + } def __attrs_post_init__(self): super().__attrs_post_init__() @@ -30,13 +37,18 @@ def write_image(self, filename): filename = os.path.abspath(filename) check_file(filename, command_prefix=self.storage.command_prefix) self.logger.info("pwd: %s", os.getcwd()) + args = ( + "dd", + "if={}".format(filename), + "of={} status=progress bs=4M conv=fdatasync" + .format(self.storage.path) + ) subprocess.check_call( - self.storage.command_prefix+["dd", "if=%s" % filename, "of=%s status=progress bs=4M conv=fdatasync" % self.storage.path] + self.storage.command_prefix + args ) @step(result=True) def get_size(self): - size = subprocess.check_output( - self.storage.command_prefix+["cat", "/sys/class/block/%s/size" % self.storage.path[5:]] - ) + args = ("cat", "/sys/class/block/{}/size" % self.storage.path[5:]) + size = subprocess.check_output(self.storage.command_prefix + args) return int(size) diff --git a/labgrid/driver/onewiredriver.py b/labgrid/driver/onewiredriver.py index 91d37b531..b54024d7d 100644 --- a/labgrid/driver/onewiredriver.py +++ b/labgrid/driver/onewiredriver.py @@ -20,7 +20,7 @@ def __attrs_post_init__(self): def set(self, status): if self.port.invert: status = not status - if status == True: + if status: self.onewire.set(self.port.path, '1') else: self.onewire.set(self.port.path, '0') diff --git a/labgrid/driver/openocddriver.py b/labgrid/driver/openocddriver.py index 5c309eda7..719442aef 100644 --- a/labgrid/driver/openocddriver.py +++ b/labgrid/driver/openocddriver.py @@ -19,8 +19,14 @@ class OpenOCDDriver(Driver, BootstrapProtocol): } config = attr.ib(validator=attr.validators.instance_of(str)) - search = attr.ib(default=None, validator=attr.validators.optional(attr.validators.instance_of(str))) - image = attr.ib(default=None, validator=attr.validators.optional(attr.validators.instance_of(str))) + search = attr.ib( + default=None, + validator=attr.validators.optional(attr.validators.instance_of(str)) + ) + image = attr.ib( + default=None, + validator=attr.validators.optional(attr.validators.instance_of(str)) + ) def __attrs_post_init__(self): super().__attrs_post_init__() diff --git a/labgrid/driver/power/gude.py b/labgrid/driver/power/gude.py index 7c77332c5..2b333d7c0 100644 --- a/labgrid/driver/power/gude.py +++ b/labgrid/driver/power/gude.py @@ -21,8 +21,9 @@ def power_get(host, index): r = requests.get("http://{}/".format(host)) r.raise_for_status() for line in r.text.splitlines(): - if line.find("Power Port {}".format(index) - ) > 0 or line.find("SwitchPort {}".format(index)) > 0: + power_pattern = "Power Port {}".format(index) + switch_patern = "SwitchPort {}".format(index) + if line.find(power_pattern) > 0 or line.find(switch_patern) > 0: if line.find("OFF") > 0: return False elif line.find("ON") > 0: diff --git a/labgrid/driver/power/netio.py b/labgrid/driver/power/netio.py index e090104c3..8a4059085 100644 --- a/labgrid/driver/power/netio.py +++ b/labgrid/driver/power/netio.py @@ -23,7 +23,7 @@ def power_get(host, index): # get the contents of the main page r = requests.get("http://" + host + "/tgi/control.tgi?l=p:admin:admin&p=l") r.raise_for_status() - m = re.match(".*(\d) (\d) (\d) (\d).*", r.text) + m = re.match(r".*(\d) (\d) (\d) (\d).*", r.text) states = {"0": False, "1": True} value = m.group(index) return states[value] diff --git a/labgrid/driver/power/netio_kshell.py b/labgrid/driver/power/netio_kshell.py index 83f10f5e8..8adb01160 100644 --- a/labgrid/driver/power/netio_kshell.py +++ b/labgrid/driver/power/netio_kshell.py @@ -27,7 +27,7 @@ def power_get(host, index): tn.read_until(b"250 OK\r\n", 0.5) tn.write("port {}\n".format(index).encode()) read = tn.read_until(b"\r\n", 0.5) - m = re.match(".*250 (\d).*", read.decode()) + m = re.match(r".*250 (\d).*", read.decode()) if m is None: raise Exception("NetIO: could not match response") value = m.group(1) diff --git a/labgrid/driver/power/simplerest.py b/labgrid/driver/power/simplerest.py index 78cc2185f..25ef07acb 100644 --- a/labgrid/driver/power/simplerest.py +++ b/labgrid/driver/power/simplerest.py @@ -15,11 +15,11 @@ def power_set(host, index, value): index = int(index) value = 1 if value else 0 - r = requests.get(host.format(value=value,index=index)) + requests.get(host.format(value=value, index=index)) def power_get(host, index): index = int(index) # remove trailing / - r = requests.get(host.format(value='',index=index).rstrip('/')) + r = requests.get(host.format(value='', index=index).rstrip('/')) r.raise_for_status() return r.text == '1' diff --git a/labgrid/driver/powerdriver.py b/labgrid/driver/powerdriver.py index 218b3f386..dc6ab0fb1 100644 --- a/labgrid/driver/powerdriver.py +++ b/labgrid/driver/powerdriver.py @@ -221,11 +221,11 @@ def __attrs_post_init__(self): def _switch(self, cmd): cmd = self.hub.command_prefix + [ - self.tool, - "-l", self.hub.path, - "-p", str(self.hub.index), - "-r", "100", # use 100 retries for now - "-a", cmd, + self.tool, + "-l", self.hub.path, + "-p", str(self.hub.index), + "-r", "100", # use 100 retries for now + "-a", cmd, ] subprocess.check_call(cmd) @@ -249,9 +249,9 @@ def cycle(self): @Driver.check_active def get(self): cmd = self.hub.command_prefix + [ - self.tool, - "-l", self.hub.path, - "-p", str(self.hub.index), + self.tool, + "-l", self.hub.path, + "-p", str(self.hub.index), ] output = subprocess.check_output(cmd) for line in output.splitlines(): diff --git a/labgrid/driver/quartushpsdriver.py b/labgrid/driver/quartushpsdriver.py index 13710ba1d..de3d1dcd6 100644 --- a/labgrid/driver/quartushpsdriver.py +++ b/labgrid/driver/quartushpsdriver.py @@ -19,8 +19,14 @@ class QuartusHPSDriver(Driver): "interface": {AlteraUSBBlaster, NetworkAlteraUSBBlaster}, } - image = attr.ib(default=None, validator=attr.validators.optional(attr.validators.instance_of(str))) - cable_number = attr.ib(default=None, validator=attr.validators.optional(attr.validators.instance_of(str))) + image = attr.ib( + default=None, + validator=attr.validators.optional(attr.validators.instance_of(str)) + ) + cable_number = attr.ib( + default=None, + validator=attr.validators.optional(attr.validators.instance_of(str)) + ) def __attrs_post_init__(self): super().__attrs_post_init__() @@ -68,7 +74,7 @@ def flash(self, filename=None, address=0x0): filename = os.path.abspath(os.path.expanduser(filename)) check_file(filename, command_prefix=self.interface.command_prefix) - assert(isinstance(address, int)) + assert isinstance(address, int) if self.cable_number is None: self.cable_number = self._get_cable_number() diff --git a/labgrid/driver/serialdigitaloutput.py b/labgrid/driver/serialdigitaloutput.py index 331a7c794..cdffa1acf 100644 --- a/labgrid/driver/serialdigitaloutput.py +++ b/labgrid/driver/serialdigitaloutput.py @@ -23,7 +23,7 @@ class SerialPortDigitalOutputDriver(Driver, DigitalOutputProtocol): """ bindings = {'serial': SerialDriver} - signal= attr.ib(validator=attr.validators.instance_of(str)) + signal = attr.ib(validator=attr.validators.instance_of(str)) def __attrs_post_init__(self): super().__attrs_post_init__() @@ -38,7 +38,7 @@ def __attrs_post_init__(self): @Driver.check_active @step() def get(self): - if self.signal == "dtr": + if self.signal == "dtr": return self._p.dtr elif self.signal == "rts": return self._p.rts diff --git a/labgrid/driver/serialdriver.py b/labgrid/driver/serialdriver.py index 11b58d25a..075c0c7c3 100644 --- a/labgrid/driver/serialdriver.py +++ b/labgrid/driver/serialdriver.py @@ -58,7 +58,7 @@ def on_activate(self): def on_deactivate(self): self.close() - def _read(self, size: int=1, timeout: float=0.0): + def _read(self, size: int = 1, timeout: float = 0.0): """ Reads 'size' or more bytes from the serialport diff --git a/labgrid/driver/shelldriver.py b/labgrid/driver/shelldriver.py index 25d3e9e12..ab7aed7e4 100644 --- a/labgrid/driver/shelldriver.py +++ b/labgrid/driver/shelldriver.py @@ -48,9 +48,9 @@ def __attrs_post_init__(self): super().__attrs_post_init__() self.re_vt100 = re.compile( r'(\x1b\[|\x9b)[^@-_a-z]*[@-_a-z]|\x1b[@-_a-z]' - ) #pylint: disable=attribute-defined-outside-init,anomalous-backslash-in-string + ) # pylint: disable=attribute-defined-outside-init,anomalous-backslash-in-string self.logger = logging.getLogger("{}:{}".format(self, self.target)) - self._status = 0 #pylint: disable=attribute-defined-outside-init + self._status = 0 # pylint: disable=attribute-defined-outside-init self._xmodem_cached_rx_cmd = "" self._xmodem_cached_sx_cmd = "" @@ -240,7 +240,7 @@ def _put_ssh_key(self, keyfile_path): if test_write == 0: self.logger.debug("Key not on target, testing for .ssh directory") _, _, ssh_dir = self._run("[ -d ~/.ssh/ ]") - if not ssh_dir == 0: + if ssh_dir != 0: self.logger.debug("~/.ssh did not exist, creating") self._run("mkdir ~/.ssh/") self._run_check("chmod 700 ~/.ssh/") @@ -367,7 +367,7 @@ def _target_cleanup(tmpfile): _target_cleanup(tmpfile) if ret != 0: raise ExecutionError('Could not truncate destination file: dd returned {}: {}'. - format(ret, out)) + format(ret, out)) @Driver.check_active def put_bytes(self, buf: bytes, remotefile: str): @@ -430,7 +430,7 @@ def _get_bytes(self, remotefile: str): # remove CPMEOF (0x1a) padding if recvd_size < file_size: raise ExecutionError('Only received {} bytes of {} expected'. - format(recvd_size, file_size)) + format(recvd_size, file_size)) self.logger.debug('received %d bytes of payload', file_size) buf.truncate(file_size) @@ -479,14 +479,14 @@ def get(self, remotefile: str, localfile: str): self._get(remotefile, localfile) @step(title='run_script', args=['data', 'timeout']) - def _run_script(self, data: bytes, timeout: int=60): + def _run_script(self, data: bytes, timeout: int = 60): hardcoded_remote_file = '/tmp/labgrid-run-script' self._put_bytes(data, hardcoded_remote_file) self._run_check("chmod +x '{}'".format(hardcoded_remote_file)) return self._run(hardcoded_remote_file, timeout=timeout) @Driver.check_active - def run_script(self, data: bytes, timeout: int=60): + def run_script(self, data: bytes, timeout: int = 60): """ Upload a script to the target and run it. Args: @@ -503,17 +503,17 @@ def run_script(self, data: bytes, timeout: int=60): self._run_script(data, timeout) @step(title='run_script_file', args=['scriptfile', 'timeout', 'args']) - def _run_script_file(self, scriptfile: str, *args, timeout: int=60): + def _run_script_file(self, scriptfile: str, *args, timeout: int = 60): hardcoded_remote_file = '/tmp/labgrid-run-script' self._put(scriptfile, hardcoded_remote_file) self._run_check("chmod +x '{}'".format(hardcoded_remote_file)) - shargs = [ shlex.quote(a) for a in args ] + shargs = [shlex.quote(a) for a in args] cmd = "{} {}".format(hardcoded_remote_file, ' '.join(shargs)) return self._run(cmd, timeout=timeout) @Driver.check_active - def run_script_file(self, scriptfile: str, *args, timeout: int=60): + def run_script_file(self, scriptfile: str, *args, timeout: int = 60): """ Upload a script file to the target and run it. Args: diff --git a/labgrid/driver/sigrokdriver.py b/labgrid/driver/sigrokdriver.py index 3b5c3e0c3..49a105351 100644 --- a/labgrid/driver/sigrokdriver.py +++ b/labgrid/driver/sigrokdriver.py @@ -141,20 +141,16 @@ def capture(self, filename, samplerate="200k"): filename = os.path.join(self._tmpdir, self._basename) cmd.append(filename) self._call_with_driver(*cmd) - while subprocess.call( - self.sigrok.command_prefix + [ - 'test', - '-e', - filename, - ] - ): + args = self.sigrok.command_prefix + ['test', '-e', filename] + + while subprocess.call(args): sleep(0.1) self._running = True @Driver.check_active def stop(self): - assert self._running == True + assert self._running self._running = False fnames = ['time'] fnames.extend(self.sigrok.channels.split(',')) @@ -214,9 +210,7 @@ def stop(self): @Driver.check_active def analyze(self, args, filename=None): - annotation_regex = re.compile( - r'(?P\d+)-(?P\d+) (?P[\w\-]+): (?P[\w\-]+): (?P".*)' - ) + annotation_regex = re.compile(r'(?P\d+)-(?P\d+) (?P[\w\-]+): (?P[\w\-]+): (?P".*)') # pylint: disable=line-too-long if not filename and self._filename: filename = self._filename else: diff --git a/labgrid/driver/smallubootdriver.py b/labgrid/driver/smallubootdriver.py index 5cc10aa5e..6656dd019 100644 --- a/labgrid/driver/smallubootdriver.py +++ b/labgrid/driver/smallubootdriver.py @@ -90,7 +90,7 @@ def _run(self, cmd): data = self.re_vt100.sub( '', before.decode('utf-8'), count=1000000 - ).replace("\r","").split("\n") + ).replace("\r", "").split("\n") data = data[1:] data = data[data.index("Unknown command 'echo{}' - try 'help'".format(marker)) +1 :] data = data[:data.index("Unknown command 'echo{}' - try 'help'".format(marker))] diff --git a/labgrid/driver/sshdriver.py b/labgrid/driver/sshdriver.py index 650eca1b9..9fa59235a 100644 --- a/labgrid/driver/sshdriver.py +++ b/labgrid/driver/sshdriver.py @@ -31,9 +31,9 @@ def __attrs_post_init__(self): def on_activate(self): self.ssh_prefix = "-o LogLevel=ERROR" self.ssh_prefix += " -i {}".format(os.path.abspath(self.keyfile) - ) if self.keyfile else "" + ) if self.keyfile else "" self.ssh_prefix += " -o PasswordAuthentication=no" if ( - not self.networkservice.password) else "" + not self.networkservice.password) else "" self.control = self._check_master() self.ssh_prefix += " -F /dev/null" self.ssh_prefix += " -o ControlPath={}".format( @@ -51,12 +51,9 @@ def _start_own_master(self): ) # use sshpass if we have a password sshpass = "sshpass -e " if self.networkservice.password else "" - args = ("{}ssh -n {} -x -o ConnectTimeout=30 -o ControlPersist=300 " - "-o UserKnownHostsFile=/dev/null " - "-o StrictHostKeyChecking=no -MN -S {} {}@{}").format( - sshpass, self.ssh_prefix, control, - self.networkservice.username, self.networkservice.address - ).split(" ") + args = ("{}ssh -n {} -x -o ConnectTimeout=30 -o ControlPersist=300 -o UserKnownHostsFile=/dev/null " "-o StrictHostKeyChecking=no -MN -S {} {}@{}").format( # pylint: disable=line-too-long + sshpass, self.ssh_prefix, control, self.networkservice.username, + self.networkservice.address).split(" ") env = os.environ.copy() if self.networkservice.password: @@ -70,9 +67,9 @@ def _start_own_master(self): format(self.networkservice.address, args, self.process.wait()) ) except subprocess.TimeoutExpired: - raise ExecutionError( - "failed to connect to {} with {} and {}". - format(self.networkservice.address, args, self.process.wait()) + raise ExecutionError( + "failed to connect to {} with {} and {}". + format(self.networkservice.address, args, self.process.wait()) ) if not os.path.exists(control): diff --git a/labgrid/driver/ubootdriver.py b/labgrid/driver/ubootdriver.py index a67ff2885..019dbe0ce 100644 --- a/labgrid/driver/ubootdriver.py +++ b/labgrid/driver/ubootdriver.py @@ -82,7 +82,7 @@ def _run(self, cmd): # Remove VT100 Codes and split by newline data = self.re_vt100.sub( '', before.decode('utf-8'), count=1000000 - ).replace("\r","").split("\n") + ).replace("\r", "").split("\n") self.logger.debug("Received Data: %s", data) # Remove first element, the invoked cmd data = data[data.index(marker) + 1:] diff --git a/labgrid/driver/usbsdmuxdriver.py b/labgrid/driver/usbsdmuxdriver.py index 8e41ef668..ad1a23030 100644 --- a/labgrid/driver/usbsdmuxdriver.py +++ b/labgrid/driver/usbsdmuxdriver.py @@ -33,13 +33,12 @@ def __attrs_post_init__(self): @Driver.check_active @step(title='sdmux_set', args=['mode']) def set_mode(self, mode): - '' if not mode.lower() in ['dut', 'host', 'off', 'client']: raise ExecutionError("Setting mode '%s' not supported by USBSDMuxDriver" % mode) cmd = self.mux.command_prefix + [ - self.tool, - "-c", - self.mux.control_path, - mode.lower() + self.tool, + "-c", + self.mux.control_path, + mode.lower() ] subprocess.check_call(cmd) diff --git a/labgrid/driver/usbvideodriver.py b/labgrid/driver/usbvideodriver.py index 97d0b32c3..804671122 100644 --- a/labgrid/driver/usbvideodriver.py +++ b/labgrid/driver/usbvideodriver.py @@ -43,14 +43,16 @@ def stream(self, caps_hint=None): rx_cmd = ["gst-launch-1.0"] rx_cmd += "fdsrc ! h264parse ! avdec_h264 ! glimagesink sync=false".split() - tx = subprocess.Popen(tx_cmd, - stdin=subprocess.DEVNULL, - stdout=subprocess.PIPE, - ) - rx = subprocess.Popen(rx_cmd, - stdin=tx.stdout, - stdout=subprocess.DEVNULL, - ) + tx = subprocess.Popen( + tx_cmd, + stdin=subprocess.DEVNULL, + stdout=subprocess.PIPE, + ) + rx = subprocess.Popen( + rx_cmd, + stdin=tx.stdout, + stdout=subprocess.DEVNULL, + ) # wait until one subprocess has termianted while True: diff --git a/labgrid/environment.py b/labgrid/environment.py index 12138c76d..069c895d4 100644 --- a/labgrid/environment.py +++ b/labgrid/environment.py @@ -27,14 +27,14 @@ def __attrs_post_init__(self): module = SourceFileLoader(module_name, user_import).load_module() sys.modules[module_name] = module - def get_target(self, role: str='main') -> Target: + def get_target(self, role: str = 'main') -> Target: """Returns the specified target or None if not found. Each target is initialized as needed. """ from . import target_factory - if not role in self.targets: + if role not in self.targets: config = self.config.get_targets().get(role) if not config: return None diff --git a/labgrid/exceptions.py b/labgrid/exceptions.py index 2816d1841..bc1fa9e6c 100644 --- a/labgrid/exceptions.py +++ b/labgrid/exceptions.py @@ -9,7 +9,10 @@ class NoConfigFoundError(Exception): @attr.s(cmp=False) class NoSupplierFoundError(Exception): msg = attr.ib(validator=attr.validators.instance_of(str)) - filter = attr.ib(default=None, validator=attr.validators.optional(attr.validators.instance_of(set))) + filter = attr.ib( + default=None, + validator=attr.validators.optional(attr.validators.instance_of(set)) + ) @attr.s(cmp=False) diff --git a/labgrid/external/hawkbit.py b/labgrid/external/hawkbit.py index f287077fb..af34db6ad 100644 --- a/labgrid/external/hawkbit.py +++ b/labgrid/external/hawkbit.py @@ -70,7 +70,7 @@ def add_distributionset(self, module_id, name=None): }] self.distribution_id = self.post_json('distributionsets', - testdata)[0]['id'] + testdata)[0]['id'] return self.distribution_id def delete_distributionset(self, distset_id: str): diff --git a/labgrid/protocol/commandprotocol.py b/labgrid/protocol/commandprotocol.py index d0fba4b88..51abd7a98 100644 --- a/labgrid/protocol/commandprotocol.py +++ b/labgrid/protocol/commandprotocol.py @@ -31,4 +31,3 @@ def wait_for(self): Wait for a shell command to return with the specified output """ raise NotImplementedError - diff --git a/labgrid/protocol/infoprotocol.py b/labgrid/protocol/infoprotocol.py index f2ad5b331..735b89d47 100644 --- a/labgrid/protocol/infoprotocol.py +++ b/labgrid/protocol/infoprotocol.py @@ -5,7 +5,7 @@ class InfoProtocol(abc.ABC): """Abstract class providing the InfoProtocol interface""" @abc.abstractmethod - def get_ip(self, interface: str='eth0'): + def get_ip(self, interface: str = 'eth0'): """Implementations should return the IP-adress for the supplied interface.""" raise NotImplementedError diff --git a/labgrid/pytestplugin/reporter.py b/labgrid/pytestplugin/reporter.py index d1f16732c..02728b3a7 100644 --- a/labgrid/pytestplugin/reporter.py +++ b/labgrid/pytestplugin/reporter.py @@ -72,7 +72,7 @@ def notify(self, event): return new = not self.rewrite - if not(self.cur_step is event.step): + if self.cur_step is not event.step: new = True if self.cur_resource is not event.resource: new = True diff --git a/labgrid/remote/client.py b/labgrid/remote/client.py index e7694ebc4..0ec5e4a2e 100755 --- a/labgrid/remote/client.py +++ b/labgrid/remote/client.py @@ -124,8 +124,8 @@ async def on_place_changed(self, name, config): return config = config.copy() config['name'] = name - config['matches' - ] = [ResourceMatch(**match) for match in config['matches']] + config['matches'] = [ResourceMatch(**match) \ + for match in config['matches']] config = filter_dict(config, Place, warn=True) place = Place(**config) if name not in self.places: @@ -171,8 +171,10 @@ async def print_resources(self): continue if self.args.acquired and resource.acquired is None: continue - if match and not match.ismatch((exporter, group_name, resource.cls, resource_name)): + if match and not match.ismatch((exporter, group_name, + resource.cls, resource_name)): continue + filtered[exporter][group_name][resource_name] = resource # print the filtered resources @@ -182,7 +184,8 @@ async def print_resources(self): for group_name, group in sorted(groups.items()): print(" Group '{}' ({}/{}/*):".format(group_name, exporter, group_name)) for resource_name, resource in sorted(group.items()): - print(" Resource '{}' ({}/{}/{}[/{}]):".format(resource_name, exporter, group_name, resource.cls, resource_name)) + print(" Resource '{}' ({}/{}/{}[/{}]):".format( + resource_name, exporter, group_name, resource.cls, resource_name)) print(indent(pformat(resource.asdict()), prefix=" ")) else: for exporter, groups in sorted(filtered.items()): @@ -260,7 +263,8 @@ def get_place(self, place=None): def get_idle_place(self, place=None): place = self.get_place(place) if place.acquired: - raise UserError("place {} is not idle (acquired by {})".format(place.name, place.acquired)) + raise UserError("place {} is not idle (acquired by {})".format( + place.name, place.acquired)) return place def get_acquired_place(self, place=None): @@ -270,9 +274,11 @@ def get_acquired_place(self, place=None): if gethostname()+'/'+getuser() not in place.allowed: host, user = place.acquired.split('/') if user != getuser(): - raise UserError("place {} is not acquired by your user, acquired by {}".format(place.name, user)) + raise UserError("place {} is not acquired by your user, acquired by {}".format( + place.name, user)) if host != gethostname(): - raise UserError("place {} is not acquired on this computer, acquired on {}".format(place.name, host)) + raise UserError("place {} is not acquired on this computer, acquired on {}".format( + place.name, host)) return place async def print_place(self): @@ -386,7 +392,7 @@ async def add_match(self): if pattern in map(repr, place.matches): print("pattern '{}' exists, skipping".format(pattern)) continue - if not (2 <= pattern.count("/") <= 3): + if not 2 <= pattern.count("/") <= 3: raise UserError( "invalid pattern format '{}' (use 'exporter/group/cls/name')". format(pattern) @@ -408,7 +414,7 @@ async def del_match(self): if pattern not in map(repr, place.matches): print("pattern '{}' not found, skipping".format(pattern)) continue - if not (2 <= pattern.count("/") <= 3): + if not 2 <= pattern.count("/") <= 3: raise UserError( "invalid pattern format '{}' (use 'exporter/group/cls/name')". format(pattern) @@ -433,7 +439,7 @@ async def add_named_match(self): name = self.args.name if pattern in map(repr, place.matches): raise UserError("pattern '{}' exists".format(pattern)) - if not (2 <= pattern.count("/") <= 3): + if not 2 <= pattern.count("/") <= 3: raise UserError( "invalid pattern format '{}' (use 'exporter/group/cls/name')". format(pattern) @@ -480,9 +486,7 @@ async def release(self): host, user = place.acquired.split('/') if user != getuser(): if not self.args.kick: - raise UserError( - "place {} is acquired by a different user ({}), use --kick if you are sure".format(place.name, place.acquired) - ) + raise UserError("place {} is acquired by a different user ({}), use --kick if you are sure".format(place.name, place.acquired)) # pylint: disable=line-too-long print("warning: kicking user ({})".format(place.acquired)) res = await self.call( 'org.labgrid.coordinator.release_place', place.name @@ -518,9 +522,9 @@ def get_target_resources(self, place): if gethostname()+'/'+getuser() not in place.allowed: host, user = place.acquired.split('/') if user != getuser(): - raise UserError("place {} is not acquired by your user, acquired by {}".format(place.name, user)) + raise UserError("place {} is not acquired by your user, acquired by {}".format(place.name, user)) # pylint: disable=line-too-long if host != gethostname(): - raise UserError("place {} is not acquired on this computer, acquired on {}".format(place.name, host)) + raise UserError("place {} is not acquired on this computer, acquired on {}".format(place.name, host)) # pylint: disable=line-too-long resources = {} for resource_path in place.acquired_resources: match = place.getmatch(resource_path) @@ -782,11 +786,12 @@ def ssh(self): ip = self._get_ip(place) if not ip: return - args = ['ssh', - '-l', 'root', - '-o', 'StrictHostKeyChecking no', - '-o', 'UserKnownHostsFile /dev/null', - str(ip), + args = [ + 'ssh', + '-l', 'root', + '-o', 'StrictHostKeyChecking no', + '-o', 'UserKnownHostsFile /dev/null', + str(ip), ] + self.args.leftover print('Note: Using dummy known hosts file.') res = subprocess.call(args) @@ -1015,8 +1020,7 @@ def main(): subparser.set_defaults(func=ClientSession.print_who) subparser = subparsers.add_parser('show', - help="show a place and related resources", - ) + help="show a place and related resources") subparser.set_defaults(func=ClientSession.print_place) subparser = subparsers.add_parser('create', help="add a new place") @@ -1080,7 +1084,8 @@ def main(): aliases=('pw',), help="change (or get) a place's power status") subparser.add_argument('action', choices=['on', 'off', 'cycle', 'get']) - subparser.add_argument('-t', '--delay', type=float, default=1.0, help='wait time between off and on during cycle') + subparser.add_argument('-t', '--delay', type=float, default=1.0, + help='wait time between off and on during cycle') subparser.set_defaults(func=ClientSession.power) subparser = subparsers.add_parser('io', @@ -1099,8 +1104,7 @@ def main(): subparser = subparsers.add_parser('fastboot', help="run fastboot") subparser.add_argument('fastboot_args', metavar='ARG', nargs=argparse.REMAINDER, - help='fastboot arguments' - ) + help='fastboot arguments') subparser.add_argument('--wait', type=float, default=10.0) subparser.set_defaults(func=ClientSession.fastboot) @@ -1109,8 +1113,7 @@ def main(): subparser.add_argument('-w', '--wait', type=float, default=10.0) subparser.add_argument('filename', help='filename to boot on the target') subparser.add_argument('bootstrap_args', metavar='ARG', nargs=argparse.REMAINDER, - help='extra bootstrap arguments' - ) + help='extra bootstrap arguments') subparser.set_defaults(func=ClientSession.bootstrap) subparser = subparsers.add_parser('sd-mux', @@ -1185,7 +1188,8 @@ def main(): if args.place: role = find_role_by_place(env.config.get_targets(), args.place) if not role: - print("RemotePlace {} not found in configuration file".format(args.place), file=sys.stderr) + print("RemotePlace {} not found in configuration file".format(args.place), + file=sys.stderr) exit(1) print("Selected role {} from configuration file".format(role)) else: @@ -1203,8 +1207,7 @@ def main(): } if args.command and args.command != 'help': - session = start_session(args.crossbar, - os.environ.get("LG_CROSSBAR_REALM", "realm1"), extra) + session = start_session(args.crossbar, os.environ.get("LG_CROSSBAR_REALM", "realm1"), extra) exitcode = 0 try: if asyncio.iscoroutinefunction(args.func): @@ -1216,29 +1219,21 @@ def main(): traceback.print_exc() else: print("{}: error: {}".format(parser.prog, e), file=sys.stderr) - print('\n'.join(["", - "This may be caused by disconnected exporter or wrong match entries.", - "You can use the 'show' command to all matching resources.", - ]), file=sys.stderr) + print("This may be caused by disconnected exporter or wrong match entries.\nYou can use the 'show' command to all matching resources.", file=sys.stderr) # pylint: disable=line-too-long exitcode = 1 except NoDriverFoundError as e: if args.debug: traceback.print_exc() else: print("{}: error: {}".format(parser.prog, e), file=sys.stderr) - print('\n'.join(["", - "This is likely caused by an error or missing driver in the environment configuration.", - ]), file=sys.stderr) + print("This is likely caused by an error or missing driver in the environment configuration.", file=sys.stderr) # pylint: disable=line-too-long exitcode = 1 except InvalidConfigError as e: if args.debug: traceback.print_exc() else: print("{}: error: {}".format(parser.prog, e), file=sys.stderr) - print('\n'.join(["", - "This is likely caused by an error in the environment configuration or invalid", - "resource information provided by the coordinator.", - ]), file=sys.stderr) + print("This is likely caused by an error in the environment configuration or invalid\nresource information provided by the coordinator.", file=sys.stderr) # pylint: disable=line-too-long exitcode = 1 except Error as e: if args.debug: diff --git a/labgrid/remote/common.py b/labgrid/remote/common.py index a25e863ae..25e9fe937 100644 --- a/labgrid/remote/common.py +++ b/labgrid/remote/common.py @@ -60,7 +60,7 @@ class ResourceMatch: @classmethod def fromstr(cls, pattern): - if not (2 <= pattern.count("/") <= 3): + if not 2 <= pattern.count("/") <= 3: raise ValueError( "invalid pattern format '{}' (use 'exporter/group/cls/name')". format(pattern) @@ -80,8 +80,8 @@ def __str__(self): return result def ismatch(self, resource_path): - exporter, group, cls, name = resource_path """Return True if this matches the given resource""" + exporter, group, cls, name = resource_path if not fnmatchcase(exporter, self.exporter): return False elif not fnmatchcase(group, self.group): diff --git a/labgrid/remote/coordinator.py b/labgrid/remote/coordinator.py index 4e96af2f0..9e8b2eae6 100644 --- a/labgrid/remote/coordinator.py +++ b/labgrid/remote/coordinator.py @@ -226,7 +226,6 @@ async def poll(self): except: traceback.print_exc() - def save_later(self): self.save_scheduled = True @@ -266,11 +265,7 @@ def _add_default_place(self, name): return place = Place(name) print(place) - place.matches.append(ResourceMatch( - exporter = "*", - group = name, - cls = "*", - )) + place.matches.append(ResourceMatch(exporter="*", group=name, cls="*")) self.places[name] = place async def _update_acquired_places(self, action, resource_path): diff --git a/labgrid/remote/exporter.py b/labgrid/remote/exporter.py index 6b12249b8..5c42e9ad4 100755 --- a/labgrid/remote/exporter.py +++ b/labgrid/remote/exporter.py @@ -114,8 +114,7 @@ def __attrs_post_init__(self): super().__attrs_post_init__() self.data['cls'] = "NetworkSerialPort" from ..resource.udev import USBSerialPort - self.local = USBSerialPort(target=None, name=None, - **self.local_params) + self.local = USBSerialPort(target=None, name=None, **self.local_params) self.child = None self.port = None @@ -182,8 +181,7 @@ def __attrs_post_init__(self): super().__attrs_post_init__() from ..resource.udev import USBEthernetInterface self.data['cls'] = "EthernetInterface" - self.local = USBEthernetInterface(target=None, name=None, - **self.local_params) + self.local = USBEthernetInterface(target=None, name=None, **self.local_params) def _get_params(self): """Helper function to return parameters""" @@ -206,8 +204,7 @@ def __attrs_post_init__(self): self.data['cls'] = "Network{}".format(self.cls) from ..resource import udev local_cls = getattr(udev, local_cls_name) - self.local = local_cls(target=None, name=None, - **self.local_params) + self.local = local_cls(target=None, name=None, **self.local_params) def _get_params(self): """Helper function to return parameters""" @@ -300,8 +297,7 @@ def __attrs_post_init__(self): super().__attrs_post_init__() from ..resource.ethernetport import SNMPEthernetPort self.data['cls'] = "EthernetPort" - self.local = SNMPEthernetPort(target=None, name=None, - **self.local_params) + self.local = SNMPEthernetPort(target=None, name=None, **self.local_params) def _get_params(self): """Helper function to return parameters""" @@ -499,7 +495,7 @@ def main(): args = parser.parse_args() - level='debug' if args.debug else 'info' + level = 'debug' if args.debug else 'info' extra = { 'name': args.name or gethostname(), diff --git a/labgrid/resource/ethernetport.py b/labgrid/resource/ethernetport.py index d47838b20..ef9847a93 100644 --- a/labgrid/resource/ethernetport.py +++ b/labgrid/resource/ethernetport.py @@ -54,7 +54,7 @@ def _get_ports(self): from pysnmp import hlapi variables = [ - (hlapi.ObjectType(hlapi.ObjectIdentity('IF-MIB', 'ifIndex')),'index'), + (hlapi.ObjectType(hlapi.ObjectIdentity('IF-MIB', 'ifIndex')), 'index'), (hlapi.ObjectType(hlapi.ObjectIdentity('IF-MIB', 'ifDescr')), 'descr'), (hlapi.ObjectType(hlapi.ObjectIdentity('IF-MIB', 'ifSpeed')), 'speed'), (hlapi.ObjectType(hlapi.ObjectIdentity('IF-MIB', 'ifOperStatus')), 'status'), @@ -204,7 +204,7 @@ def on_resource_added(self, resource): if not isinstance(resource, SNMPEthernetPort): return self._start() - resource.avail=True + resource.avail = True def _start(self): """Internal function to register as task and attach/start the event diff --git a/labgrid/resource/remote.py b/labgrid/resource/remote.py index 338680c63..5391381ad 100644 --- a/labgrid/resource/remote.py +++ b/labgrid/resource/remote.py @@ -36,9 +36,11 @@ def on_resource_added(self, resource): if not self.session: self.env = remote_place.target.env config = self.env.config - self.url = config.get_option('crossbar_url', + self.url = config.get_option( + 'crossbar_url', os.environ.get("LG_CROSSBAR", "ws://127.0.0.1:20408/ws")) - self.realm = config.get_option('crossbar_realm', + self.realm = config.get_option( + 'crossbar_realm', os.environ.get("LG_CROSSBAR_REALM", "realm1")) self._start() place = self.session.get_place(remote_place.name) @@ -56,7 +58,7 @@ def on_resource_added(self, resource): expanded.append(new) self.logger.debug("expanded remote resources for place {}: {}".format( remote_place.name, expanded)) - remote_place.avail=True + remote_place.avail = True def poll(self): import asyncio @@ -136,6 +138,7 @@ def __attrs_post_init__(self): self.timeout = 10.0 super().__attrs_post_init__() + @target_factory.reg_resource @attr.s(cmp=False) class NetworkSigrokUSBDevice(RemoteUSBResource): @@ -146,6 +149,7 @@ def __attrs_post_init__(self): self.timeout = 10.0 super().__attrs_post_init__() + @target_factory.reg_resource @attr.s(cmp=False) class NetworkUSBMassStorage(RemoteUSBResource): @@ -154,6 +158,7 @@ def __attrs_post_init__(self): self.timeout = 10.0 super().__attrs_post_init__() + @target_factory.reg_resource @attr.s(cmp=False) class NetworkUSBSDMuxDevice(RemoteUSBResource): @@ -163,6 +168,7 @@ def __attrs_post_init__(self): self.timeout = 10.0 super().__attrs_post_init__() + @target_factory.reg_resource @attr.s(cmp=False) class NetworkUSBPowerPort(RemoteUSBResource): @@ -172,6 +178,7 @@ def __attrs_post_init__(self): self.timeout = 10.0 super().__attrs_post_init__() + @target_factory.reg_resource @attr.s(cmp=False) class NetworkUSBVideo(RemoteUSBResource): @@ -180,6 +187,7 @@ def __attrs_post_init__(self): self.timeout = 10.0 super().__attrs_post_init__() + @target_factory.reg_resource @attr.s(cmp=False) class NetworkUSBTMC(RemoteUSBResource): diff --git a/labgrid/resource/serialport.py b/labgrid/resource/serialport.py index dd6c1ea69..180869572 100644 --- a/labgrid/resource/serialport.py +++ b/labgrid/resource/serialport.py @@ -28,4 +28,4 @@ class NetworkSerialPort(NetworkResource): """ port = attr.ib(validator=attr.validators.optional(attr.validators.instance_of(int))) speed = attr.ib(default=115200, validator=attr.validators.instance_of(int)) - protocol = attr.ib(default="rfc2217", validator=attr.validators.instance_of(str)) \ No newline at end of file + protocol = attr.ib(default="rfc2217", validator=attr.validators.instance_of(str)) diff --git a/labgrid/resource/udev.py b/labgrid/resource/udev.py index 75983b55f..3a01cbc00 100644 --- a/labgrid/resource/udev.py +++ b/labgrid/resource/udev.py @@ -112,7 +112,8 @@ def devnum(self): def _get_usb_device(self): device = self.device - if self.device and (self.device.subsystem != 'usb' or self.device.device_type != 'usb_device'): + if self.device and (self.device.subsystem != 'usb' + or self.device.device_type != 'usb_device'): device = self.device.find_parent('usb', 'usb_device') return device @@ -194,7 +195,7 @@ class MXSUSBLoader(USBResource): def filter_match(self, device): match = (device.get('ID_VENDOR_ID'), device.get('ID_MODEL_ID')) - if not match in [("066f", "3780"), ("15a2", "004f")]: + if match not in [("066f", "3780"), ("15a2", "004f")]: return False return super().filter_match(device) diff --git a/labgrid/resource/ykushpowerport.py b/labgrid/resource/ykushpowerport.py index 5677ddc89..028b4dc48 100644 --- a/labgrid/resource/ykushpowerport.py +++ b/labgrid/resource/ykushpowerport.py @@ -10,7 +10,7 @@ class YKUSHPowerPort(Resource): """This resource describes a YEPKIT YKUSH switchable USB hub. Args: - serial (str): serial of the YKUSH device + serial (str): serial of the YKUSH device index (int): port index""" serial = attr.ib(validator=attr.validators.instance_of(str)) index = attr.ib(validator=attr.validators.instance_of(int), diff --git a/labgrid/target.py b/labgrid/target.py index 35f31ca75..1defd7d17 100644 --- a/labgrid/target.py +++ b/labgrid/target.py @@ -336,9 +336,7 @@ def bind_driver(self, client): requirements, self, errors) ) elif len(suppliers) > 1: - raise NoSupplierFoundError( - "conflicting suppliers matching {} found in target {}".format(requirements, self) - ) + raise NoSupplierFoundError("conflicting suppliers matching {} found in target {}".format(requirements, self)) # pylint: disable=line-too-long else: supplier = suppliers[0] setattr(client, name, supplier) diff --git a/labgrid/util/agent.py b/labgrid/util/agent.py index f054f3a18..a55568e62 100644 --- a/labgrid/util/agent.py +++ b/labgrid/util/agent.py @@ -43,7 +43,7 @@ def run(self): try: response = self.methods[name](*args, **kwargs) self._send({'result': response}) - except Exception as e: + except Exception as e: # pylint: disable=broad-except self._send({'exception': repr(e)}) break @@ -76,5 +76,5 @@ def main(): a.register('usbtmc', handle_usbtmc) a.run() -if __name__=="__main__": +if __name__ == "__main__": main() diff --git a/labgrid/util/agentwrapper.py b/labgrid/util/agentwrapper.py index 8e3354254..5b18c9f77 100644 --- a/labgrid/util/agentwrapper.py +++ b/labgrid/util/agentwrapper.py @@ -83,4 +83,3 @@ def close(self): self.agent.stdin.flush() self.agent.wait() self.agent = None - diff --git a/labgrid/util/dict.py b/labgrid/util/dict.py index 41c6a6ffb..9dbbcc54c 100644 --- a/labgrid/util/dict.py +++ b/labgrid/util/dict.py @@ -34,5 +34,6 @@ def filter_dict(d, cls, warn=False): if warn: remove = set(d) - fields for k in sorted(remove): - warnings.warn("unsupported attribute '{}' with value '{}' for class '{}'".format(k, d[k], cls.__name__), stacklevel=2) + warnings.warn("unsupported attribute '{}' with value '{}' for class '{}'".format( + k, d[k], cls.__name__), stacklevel=2) return {k: v for k, v in d.items() if k in fields} diff --git a/labgrid/util/qmp.py b/labgrid/util/qmp.py index 55fdbf0c8..c8206bccb 100644 --- a/labgrid/util/qmp.py +++ b/labgrid/util/qmp.py @@ -6,7 +6,7 @@ @attr.s(cmp=False) class QMPMonitor: monitor_out = attr.ib() - monitor_in = attr.ib() + monitor_in = attr.ib() def __attrs_post_init__(self): self.logger = logging.getLogger("{}:".format(self)) diff --git a/tests/test_ethernetport.py b/tests/test_ethernetport.py index 447c22b34..bea4b8ad7 100644 --- a/tests/test_ethernetport.py +++ b/tests/test_ethernetport.py @@ -1,5 +1,6 @@ from labgrid.resource import SNMPEthernetPort + def test_instance(target): s = SNMPEthernetPort(target, 'port-1', switch='dummy-switch', interface='1') assert (isinstance(s, SNMPEthernetPort)) diff --git a/tests/test_usbtmc.py b/tests/test_usbtmc.py index 362398807..307024344 100644 --- a/tests/test_usbtmc.py +++ b/tests/test_usbtmc.py @@ -1,6 +1,7 @@ from labgrid.resource.remote import NetworkUSBTMC from labgrid.driver.usbtmcdriver import USBTMCDriver + def test_usbtmc_create(target): r = NetworkUSBTMC(target, name=None, diff --git a/tests/test_usbvideo.py b/tests/test_usbvideo.py index 41447c372..57a6ced04 100644 --- a/tests/test_usbvideo.py +++ b/tests/test_usbvideo.py @@ -1,6 +1,7 @@ from labgrid.resource.remote import NetworkUSBVideo from labgrid.driver.usbvideodriver import USBVideoDriver + def test_usbvideo_create(target): r = NetworkUSBVideo(target, name=None, From 8feb8926f6d7f50a6f9fe87a62cae5e191ca2f0c Mon Sep 17 00:00:00 2001 From: Bastian Stender Date: Wed, 30 May 2018 22:28:16 +0200 Subject: [PATCH 34/45] linting: use specific exceptions where possible Signed-off-by: Bastian Stender --- examples/strategy/test_uboot_strategy.py | 2 +- labgrid/autoinstall/main.py | 4 ++-- labgrid/remote/client.py | 2 +- labgrid/remote/coordinator.py | 2 +- labgrid/remote/exporter.py | 8 ++++---- labgrid/resource/ethernetport.py | 2 +- labgrid/step.py | 2 +- labgrid/util/agent.py | 2 +- 8 files changed, 12 insertions(+), 12 deletions(-) diff --git a/examples/strategy/test_uboot_strategy.py b/examples/strategy/test_uboot_strategy.py index 59ce20c66..8fa2b0263 100644 --- a/examples/strategy/test_uboot_strategy.py +++ b/examples/strategy/test_uboot_strategy.py @@ -5,7 +5,7 @@ def strategy(target): try: return target.get_driver('UBootStrategy') - except: + except NoDriverFoundError: pytest.skip("strategy not found") diff --git a/labgrid/autoinstall/main.py b/labgrid/autoinstall/main.py index d1ba5eda5..3406e4ad1 100644 --- a/labgrid/autoinstall/main.py +++ b/labgrid/autoinstall/main.py @@ -73,7 +73,7 @@ def run(self): self.context['target'] = self.target if self.target is None: raise KeyError - except: + except Exception: # pylint: disable=broad-except self.log.exception("target creation failed") return @@ -123,7 +123,7 @@ def run_once(self): next(iter(e.filter))) else: self.log.warning("resource not found, restarting") - except: + except Exception: # pylint: disable=broad-except self.log.exception("handler failed") return False diff --git a/labgrid/remote/client.py b/labgrid/remote/client.py index 0ec5e4a2e..8b3735d65 100755 --- a/labgrid/remote/client.py +++ b/labgrid/remote/client.py @@ -1243,7 +1243,7 @@ def main(): exitcode = 1 except KeyboardInterrupt: exitcode = 0 - except: + except Exception: # pylint: disable=broad-except traceback.print_exc() exitcode = 2 exit(exitcode) diff --git a/labgrid/remote/coordinator.py b/labgrid/remote/coordinator.py index 9e8b2eae6..896b8f684 100644 --- a/labgrid/remote/coordinator.py +++ b/labgrid/remote/coordinator.py @@ -223,7 +223,7 @@ async def poll(self): await self._poll_step() except asyncio.CancelledError: break - except: + except Exception: # pylint: disable=broad-except traceback.print_exc() def save_later(self): diff --git a/labgrid/remote/exporter.py b/labgrid/remote/exporter.py index 5c42e9ad4..f4852989c 100755 --- a/labgrid/remote/exporter.py +++ b/labgrid/remote/exporter.py @@ -18,7 +18,7 @@ try: import pkg_resources __version__ = pkg_resources.get_distribution('labgrid').version -except: +except pkg_resources.DistributionNotFound: __version__ = "unknown" def get_free_port(): @@ -351,7 +351,7 @@ async def onJoin(self, details): group_name, resource_name, cls, params ) - except: + except Exception: # pylint: disable=broad-except traceback.print_exc() self.loop.stop() return @@ -400,7 +400,7 @@ async def _poll_step(self): continue try: changed = resource.poll() - except: + except Exception: # pylint: disable=broad-except print("Exception while polling {}".format(resource), file=sys.stderr) traceback.print_exc() continue @@ -420,7 +420,7 @@ async def poll(self): await self._poll_step() except asyncio.CancelledError: break - except: + except Exception: # pylint: disable=broad-except traceback.print_exc() async def add_resource(self, group_name, resource_name, cls, params): diff --git a/labgrid/resource/ethernetport.py b/labgrid/resource/ethernetport.py index ef9847a93..0dbd0353f 100644 --- a/labgrid/resource/ethernetport.py +++ b/labgrid/resource/ethernetport.py @@ -245,7 +245,7 @@ async def poll(self, handler): await handler(self) except asyncio.CancelledError: break - except: + except Exception: # pylint: disable=broad-except import traceback traceback.print_exc() diff --git a/labgrid/step.py b/labgrid/step.py index 88ad51045..0cc7a4663 100644 --- a/labgrid/step.py +++ b/labgrid/step.py @@ -40,7 +40,7 @@ def notify(self, event): for subscriber in self._subscribers: try: subscriber(event) - except Exception as e: + except Exception as e: # pylint: disable=broad-except warnings.warn("unhandled exception during event notification: {}".format(e)) steps = Steps() diff --git a/labgrid/util/agent.py b/labgrid/util/agent.py index a55568e62..580c3b423 100644 --- a/labgrid/util/agent.py +++ b/labgrid/util/agent.py @@ -30,7 +30,7 @@ def run(self): try: request = json.loads(line) - except: + except json.JSONDecodeError: self._send({'error': 'request parsing failed'}) break From 563830db67aed2d0d6cb7d989c62d834426da83e Mon Sep 17 00:00:00 2001 From: Bastian Stender Date: Wed, 30 May 2018 15:59:03 +0200 Subject: [PATCH 35/45] linting: use explicit returns and remove else-path where possible See pylint error messages R1705 and R1710. Signed-off-by: Bastian Stender --- labgrid/binding.py | 8 +++---- labgrid/config.py | 4 ++-- labgrid/driver/bareboxdriver.py | 4 ++-- labgrid/driver/common.py | 2 ++ labgrid/driver/consoleexpectmixin.py | 6 ++--- labgrid/driver/externalconsoledriver.py | 4 ++-- labgrid/driver/infodriver.py | 4 ++-- labgrid/driver/sshdriver.py | 4 ++-- labgrid/driver/ubootdriver.py | 4 ++-- labgrid/driver/usbtmcdriver.py | 6 ++--- labgrid/remote/common.py | 6 +++-- labgrid/remote/coordinator.py | 4 ++-- labgrid/resource/udev.py | 32 +++++++++++++++++-------- labgrid/step.py | 8 +++---- labgrid/util/agent.py | 2 +- 15 files changed, 57 insertions(+), 41 deletions(-) diff --git a/labgrid/binding.py b/labgrid/binding.py index 2cccee24c..a6cc80542 100644 --- a/labgrid/binding.py +++ b/labgrid/binding.py @@ -61,10 +61,10 @@ def display_name(self): return "{}(target={}, name={})".format( self.__class__.__name__, self.target.name, self.name ) - else: - return "{}(target={})".format( - self.__class__.__name__, self.target.name - ) + + return "{}(target={})".format( + self.__class__.__name__, self.target.name + ) def on_supplier_bound(self, supplier): """Called by the Target after a new supplier has been bound""" diff --git a/labgrid/config.py b/labgrid/config.py index dd1139474..a50ec488f 100644 --- a/labgrid/config.py +++ b/labgrid/config.py @@ -64,8 +64,8 @@ def resolve_path(self, path): path = os.path.expandvars(path) if os.path.isabs(path): return path - else: - return os.path.join(self.base, path) + + return os.path.join(self.base, path) def get_tool(self, tool): """Retrieve an entry from the tools subkey diff --git a/labgrid/driver/bareboxdriver.py b/labgrid/driver/bareboxdriver.py index 89cb64d90..e45421cb4 100644 --- a/labgrid/driver/bareboxdriver.py +++ b/labgrid/driver/bareboxdriver.py @@ -87,8 +87,8 @@ def run(self, cmd: str, *, step, timeout: int = 30): # Get exit code exitcode = int(match.group(2)) return (data, [], exitcode) - else: - return None + + return None @Driver.check_active @step() diff --git a/labgrid/driver/common.py b/labgrid/driver/common.py index ffcf1d3f7..e0ccf743a 100644 --- a/labgrid/driver/common.py +++ b/labgrid/driver/common.py @@ -43,6 +43,8 @@ def get_priority(self, protocol): if cls.__name__ == protocol.__name__: return 0 + return 0 + def check_file(filename, *, command_prefix=[]): if subprocess.call(command_prefix + ['test', '-r', filename]) != 0: diff --git a/labgrid/driver/consoleexpectmixin.py b/labgrid/driver/consoleexpectmixin.py index cc45eaeff..837c9adcf 100644 --- a/labgrid/driver/consoleexpectmixin.py +++ b/labgrid/driver/consoleexpectmixin.py @@ -36,9 +36,9 @@ def write(self, data): sleep(self.txdelay) count += self._write(data[i:i+1]) return count - else: - self.logger.debug("Write %i bytes: %s", len(data), data) - return self._write(data) + + self.logger.debug("Write %i bytes: %s", len(data), data) + return self._write(data) @Driver.check_active def sendline(self, line): diff --git a/labgrid/driver/externalconsoledriver.py b/labgrid/driver/externalconsoledriver.py index 9ac9eae08..d1205af89 100644 --- a/labgrid/driver/externalconsoledriver.py +++ b/labgrid/driver/externalconsoledriver.py @@ -78,8 +78,8 @@ def _read(self, size: int = 1024, timeout: int = 0): raise ExecutionError("child has vanished") if self._poll.poll(timeout): return self._child.stdout.read(size) - else: - return b'' + + return b'' def _write(self, data: bytes): """ diff --git a/labgrid/driver/infodriver.py b/labgrid/driver/infodriver.py index fc568f128..4e5a9fd11 100644 --- a/labgrid/driver/infodriver.py +++ b/labgrid/driver/infodriver.py @@ -52,8 +52,8 @@ def get_ip(self, interface="eth0"): self.logger.debug("Complete result: %s", result) if result: return result[interface] - else: - return None + + return None @Driver.check_active @step(args=['service']) diff --git a/labgrid/driver/sshdriver.py b/labgrid/driver/sshdriver.py index 9fa59235a..105a25cfc 100644 --- a/labgrid/driver/sshdriver.py +++ b/labgrid/driver/sshdriver.py @@ -95,8 +95,8 @@ def _check_master(self): ) if check == 0: return "" - else: - return self._start_own_master() + + return self._start_own_master() @Driver.check_active @step(args=['cmd']) diff --git a/labgrid/driver/ubootdriver.py b/labgrid/driver/ubootdriver.py index 019dbe0ce..41652c326 100644 --- a/labgrid/driver/ubootdriver.py +++ b/labgrid/driver/ubootdriver.py @@ -90,8 +90,8 @@ def _run(self, cmd): exitcode = int(data[-1]) del data[-1] return (data, [], exitcode) - else: - return None + + return None @Driver.check_active def run(self, cmd): diff --git a/labgrid/driver/usbtmcdriver.py b/labgrid/driver/usbtmcdriver.py index 95917988a..22d0620b4 100644 --- a/labgrid/driver/usbtmcdriver.py +++ b/labgrid/driver/usbtmcdriver.py @@ -64,9 +64,9 @@ def query(self, cmd, binary=False): digits = int(res[1:2], 10) count = int(res[2:2+digits], 10) return res[2+digits:2+digits+count] - else: - assert res[-1:] == b'\n' - return res[:-1].decode('ASCII') + + assert res[-1:] == b'\n' + return res[:-1].decode('ASCII') @Driver.check_active def identify(self): diff --git a/labgrid/remote/common.py b/labgrid/remote/common.py index 25e9fe937..be08dc554 100644 --- a/labgrid/remote/common.py +++ b/labgrid/remote/common.py @@ -90,8 +90,8 @@ def ismatch(self, resource_path): return False elif self.name and not fnmatchcase(name, self.name): return False - else: - return True + + return True @attr.s(cmp=False) @@ -141,6 +141,8 @@ def getmatch(self, resource_path): if match.ismatch(resource_path): return match + return None + def hasmatch(self, resource_path): """Return True if this place as a ResourceMatch object for the given resource path. diff --git a/labgrid/remote/coordinator.py b/labgrid/remote/coordinator.py index 896b8f684..973949b87 100644 --- a/labgrid/remote/coordinator.py +++ b/labgrid/remote/coordinator.py @@ -75,8 +75,8 @@ def set_resource(self, groupname, resourcename, resource): return Action.DEL, resource_path elif new: return Action.ADD, resource_path - else: - return None, resource_path + + return None, resource_path def get_resources(self): """Method invoked by the exporter, get a resource from the coordinator""" diff --git a/labgrid/resource/udev.py b/labgrid/resource/udev.py index 3a01cbc00..99ab88403 100644 --- a/labgrid/resource/udev.py +++ b/labgrid/resource/udev.py @@ -104,12 +104,16 @@ def busnum(self): if device: return int(device.get('BUSNUM')) + return None + @property def devnum(self): device = self._get_usb_device() if device: return int(device.get('DEVNUM')) + return None + def _get_usb_device(self): device = self.device if self.device and (self.device.subsystem != 'usb' @@ -123,18 +127,24 @@ def path(self): if device: return str(device.sys_name) + return None + @property def vendor_id(self): device = self._get_usb_device() if device: return int(device.get('ID_VENDOR_ID'), 16) + return None + @property def model_id(self): device = self._get_usb_device() if device: return int(device.get('ID_MODEL_ID'), 16) + return None + def read_attr(self, attribute): """read uncached attribute value from sysfs @@ -147,6 +157,8 @@ def read_attr(self, attribute): with open(os.path.join(self.device.sys_path, attribute), 'rb') as f: return f.read().rstrip(b'\n') # drop trailing newlines + return None + @target_factory.reg_resource @attr.s(cmp=False) @@ -175,8 +187,8 @@ def __attrs_post_init__(self): def path(self): if self.device: return self.device.device_node - else: - return None + + return None @target_factory.reg_resource @attr.s(cmp=False) @@ -297,16 +309,16 @@ def control_path(self): dev = self._get_scsi_dev() if dev: return dev.device_node - else: - return None + + return None @property def path(self): dev = self._get_block_disk_dev() if dev: return dev.device_node - else: - return None + + return None @target_factory.reg_resource @attr.s(cmp=False) @@ -335,8 +347,8 @@ def __attrs_post_init__(self): def path(self): if self.device: return self.device.device_node - else: - return None + + return None @target_factory.reg_resource @attr.s(cmp=False) @@ -351,5 +363,5 @@ def __attrs_post_init__(self): def path(self): if self.device: return self.device.device_node - else: - return None + + return None diff --git a/labgrid/step.py b/labgrid/step.py index 0cc7a4663..7f26c55b2 100644 --- a/labgrid/step.py +++ b/labgrid/step.py @@ -129,8 +129,8 @@ def duration(self): return 0.0 elif self._stop_ts is None: return monotonic() - self._start_ts - else: - return self._stop_ts - self._start_ts + + return self._stop_ts - self._start_ts @property def status(self): @@ -138,8 +138,8 @@ def status(self): return 'new' elif self._stop_ts is None: return 'active' - else: - return 'done' + + return 'done' @property def is_active(self): diff --git a/labgrid/util/agent.py b/labgrid/util/agent.py index 580c3b423..b45347bf4 100644 --- a/labgrid/util/agent.py +++ b/labgrid/util/agent.py @@ -60,7 +60,7 @@ def handle_usbtmc(index, cmd, read=False): os.write(fd, cmd) if not read: os.close(fd) - return + return None data = [] while True: data.append(os.read(fd, 4096)) From 6170ba040aa52738781b9fd99fabb7db8d161894 Mon Sep 17 00:00:00 2001 From: Bastian Stender Date: Wed, 30 May 2018 16:26:35 +0200 Subject: [PATCH 36/45] linting: driver/usbtmcdriver: remove unused kwarg "binary" in command() Signed-off-by: Bastian Stender --- labgrid/driver/usbtmcdriver.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/labgrid/driver/usbtmcdriver.py b/labgrid/driver/usbtmcdriver.py index 22d0620b4..d4ec08b8d 100644 --- a/labgrid/driver/usbtmcdriver.py +++ b/labgrid/driver/usbtmcdriver.py @@ -49,7 +49,7 @@ def on_deactivate(self): self.backend = None @Driver.check_active - def command(self, cmd, binary=False): + def command(self, cmd): assert isinstance(cmd, str) cmd = b2s(cmd.encode('ASCII')+b'\n') self.wrapper.usbtmc(self.index, cmd, read=False) From fec552f3ef37a392bbd12db6f8fdab7480c943ca Mon Sep 17 00:00:00 2001 From: Bastian Stender Date: Fri, 25 May 2018 15:30:08 +0200 Subject: [PATCH 37/45] linting: do not use len() to determine if a sequence is empty Instead of comparing the length to 0, rely on the fact that empty sequences are False. Signed-off-by: Bastian Stender --- examples/barebox/test_barebox.py | 8 ++++---- examples/barebox/test_bootchooser.py | 3 ++- examples/barebox/test_sleep.py | 8 ++++---- examples/barebox/test_state.py | 2 +- examples/barebox/test_watchdog.py | 4 ++-- examples/remote/test_barebox.py | 8 ++++---- examples/shell/test_shell.py | 8 ++++---- examples/strategy/test_barebox_strategy.py | 8 ++++---- examples/strategy/test_uboot_strategy.py | 12 ++++++------ examples/usbpower/test_example.py | 8 ++++---- labgrid/target.py | 4 ++-- tests/test_util.py | 2 +- 12 files changed, 38 insertions(+), 37 deletions(-) diff --git a/examples/barebox/test_barebox.py b/examples/barebox/test_barebox.py index 0011901e1..271ac17ff 100644 --- a/examples/barebox/test_barebox.py +++ b/examples/barebox/test_barebox.py @@ -1,11 +1,11 @@ def test_barebox(command): stdout, stderr, returncode = command.run('version') assert returncode == 0 - assert len(stdout) > 0 - assert len(stderr) == 0 + assert stdout + assert not stderr assert 'barebox' in '\n'.join(stdout) stdout, stderr, returncode = command.run('false') assert returncode == 1 - assert len(stdout) == 0 - assert len(stderr) == 0 + assert not stdout + assert not stderr diff --git a/examples/barebox/test_bootchooser.py b/examples/barebox/test_bootchooser.py index 6a68ff997..57e68e2e6 100644 --- a/examples/barebox/test_bootchooser.py +++ b/examples/barebox/test_bootchooser.py @@ -1,10 +1,11 @@ import pytest + def test_bootchooser(command): stdout, stderr, returncode = command.run('bootchooser -i') if returncode == 127: pytest.skip("bootchooser command not available") assert returncode == 0 - assert len(stderr) == 0 + assert not stderr assert stdout[0].startswith('Good targets') assert stdout[1] != 'none' diff --git a/examples/barebox/test_sleep.py b/examples/barebox/test_sleep.py index f537d524e..1df4ce66e 100644 --- a/examples/barebox/test_sleep.py +++ b/examples/barebox/test_sleep.py @@ -9,15 +9,15 @@ def test_sleep(command): stdout, stderr, returncode = command.run('true') elapsed_true = monotonic() - timestamp assert returncode == 0 - assert len(stdout) == 0 - assert len(stderr) == 0 + assert not stdout + assert not stderr timestamp = monotonic() stdout, stderr, returncode = command.run('sleep 1') elapsed_sleep = monotonic() - timestamp assert returncode == 0 - assert len(stdout) == 0 - assert len(stderr) == 0 + assert not stdout + assert not stderr assert elapsed_true < elapsed_sleep diff --git a/examples/barebox/test_state.py b/examples/barebox/test_state.py index fb2a3f750..13e397dcf 100644 --- a/examples/barebox/test_state.py +++ b/examples/barebox/test_state.py @@ -6,6 +6,6 @@ def test_state(command): if returncode == 127: pytest.skip("state command not available") assert returncode == 0 - assert len(stderr) == 0 + assert not stderr assert stdout[0] == 'registered state instances:' assert len(stdout) > 1 diff --git a/examples/barebox/test_watchdog.py b/examples/barebox/test_watchdog.py index 6e542e176..43b75183b 100644 --- a/examples/barebox/test_watchdog.py +++ b/examples/barebox/test_watchdog.py @@ -6,8 +6,8 @@ def test_watchdog(command): if returncode == 127: pytest.skip("wd command not available") assert returncode == 0 - assert len(stderr) == 0 - assert len(stdout) == 0 + assert not stderr + assert not stdout command._await_prompt() diff --git a/examples/remote/test_barebox.py b/examples/remote/test_barebox.py index ea39054d7..e8ae6319d 100644 --- a/examples/remote/test_barebox.py +++ b/examples/remote/test_barebox.py @@ -4,11 +4,11 @@ def test_target(target): stdout, stderr, returncode = barebox.run('version') assert returncode == 0 - assert len(stdout) > 0 - assert len(stderr) == 0 + assert stdout + assert not stderr assert 'barebox' in '\n'.join(stdout) stdout, stderr, returncode = barebox.run('false') assert returncode == 1 - assert len(stdout) == 0 - assert len(stderr) == 0 + assert not stdout + assert not stderr diff --git a/examples/shell/test_shell.py b/examples/shell/test_shell.py index 50b9b7d5d..58552f91b 100644 --- a/examples/shell/test_shell.py +++ b/examples/shell/test_shell.py @@ -1,11 +1,11 @@ def test_shell(command): stdout, stderr, returncode = command.run('cat /proc/version') assert returncode == 0 - assert len(stdout) > 0 - assert len(stderr) == 0 + assert stdout + assert not stderr assert 'Linux' in stdout[0] stdout, stderr, returncode = command.run('false') assert returncode != 0 - assert len(stdout) == 0 - assert len(stderr) == 0 + assert not stdout + assert not stderr diff --git a/examples/strategy/test_barebox_strategy.py b/examples/strategy/test_barebox_strategy.py index 260344480..a11ff8661 100644 --- a/examples/strategy/test_barebox_strategy.py +++ b/examples/strategy/test_barebox_strategy.py @@ -28,8 +28,8 @@ def test_barebox(target, in_bootloader): stdout, stderr, returncode = command.run('version') assert returncode == 0 - assert len(stdout) > 0 - assert len(stderr) == 0 + assert stdout + assert not stderr assert 'barebox' in '\n'.join(stdout) @@ -38,8 +38,8 @@ def test_shell(target, in_shell): command = target['ShellDriver'] stdout, stderr, returncode = command.run('cat /proc/version') assert returncode == 0 - assert len(stdout) > 0 - assert len(stderr) == 0 + assert stdout + assert not stderr assert 'Linux' in stdout[0] diff --git a/examples/strategy/test_uboot_strategy.py b/examples/strategy/test_uboot_strategy.py index 8fa2b0263..0c31c2702 100644 --- a/examples/strategy/test_uboot_strategy.py +++ b/examples/strategy/test_uboot_strategy.py @@ -27,8 +27,8 @@ def test_uboot(target, in_bootloader): stdout, stderr, returncode = command.run('version') assert returncode == 0 - assert len(stdout) > 0 - assert len(stderr) == 0 + assert stdout + assert not stderr assert 'U-Boot' in '\n'.join(stdout) @@ -37,8 +37,8 @@ def test_shell(target, in_shell): command = target.get_driver('ShellDriver') stdout, stderr, returncode = command.run('cat /proc/version') assert returncode == 0 - assert len(stdout) > 0 - assert len(stderr) == 0 + assert stdout + assert not stderr assert 'Linux' in stdout[0] @@ -47,6 +47,6 @@ def test_uboot_2(target, in_bootloader): stdout, stderr, returncode = command.run('version') assert returncode == 0 - assert len(stdout) > 0 - assert len(stderr) == 0 + assert stdout + assert not stderr assert 'U-Boot' in '\n'.join(stdout) diff --git a/examples/usbpower/test_example.py b/examples/usbpower/test_example.py index 443db89cc..ec3459a54 100644 --- a/examples/usbpower/test_example.py +++ b/examples/usbpower/test_example.py @@ -28,16 +28,16 @@ def shell(target, strategy, capsys): def test_barebox(bootloader): stdout, stderr, returncode = bootloader.run('version') assert returncode == 0 - assert len(stdout) > 0 - assert len(stderr) == 0 + assert stdout + assert not stderr assert 'barebox' in '\n'.join(stdout) def test_shell(shell): stdout, stderr, returncode = shell.run('cat /proc/version') assert returncode == 0 - assert len(stdout) > 0 - assert len(stderr) == 0 + assert stdout + assert not stderr assert 'Linux' in stdout[0] diff --git a/labgrid/target.py b/labgrid/target.py index 1defd7d17..b94fdcaba 100644 --- a/labgrid/target.py +++ b/labgrid/target.py @@ -119,7 +119,7 @@ def get_resource(self, cls, *, name=None, await=True): other_names.append(res.name) continue found.append(res) - if len(found) == 0: + if not found: if other_names: raise NoResourceFoundError( "all resources matching {} found in target {} have other names: {}".format( @@ -154,7 +154,7 @@ def _get_driver(self, cls, *, name=None, activate=True, active=False): if active and drv.state != BindingState.active: continue found.append(drv) - if len(found) == 0: + if not found: if other_names: raise NoDriverFoundError( "all {}drivers matching {} found in target {} have other names: {}".format( diff --git a/tests/test_util.py b/tests/test_util.py index f1a641785..cfbb50002 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -30,7 +30,7 @@ class A: with pytest.warns(None) as record: d_filtered = filter_dict(d_orig, A) - assert len(record) == 0 + assert not record assert d_filtered is not d_orig assert d_filtered == {'foo': 1} From 1077a6c952ed020ad847ee2dc8d884446834a1c4 Mon Sep 17 00:00:00 2001 From: Bastian Stender Date: Fri, 25 May 2018 16:45:03 +0200 Subject: [PATCH 38/45] linting: replace "await" with "wait_avail" "await" will become a keyword in Python 3.7. Signed-off-by: Bastian Stender --- labgrid/autoinstall/main.py | 2 +- labgrid/pytestplugin/fixtures.py | 2 +- labgrid/target.py | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/labgrid/autoinstall/main.py b/labgrid/autoinstall/main.py index 3406e4ad1..cf42b3b97 100644 --- a/labgrid/autoinstall/main.py +++ b/labgrid/autoinstall/main.py @@ -62,7 +62,7 @@ def _get_initial_resource(self): if not cls: return None - return self.target.get_resource(self.context[cls], await=False) + return self.target.get_resource(self.context[cls], wait_avail=False) def run(self): self.log = logging.getLogger(self.name) diff --git a/labgrid/pytestplugin/fixtures.py b/labgrid/pytestplugin/fixtures.py index 7e7f7aac0..9c3f21778 100644 --- a/labgrid/pytestplugin/fixtures.py +++ b/labgrid/pytestplugin/fixtures.py @@ -71,7 +71,7 @@ def env(request): for target_name in targets: target = env.get_target(target_name) try: - remote_place = target.get_resource(RemotePlace, await=False) + remote_place = target.get_resource(RemotePlace, wait_avail=False) remote_name = remote_place.name my_junit.add_global_property( 'TARGET_{}_REMOTE'.format(target_name.upper()), remote_name) diff --git a/labgrid/target.py b/labgrid/target.py index b94fdcaba..5a5e26627 100644 --- a/labgrid/target.py +++ b/labgrid/target.py @@ -97,7 +97,7 @@ def await_resources(self, resources, timeout=None, avail=True): self.update_resources() - def get_resource(self, cls, *, name=None, await=True): + def get_resource(self, cls, *, name=None, wait_avail=True): """ Helper function to get a resource of the target. Returns the first valid resource found, otherwise None. @@ -105,7 +105,7 @@ def get_resource(self, cls, *, name=None, await=True): Arguments: cls -- resource-class to return as a resource name -- optional name to use as a filter - await -- wait for the resource to become available (default True) + wait_avail -- wait for the resource to become available (default True) """ found = [] other_names = [] @@ -133,7 +133,7 @@ def get_resource(self, cls, *, name=None, await=True): raise NoResourceFoundError( "multiple resources matching {} found in target {}".format(cls, self) ) - if await: + if wait_avail: self.await_resources(found) return found[0] @@ -315,7 +315,7 @@ def bind_driver(self, client): try: if issubclass(requirement, Resource): suppliers.append( - self.get_resource(requirement, name=supplier_name, await=False), + self.get_resource(requirement, name=supplier_name, wait_avail=False), ) elif issubclass(requirement, (Driver, abc.ABC)): # all Protocols derive from ABC suppliers.append( From 5b4b4957a73cde06b7973b3e98a6f993b29cdf35 Mon Sep 17 00:00:00 2001 From: Bastian Stender Date: Wed, 30 May 2018 16:33:57 +0200 Subject: [PATCH 39/45] linting: remove unused variables In case unpacking gets complicated use _ for unused variables. Signed-off-by: Bastian Stender --- labgrid/binding.py | 1 - labgrid/config.py | 2 +- labgrid/factory.py | 7 +++---- labgrid/pytestplugin/reporter.py | 2 +- labgrid/remote/client.py | 14 +++++++------- labgrid/remote/coordinator.py | 2 +- labgrid/remote/exporter.py | 6 ++++-- labgrid/resource/ethernetport.py | 18 ++++++++---------- 8 files changed, 25 insertions(+), 27 deletions(-) diff --git a/labgrid/binding.py b/labgrid/binding.py index a6cc80542..7f1e1e2e1 100644 --- a/labgrid/binding.py +++ b/labgrid/binding.py @@ -45,7 +45,6 @@ class BindingMixin: state = attr.ib(default=BindingState.idle, init=False) def __attrs_post_init__(self): - binding_names = {} self.suppliers = set() self.clients = set() target = self.target diff --git a/labgrid/config.py b/labgrid/config.py index a50ec488f..f72e98441 100644 --- a/labgrid/config.py +++ b/labgrid/config.py @@ -137,7 +137,7 @@ def get_option(self, name, default=None): """ try: return str(self.data['options'][name]) - except KeyError as e: + except KeyError: if default is None: raise KeyError("no option '{}' found in configuration".format(name)) else: diff --git a/labgrid/factory.py b/labgrid/factory.py index 525eb5276..6faf613ce 100644 --- a/labgrid/factory.py +++ b/labgrid/factory.py @@ -50,7 +50,7 @@ def _convert_to_named_list(self, data): # resolve syntactic sugar (list of dicts each containing a dict of key -> args) result = [] if isinstance(data, list): - for idx, item in enumerate(data): + for item in data: if not isinstance(item, dict): raise InvalidConfigError( "invalid list item type {} (should be dict)".format(type(item))) @@ -128,20 +128,19 @@ def make_driver(self, target, driver, name, args): def make_target(self, name, config, *, env=None): from .target import Target - role = config.get('role', name) target = Target(name, env=env) for item in self._convert_to_named_list(config.get('resources', {})): resource = item.pop('cls') name = item.pop('name', None) args = item # remaining args - r = self.make_resource(target, resource, name, args) + self.make_resource(target, resource, name, args) for item in self._convert_to_named_list(config.get('drivers', {})): driver = item.pop('cls') name = item.pop('name', None) bindings = item.pop('bindings', {}) args = item # remaining args target.set_binding_map(bindings) - d = self.make_driver(target, driver, name, args) + self.make_driver(target, driver, name, args) return target diff --git a/labgrid/pytestplugin/reporter.py b/labgrid/pytestplugin/reporter.py index 02728b3a7..7f2a1b300 100644 --- a/labgrid/pytestplugin/reporter.py +++ b/labgrid/pytestplugin/reporter.py @@ -98,7 +98,7 @@ def notify(self, event): @pytest.hookimpl(hookwrapper=True, trylast=True) def pytest_runtest_logstart(self): - outcome = yield + yield self.tr._tw.write('\n') self.tr._tw._lastlen = 0 diff --git a/labgrid/remote/client.py b/labgrid/remote/client.py index 8b3735d65..8923e3476 100755 --- a/labgrid/remote/client.py +++ b/labgrid/remote/client.py @@ -149,10 +149,10 @@ async def complete(self): if self.args.type == 'resources': for exporter, groups in sorted(self.resources.items()): for group_name, group in sorted(groups.items()): - for resource_name, resource in sorted(group.items()): + for _, resource in sorted(group.items()): print("{}/{}/{}".format(exporter, group_name, resource.cls)) elif self.args.type == 'places': - for name, place in sorted(self.places.items()): + for name in sorted(self.places.keys()): print(name) async def print_resources(self): @@ -483,7 +483,7 @@ async def release(self): place = self.get_place() if not place.acquired: raise UserError("place {} is not acquired".format(place.name)) - host, user = place.acquired.split('/') + _, user = place.acquired.split('/') if user != getuser(): if not self.args.kick: raise UserError("place {} is acquired by a different user ({}), use --kick if you are sure".format(place.name, place.acquired)) # pylint: disable=line-too-long @@ -501,7 +501,7 @@ async def allow(self): place = self.get_place() if not place.acquired: raise UserError("place {} is not acquired".format(place.name)) - host, user = place.acquired.split('/') + _, user = place.acquired.split('/') if user != getuser(): raise UserError( "place {} is acquired by a different user ({})".format(place.name, place.acquired) @@ -528,7 +528,7 @@ def get_target_resources(self, place): resources = {} for resource_path in place.acquired_resources: match = place.getmatch(resource_path) - (exporter, group_name, resource_cls, resource_name) = resource_path + (exporter, group_name, _, resource_name) = resource_path name = resource_name if match.rename: name = match.rename @@ -769,7 +769,7 @@ def _get_ip(self, place): print("resource not found") return None matches = [] - for mac, details in resource.extra.get('macs').items(): + for details in resource.extra.get('macs').values(): ips = details.get('ips', []) if not ips: continue @@ -914,7 +914,7 @@ def create(): _, host, port, _, _, _ = parse_url(url) coro = loop.create_connection(transport_factory, host, port) - (transport, protocol) = loop.run_until_complete(coro) + loop.run_until_complete(coro) loop.run_until_complete(ready.wait()) return session[0] diff --git a/labgrid/remote/coordinator.py b/labgrid/remote/coordinator.py index 973949b87..b669345ba 100644 --- a/labgrid/remote/coordinator.py +++ b/labgrid/remote/coordinator.py @@ -200,7 +200,7 @@ async def _poll_step(self): fut = self.call( 'org.labgrid.exporter.{}.version'.format(session.name) ) - done, pending = await asyncio.wait([fut], timeout=5) + done, _ = await asyncio.wait([fut], timeout=5) if not done: print('kicking exporter ({}/{})'.format(session.key, session.name)) await self.on_session_leave(session.key) diff --git a/labgrid/remote/exporter.py b/labgrid/remote/exporter.py index f4852989c..1a505dad1 100755 --- a/labgrid/remote/exporter.py +++ b/labgrid/remote/exporter.py @@ -381,12 +381,14 @@ async def onDisconnect(self): self.loop.stop() async def acquire(self, group_name, resource_name): - resource = self.groups[group_name][resource_name] + # TODO: perform local actions when a resource is acquired + #resource = self.groups[group_name][resource_name] #resource.acquire() await self.update_resource(group_name, resource_name) async def release(self, group_name, resource_name): - resource = self.groups[group_name][resource_name] + # TODO: perform local actions when a resource is released + #resource = self.groups[group_name][resource_name] #resource.release() await self.update_resource(group_name, resource_name) diff --git a/labgrid/resource/ethernetport.py b/labgrid/resource/ethernetport.py index 0dbd0353f..1d5a90ffa 100644 --- a/labgrid/resource/ethernetport.py +++ b/labgrid/resource/ethernetport.py @@ -22,7 +22,7 @@ def __attrs_post_init__(self): def _autodetect(self): from pysnmp import hlapi - for (errorIndication, errorStatus, errorIndex, varBindTable) in hlapi.getCmd( + for (errorIndication, errorStatus, _, varBindTable) in hlapi.getCmd( hlapi.SnmpEngine(), hlapi.CommunityData('public'), hlapi.UdpTransportTarget((self.hostname, 161)), @@ -64,7 +64,7 @@ def _get_ports(self): ] ports = {} - for (errorIndication, errorStatus, errorIndex, varBindTable) in hlapi.bulkCmd( + for (errorIndication, errorStatus, _, varBindTable) in hlapi.bulkCmd( hlapi.SnmpEngine(), hlapi.CommunityData('public'), hlapi.UdpTransportTarget((self.hostname, 161)), @@ -78,7 +78,7 @@ def _get_ports(self): Exception("snmp error {}".format(errorStatus)) else: port = {} - for (key, val), (base, label) in zip(varBindTable, variables): + for (_, val), (_, label) in zip(varBindTable, variables): val = val.prettyPrint() if label == 'status': val = val.strip("'") @@ -97,7 +97,7 @@ def _get_fdb_dot1d(self): ports = {} - for (errorIndication, errorStatus, errorIndex, varBindTable) in hlapi.bulkCmd( + for (errorIndication, errorStatus, _, varBindTable) in hlapi.bulkCmd( hlapi.SnmpEngine(), hlapi.CommunityData('public'), hlapi.UdpTransportTarget((self.hostname, 161)), @@ -130,7 +130,7 @@ def _get_fdb_dot1q(self): ports = {} - for (errorIndication, errorStatus, errorIndex, varBindTable) in hlapi.bulkCmd( + for (errorIndication, errorStatus, _, varBindTable) in hlapi.bulkCmd( hlapi.SnmpEngine(), hlapi.CommunityData('public'), hlapi.UdpTransportTarget((self.hostname, 161)), @@ -266,10 +266,8 @@ def _get_neigh(self): line = line.decode('ascii').strip().split() addr = line.pop(0) if line[0] == 'dev': - line.pop(0) - dev = line.pop(0) - else: - dev = None + line.pop(0) # "dev" + line.pop(0) # actual dev if line[0] == 'lladdr': line.pop(0) lladdr = line.pop(0) @@ -277,7 +275,7 @@ def _get_neigh(self): lladdr = None if line[0] == 'router': line.pop() - state = line.pop(0) + line.pop(0) # state assert not line # TODO: check if we could use the device and state information neighbors.setdefault(lladdr, []).append(addr) From 1024802367f715dd414d6512412e969067fb49a6 Mon Sep 17 00:00:00 2001 From: Bastian Stender Date: Wed, 30 May 2018 16:41:55 +0200 Subject: [PATCH 40/45] linting: use lazy logging See pylint error messge W1201. Signed-off-by: Bastian Stender --- labgrid/driver/shelldriver.py | 16 ++++++++-------- labgrid/remote/exporter.py | 8 +++----- labgrid/resource/ethernetport.py | 5 ++--- labgrid/resource/remote.py | 7 +++---- labgrid/resource/udev.py | 6 +++--- labgrid/target.py | 3 +-- labgrid/util/qmp.py | 2 +- 7 files changed, 21 insertions(+), 26 deletions(-) diff --git a/labgrid/driver/shelldriver.py b/labgrid/driver/shelldriver.py index ab7aed7e4..19788435f 100644 --- a/labgrid/driver/shelldriver.py +++ b/labgrid/driver/shelldriver.py @@ -269,16 +269,16 @@ def _xmodem_getc(self, size, timeout=10): # something of the XMODEM protocol data into its internal buffers: xpct = self.console.expect(r'.{%d}' % size, timeout=timeout) s = xpct[2].group() - self.logger.debug('XMODEM GETC({}): read {}'.format(size, repr(s))) + self.logger.debug('XMODEM GETC(%d): read %r', size, s) return s except TIMEOUT: - self.logger.debug('XMODEM GETC({}): TIMEOUT after {} seconds' .format(size, timeout)) + self.logger.debug('XMODEM GETC(%s): TIMEOUT after %d seconds', size, timeout) return None def _xmodem_putc(self, data, timeout=1): """ called by the xmodem.XMODEM instance to write protocol data to the console """ # Note: we ignore the timeout because we cannot pass it through. - self.logger.debug('XMODEM PUTC: {}'.format(repr(data))) + self.logger.debug('XMODEM PUTC: %r', data) self.console.write(data) return len(data) @@ -346,7 +346,7 @@ def _target_cleanup(tmpfile): try: rx_cmd = self._get_xmodem_rx_cmd(tmpfile) - self.logger.debug('XMODEM receive command on target: ' + rx_cmd) + self.logger.debug('XMODEM receive command on target: %s', rx_cmd) except ExecutionError: _target_cleanup(tmpfile) raise @@ -355,13 +355,13 @@ def _target_cleanup(tmpfile): modem = xmodem.XMODEM(self._xmodem_getc, self._xmodem_putc) ret = modem.send(stream) - self.logger.debug('xmodem.send() returned %r' % ret) + self.logger.debug('xmodem.send() returned %r', ret) self.console.expect(self.prompt, timeout=30) # truncate the file to get rid of CPMEOF padding dd_cmd = "dd if='{}' of='{}' bs=1 count={}".format(tmpfile, remotefile, len(buf)) - self.logger.debug('dd command: ' + dd_cmd) + self.logger.debug('dd command: %s', dd_cmd) out, _, ret = self._run(dd_cmd) _target_cleanup(tmpfile) @@ -410,7 +410,7 @@ def _get_bytes(self, remotefile: str): buf = io.BytesIO() cmd = self._get_xmodem_sx_cmd(remotefile) - self.logger.info('XMODEM send command on target: ' + cmd) + self.logger.info('XMODEM send command on target: %s', cmd) # get file size to remove XMODEM's CPMEOF padding at the end of the last packet out, _, ret = self._run("stat '{}'".format(remotefile)) @@ -425,7 +425,7 @@ def _get_bytes(self, remotefile: str): modem = xmodem.XMODEM(self._xmodem_getc, self._xmodem_putc) recvd_size = modem.recv(buf) - self.logger.debug('xmodem.recv() returned %r' % recvd_size) + self.logger.debug('xmodem.recv() returned %r', recvd_size) # remove CPMEOF (0x1a) padding if recvd_size < file_size: diff --git a/labgrid/remote/exporter.py b/labgrid/remote/exporter.py index 1a505dad1..608d9e933 100755 --- a/labgrid/remote/exporter.py +++ b/labgrid/remote/exporter.py @@ -81,7 +81,7 @@ def need_restart(self): """ start_params = self._get_start_params() if self.start_params != start_params: - self.logger.info("restart needed ({} -> {})".format(self.start_params, start_params)) + self.logger.info("restart needed (%s -> %s)", self.start_params, start_params) return True return False @@ -152,8 +152,7 @@ def _start(self, start_params): self.port, start_params['path'] ), ]) - self.logger.info("started ser2net for {} on port {}".format( - start_params['path'], self.port)) + self.logger.info("started ser2net for %s on port %d", start_params['path'], self.port) def _stop(self, start_params): """Stop spawned subprocess""" @@ -167,8 +166,7 @@ def _stop(self, start_params): except subprocess.TimeoutExpired: child.kill() child.wait(1.0) - self.logger.info("stopped ser2net for {} on port {}".format( - start_params['path'], self.port)) + self.logger.info("stopped ser2net for %s on port %d", start_params['path'], self.port) exports["USBSerialPort"] = USBSerialPortExport diff --git a/labgrid/resource/ethernetport.py b/labgrid/resource/ethernetport.py index 1d5a90ffa..e696f19d1 100644 --- a/labgrid/resource/ethernetport.py +++ b/labgrid/resource/ethernetport.py @@ -42,8 +42,7 @@ def _autodetect(self): else: Exception("unsupported switch {}".format(sysDescr)) - self.logger.debug("autodetected switch{}: {} {}".format( - sysDescr, self._get_ports, self._get_fdb)) + self.logger.debug("autodetected switch%s: %s %s", sysDescr, self._get_ports, self._get_fdb) def _get_ports(self): """Fetch ports and their values via SNMP @@ -307,7 +306,7 @@ def poll(self): extra.update(switch.ports.get(resource.interface, {})) if resource.extra != extra: resource.extra = extra - self.logger.debug("new information for {}: {}".format(resource, extra)) + self.logger.debug("new information for %s: %s", resource, extra) @target_factory.reg_resource diff --git a/labgrid/resource/remote.py b/labgrid/resource/remote.py index 5391381ad..70e8f2f70 100644 --- a/labgrid/resource/remote.py +++ b/labgrid/resource/remote.py @@ -56,8 +56,7 @@ def on_resource_added(self, resource): if not isinstance(new, ManagedResource): self.unmanaged_resources.append(new) expanded.append(new) - self.logger.debug("expanded remote resources for place {}: {}".format( - remote_place.name, expanded)) + self.logger.debug("expanded remote resources for place %s: %s", remote_place.name, expanded) remote_place.avail = True def poll(self): @@ -82,9 +81,9 @@ def poll(self): if v_old != v_new: changes.append((k, v_old, v_new)) if changes: - self.logger.debug("changed attributes for {}:".format(resource)) + self.logger.debug("changed attributes for %s:", resource) for k, v_old, v_new in changes: - self.logger.debug(" {}: {} -> {}".format(k, v_old, v_new)) + self.logger.debug(" %s: %s -> %s", k, v_old, v_new) @target_factory.reg_resource diff --git a/labgrid/resource/udev.py b/labgrid/resource/udev.py index 99ab88403..600ce3b7a 100644 --- a/labgrid/resource/udev.py +++ b/labgrid/resource/udev.py @@ -28,9 +28,9 @@ def on_resource_added(self, resource): def poll(self): for device in iter(partial(self._monitor.poll, 0), None): - self.log.debug("{0.action}: {0}".format(device)) + self.log.debug("%s: %s", device.action, device) for resource in self.resources: - self.log.debug(" {}".format(resource)) + self.log.debug(" %s", resource) if resource.try_match(device): break @@ -81,7 +81,7 @@ def match_ancestors(key, value): if not self.filter_match(device): return False - self.log.debug(" found match: {}".format(self)) + self.log.debug(" found match: %s", self) if device.action in [None, 'add']: if self.avail: warnings.warn("udev device {} is already available".format(device)) diff --git a/labgrid/target.py b/labgrid/target.py index 5a5e26627..fab1488ec 100644 --- a/labgrid/target.py +++ b/labgrid/target.py @@ -50,8 +50,7 @@ def update_resources(self): manager.poll() for resource in resources: if not resource.avail and resource.state is BindingState.active: - self.log.info("deactivating unavailable resource {}".format( - resource.display_name)) + self.log.info("deactivating unavailable resource %s", resource.display_name) # pylint: disable=line-too-long self.deactivate(resource) def await_resources(self, resources, timeout=None, avail=True): diff --git a/labgrid/util/qmp.py b/labgrid/util/qmp.py index c8206bccb..de0ac6bda 100644 --- a/labgrid/util/qmp.py +++ b/labgrid/util/qmp.py @@ -27,7 +27,7 @@ def _negotiate_capabilities(self): def _read_parse_json(self): line = self.monitor_out.readline().decode('utf-8') - self.logger.debug("Received line:{}".format(line)) + self.logger.debug("Received line: %s", line) return json.loads(line) def execute(self, command): From 3248565bf25fed678162aaae0a804cc8c43f2f0d Mon Sep 17 00:00:00 2001 From: Bastian Stender Date: Mon, 4 Jun 2018 19:23:57 +0200 Subject: [PATCH 41/45] remote/common: remove unnecessary lambda in Place Signed-off-by: Bastian Stender --- labgrid/remote/common.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/labgrid/remote/common.py b/labgrid/remote/common.py index be08dc554..4d7c62a13 100644 --- a/labgrid/remote/common.py +++ b/labgrid/remote/common.py @@ -103,8 +103,8 @@ class Place: acquired = attr.ib(default=None) acquired_resources = attr.ib(default=attr.Factory(list)) allowed = attr.ib(default=attr.Factory(set), convert=set) - created = attr.ib(default=attr.Factory(lambda: time.time())) - changed = attr.ib(default=attr.Factory(lambda: time.time())) + created = attr.ib(default=attr.Factory(time.time)) + changed = attr.ib(default=attr.Factory(time.time)) def asdict(self): result = attr.asdict(self) From 2bdba80b3370017d49d307dbd8febd12fc36b929 Mon Sep 17 00:00:00 2001 From: Bastian Stender Date: Wed, 30 May 2018 16:51:12 +0200 Subject: [PATCH 42/45] linting: annotate pylint exceptions Signed-off-by: Bastian Stender --- labgrid/autoinstall/main.py | 2 +- labgrid/driver/bareboxdriver.py | 2 +- labgrid/driver/shelldriver.py | 7 ++++--- labgrid/provider/mediafileprovider.py | 2 +- labgrid/remote/authenticator.py | 2 +- labgrid/remote/common.py | 7 ++++--- labgrid/remote/coordinator.py | 4 ++-- labgrid/remote/exporter.py | 3 ++- labgrid/resource/udev.py | 3 ++- labgrid/step.py | 2 +- labgrid/strategy/bareboxstrategy.py | 2 +- labgrid/strategy/shellstrategy.py | 2 +- labgrid/util/agent.py | 2 +- 13 files changed, 22 insertions(+), 18 deletions(-) diff --git a/labgrid/autoinstall/main.py b/labgrid/autoinstall/main.py index cf42b3b97..f2077667a 100644 --- a/labgrid/autoinstall/main.py +++ b/labgrid/autoinstall/main.py @@ -47,7 +47,7 @@ def _get_setup_function(self): context['log'] = self.log.getChild('setup') setup = self._get_function('setup', self.context) if setup is None: - def setup(): + def setup(): # pylint: disable=function-redefined pass return setup diff --git a/labgrid/driver/bareboxdriver.py b/labgrid/driver/bareboxdriver.py index e45421cb4..f8dfd6387 100644 --- a/labgrid/driver/bareboxdriver.py +++ b/labgrid/driver/bareboxdriver.py @@ -58,7 +58,7 @@ def on_deactivate(self): @Driver.check_active @step(args=['cmd']) - def run(self, cmd: str, *, step, timeout: int = 30): + def run(self, cmd: str, *, step, timeout: int = 30): # pylint: disable=unused-argument """ Runs the specified command on the shell and returns the output. diff --git a/labgrid/driver/shelldriver.py b/labgrid/driver/shelldriver.py index 19788435f..d987efe75 100644 --- a/labgrid/driver/shelldriver.py +++ b/labgrid/driver/shelldriver.py @@ -1,4 +1,4 @@ -# pylint: disable=no-member +# pylint: disable=no-member,missing-kwoa,unused-argument """The ShellDriver provides the CommandProtocol, ConsoleProtocol and InfoProtocol on top of a SerialPort.""" import io @@ -61,7 +61,8 @@ def on_activate(self): self._inject_run() if self.keyfile: self._put_ssh_key(self.keyfile) - self._run("dmesg -n 1") # Turn off Kernel Messages to the console + # Turn off Kernel Messages to the console + self._run("dmesg -n 1") def on_deactivate(self): self._status = 0 @@ -161,7 +162,7 @@ def _await_login(self): last_before = before if time.time() > start + self.login_timeout: - raise TIMEOUT("Timeout of {} seconds exceeded during waiting for login".format(self.login_timeout)) + raise TIMEOUT("Timeout of {} seconds exceeded during waiting for login".format(self.login_timeout)) # pylint: disable=line-too-long @step() def get_status(self): diff --git a/labgrid/provider/mediafileprovider.py b/labgrid/provider/mediafileprovider.py index d00f598cf..4fb801b06 100644 --- a/labgrid/provider/mediafileprovider.py +++ b/labgrid/provider/mediafileprovider.py @@ -12,7 +12,7 @@ def _add_file(self, name: str, remote_path, local_path): group[remote_path] = local_path def get(self, name): - return self.groups[name] + return self.groups[name] # pylint: disable=unsubscriptable-object def list(self): return list(self.groups.keys()) diff --git a/labgrid/remote/authenticator.py b/labgrid/remote/authenticator.py index d59abaa4f..0378a64ab 100644 --- a/labgrid/remote/authenticator.py +++ b/labgrid/remote/authenticator.py @@ -6,7 +6,7 @@ class AuthenticatorSession(ApplicationSession): @inlineCallbacks def onJoin(self, details): - def authenticate(realm, authid, details): + def authenticate(realm, authid, details): # pylint: disable=unused-argument pprint(details) principal = {'role': 'public', 'extra': {}} return principal diff --git a/labgrid/remote/common.py b/labgrid/remote/common.py index 4d7c62a13..81cd0687d 100644 --- a/labgrid/remote/common.py +++ b/labgrid/remote/common.py @@ -1,3 +1,4 @@ +# pylint: disable=unsubscriptable-object import socket import time from datetime import datetime @@ -116,11 +117,11 @@ def show(self, level=0): print(indent + "aliases: {}".format(', '.join(self.aliases))) print(indent + "comment: {}".format(self.comment)) print(indent + "matches:") - for match in self.matches: + for match in self.matches: # pylint: disable=not-an-iterable print(indent + " {}".format(match)) print(indent + "acquired: {}".format(self.acquired)) print(indent + "acquired resources:") - for resource_path in self.acquired_resources: + for resource_path in self.acquired_resources: # pylint: disable=not-an-iterable match = self.getmatch(resource_path) if match.rename: print(indent + " {} → {}".format( @@ -137,7 +138,7 @@ def getmatch(self, resource_path): A resource_path has the structure (exporter, group, cls, name). """ - for match in self.matches: + for match in self.matches: # pylint: disable=not-an-iterable if match.ismatch(resource_path): return match diff --git a/labgrid/remote/coordinator.py b/labgrid/remote/coordinator.py index b669345ba..809678e20 100644 --- a/labgrid/remote/coordinator.py +++ b/labgrid/remote/coordinator.py @@ -1,5 +1,5 @@ """The coordinator module coordinates exported resources and clients accessing them.""" -# pylint: disable=no-member +# pylint: disable=no-member,unused-argument import asyncio import traceback from collections import defaultdict @@ -332,7 +332,7 @@ async def set_resource(self, groupname, resourcename, resource, details=None): action, resource_path = session.set_resource(groupname, resourcename, resource) if action is Action.ADD: self._add_default_place(groupname) - await self._update_acquired_places(action, resource_path) + await self._update_acquired_places(action, resource_path) # pylint: disable=not-an-iterable self.save_later() def _get_resources(self): diff --git a/labgrid/remote/exporter.py b/labgrid/remote/exporter.py index 608d9e933..211827dad 100755 --- a/labgrid/remote/exporter.py +++ b/labgrid/remote/exporter.py @@ -1,5 +1,6 @@ """The remote.exporter module exports resources to the coordinator and makes them available to other clients on the same coordinator""" +# pylint: disable=unsupported-assignment-operation import argparse import asyncio import logging @@ -101,7 +102,7 @@ def poll(self): if self.local.avail and self.need_restart(): self.stop() self.start() - self.data['params'].update(params) + self.data['params'].update(params) # pylint: disable=unsubscriptable-object dirty = True return dirty diff --git a/labgrid/resource/udev.py b/labgrid/resource/udev.py index 600ce3b7a..312fe66b5 100644 --- a/labgrid/resource/udev.py +++ b/labgrid/resource/udev.py @@ -1,3 +1,4 @@ +# pylint: disable=unsupported-assignment-operation from functools import partial import logging import os @@ -48,7 +49,7 @@ def __attrs_post_init__(self): self.match.setdefault('SUBSYSTEM', 'usb') super().__attrs_post_init__() - def filter_match(self, device): + def filter_match(self, device): # pylint: disable=unused-argument return True def try_match(self, device): diff --git a/labgrid/step.py b/labgrid/step.py index 7f26c55b2..8816d80bb 100644 --- a/labgrid/step.py +++ b/labgrid/step.py @@ -182,7 +182,7 @@ def __del__(self): warnings.warn("__del__ called before {} was done".format(step)) -def step(*, title=None, args=[], result=False, tag=None): +def step(*, title=None, args=[], result=False, tag=None): # pylint: disable=unused-argument def decorator(func): # resolve default title nonlocal title diff --git a/labgrid/strategy/bareboxstrategy.py b/labgrid/strategy/bareboxstrategy.py index 24135f1ee..cb39f3969 100644 --- a/labgrid/strategy/bareboxstrategy.py +++ b/labgrid/strategy/bareboxstrategy.py @@ -47,7 +47,7 @@ def transition(self, status, *, step): self.target.activate(self.barebox) elif status == Status.shell: # tansition to barebox - self.transition(Status.barebox) + self.transition(Status.barebox) # pylint: disable=missing-kwoa self.barebox.boot("") self.barebox.await_boot() self.target.activate(self.shell) diff --git a/labgrid/strategy/shellstrategy.py b/labgrid/strategy/shellstrategy.py index 57654ffbd..6c2189408 100644 --- a/labgrid/strategy/shellstrategy.py +++ b/labgrid/strategy/shellstrategy.py @@ -43,7 +43,7 @@ def transition(self, status, *, step): self.target.activate(self.power) self.power.off() elif status == Status.shell: - self.transition(Status.off) + self.transition(Status.off) # pylint: disable=missing-kwoa self.power.cycle() self.target.activate(self.shell) else: diff --git a/labgrid/util/agent.py b/labgrid/util/agent.py index b45347bf4..48af4a85a 100644 --- a/labgrid/util/agent.py +++ b/labgrid/util/agent.py @@ -47,7 +47,7 @@ def run(self): self._send({'exception': repr(e)}) break -def handle_test(*args, **kwargs): +def handle_test(*args, **kwargs): # pylint: disable=unused-argument return args[::-1] def handle_error(message): From eec9ac527e559685d540a865f64d9ab9ba4e0af7 Mon Sep 17 00:00:00 2001 From: Bastian Stender Date: Thu, 31 May 2018 12:10:44 +0200 Subject: [PATCH 43/45] setup.py: add PyPI classifiers Signed-off-by: Bastian Stender --- setup.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 9ec3a1ab0..e731ea3eb 100755 --- a/setup.py +++ b/setup.py @@ -60,6 +60,12 @@ 'labgrid-autoinstall = labgrid.autoinstall.main:main', ] }, - # custom PyPI classifier for pytest plugins - classifiers=["Framework :: Pytest", ], + # custom PyPI classifiers + classifiers=[ + "Topic :: Software Development :: Testing", + "Framework :: Pytest", + "Programming Language :: Python :: 3 :: Only", + "Programming Language :: Python :: 3.5", + "Programming Language :: Python :: 3.6", + ], ) From 3906095656a6ad62f293937cae597cca29541334 Mon Sep 17 00:00:00 2001 From: Bastian Stender Date: Thu, 31 May 2018 23:23:41 +0200 Subject: [PATCH 44/45] travis: requirements: move travis requirements to separate file Signed-off-by: Bastian Stender --- .travis.yml | 4 +--- crossbar-requirements.txt | 1 + travis-requirements.txt | 3 +++ 3 files changed, 5 insertions(+), 3 deletions(-) create mode 100644 travis-requirements.txt diff --git a/.travis.yml b/.travis.yml index b2c934f6b..f7959f73a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,9 +6,7 @@ before_install: - sudo apt-get -qq update - sudo apt-get install -y libow-dev install: - - pip install --upgrade setuptools - - pip install --upgrade pytest pytest-mock pytest-cov coveralls codecov - - pip install -r dev-requirements.txt + - pip install -r travis-requirements.txt - pip install -e . script: - pytest --cov-config .coveragerc --cov=labgrid diff --git a/crossbar-requirements.txt b/crossbar-requirements.txt index 726f6251d..e1c9f84ce 100644 --- a/crossbar-requirements.txt +++ b/crossbar-requirements.txt @@ -1,4 +1,5 @@ -r requirements.txt +setuptools>=38.0.0 crossbar==17.12.1 # For crossbar idna==2.5 \ No newline at end of file diff --git a/travis-requirements.txt b/travis-requirements.txt new file mode 100644 index 000000000..21a6c5491 --- /dev/null +++ b/travis-requirements.txt @@ -0,0 +1,3 @@ +coveralls>=1.3.0 +codecov>=2.0.15 +-r dev-requirements.txt From ed61360bea99534874cdc06a7964c9d8f14d737b Mon Sep 17 00:00:00 2001 From: Bastian Stender Date: Mon, 4 Jun 2018 18:52:29 +0200 Subject: [PATCH 45/45] travis: fix and simplify accidental git diff with pager This makes travis stall in case the diff is big enough that git decides to display it in a pager. Signed-off-by: Bastian Stender --- .travis.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index f7959f73a..11d64d9d2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,8 +12,7 @@ script: - pytest --cov-config .coveragerc --cov=labgrid - python setup.py build_sphinx - make -C man all - - git diff - - git diff-index --quiet HEAD -- + - git --no-pager diff --exit-code after_success: - coveralls - codecov