tools: flake8 fixes for the various python files

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
Peter Hutterer 2019-09-11 10:00:33 +10:00
parent 975ff2fb6e
commit 27632555e1
8 changed files with 103 additions and 105 deletions

View file

@ -476,6 +476,15 @@ fedora:30@usr-bin-env-python:
/bin/false
fi
fedora:30@flake8:
extends: .fedora-build@template
variables:
FEDORA_VERSION: 30
before_script:
- dnf install -y python3-flake8
script:
- flake8-3 --ignore=W501,E501,W504 $(git grep -l '^#!/usr/bin/env python3')
#
# Ubuntu
#

View file

@ -101,10 +101,10 @@ class Device(libevdev.Device):
property. Returns None if the property doesn't exist'''
axes = {
0x00: self.udev_device.get('LIBINPUT_FUZZ_00'),
0x01: self.udev_device.get('LIBINPUT_FUZZ_01'),
0x35: self.udev_device.get('LIBINPUT_FUZZ_35'),
0x36: self.udev_device.get('LIBINPUT_FUZZ_36'),
0x00: self.udev_device.get('LIBINPUT_FUZZ_00'),
0x01: self.udev_device.get('LIBINPUT_FUZZ_01'),
0x35: self.udev_device.get('LIBINPUT_FUZZ_35'),
0x36: self.udev_device.get('LIBINPUT_FUZZ_36'),
}
if axes[0x35] is not None:
@ -122,7 +122,7 @@ class Device(libevdev.Device):
return None
if ((xfuzz is not None and yfuzz is None) or
(xfuzz is None and yfuzz is not None)):
(xfuzz is None and yfuzz is not None)):
raise InvalidConfigurationError('fuzz should be set for both axes')
return (xfuzz, yfuzz)
@ -138,12 +138,12 @@ class Device(libevdev.Device):
if self.has(libevdev.EV_ABS.ABS_MT_POSITION_X) != self.has(libevdev.EV_ABS.ABS_MT_POSITION_Y):
raise InvalidDeviceError('device does not have both multitouch axes')
xfuzz = self.absinfo[libevdev.EV_ABS.ABS_X].fuzz or \
self.absinfo[libevdev.EV_ABS.ABS_MT_POSITION_X].fuzz
yfuzz = self.absinfo[libevdev.EV_ABS.ABS_Y].fuzz or \
self.absinfo[libevdev.EV_ABS.ABS_MT_POSITION_Y].fuzz
xfuzz = (self.absinfo[libevdev.EV_ABS.ABS_X].fuzz or
self.absinfo[libevdev.EV_ABS.ABS_MT_POSITION_X].fuzz)
yfuzz = (self.absinfo[libevdev.EV_ABS.ABS_Y].fuzz or
self.absinfo[libevdev.EV_ABS.ABS_MT_POSITION_Y].fuzz)
if xfuzz is 0 and yfuzz is 0:
if xfuzz == 0 and yfuzz == 0:
return None
return (xfuzz, yfuzz)
@ -169,10 +169,10 @@ def handle_existing_entry(device, fuzz):
# If the lines aren't in the same order in the file, it'll be a false
# negative.
overrides = {
0x00: device.udev_device.get('EVDEV_ABS_00'),
0x01: device.udev_device.get('EVDEV_ABS_01'),
0x35: device.udev_device.get('EVDEV_ABS_35'),
0x36: device.udev_device.get('EVDEV_ABS_36'),
0x00: device.udev_device.get('EVDEV_ABS_00'),
0x01: device.udev_device.get('EVDEV_ABS_01'),
0x35: device.udev_device.get('EVDEV_ABS_35'),
0x36: device.udev_device.get('EVDEV_ABS_36'),
}
has_existing_rules = False
@ -193,8 +193,8 @@ def handle_existing_entry(device, fuzz):
template = [' EVDEV_ABS_00={}'.format(overrides[0x00]),
' EVDEV_ABS_01={}'.format(overrides[0x01])]
if overrides[0x35] is not None:
template += [' EVDEV_ABS_35={}'.format(overrides[0x35]),
' EVDEV_ABS_36={}'.format(overrides[0x36])]
template += [' EVDEV_ABS_35={}'.format(overrides[0x35]),
' EVDEV_ABS_36={}'.format(overrides[0x36])]
print('Checking in {}... '.format(OVERRIDE_HWDB_FILE), end='')
entry, prefix, lineno = check_file_for_lines(OVERRIDE_HWDB_FILE, template)
@ -410,11 +410,11 @@ def write_udev_rule(device, fuzz):
def main(args):
parser = argparse.ArgumentParser(
description='Print fuzz settings and/or suggest udev rules for the fuzz to be adjusted.'
description='Print fuzz settings and/or suggest udev rules for the fuzz to be adjusted.'
)
parser.add_argument('path', metavar='/dev/input/event0',
nargs='?', type=str, help='Path to device (optional)')
parser.add_argument('--fuzz', type=int, help='Suggested fuzz')
parser.add_argument('--fuzz', type=int, help='Suggested fuzz')
args = parser.parse_args()
try:

View file

@ -87,9 +87,9 @@ class Touch(object):
def __str__(self):
s = "Touch: major {:3d}".format(self.major)
if self.minor is not None:
s += ", minor {:3d}".format(self.minor)
s += ", minor {:3d}".format(self.minor)
if self.orientation is not None:
s += ", orientation {:+3d}".format(self.orientation)
s += ", orientation {:+3d}".format(self.orientation)
return s
@ -119,17 +119,15 @@ class TouchSequence(object):
self.major_range.update(touch.major)
self.minor_range.update(touch.minor)
if touch.major < self.device.up or \
touch.minor < self.device.up:
self.is_down = False
elif touch.major > self.device.down or \
touch.minor > self.device.down:
if touch.major < self.device.up or touch.minor < self.device.up:
self.is_down = False
elif touch.major > self.device.down or touch.minor > self.device.down:
self.is_down = True
self.was_down = True
self.is_palm = touch.major > self.device.palm
if self.is_palm:
self.was_palm = True
self.was_palm = True
self.is_thumb = self.device.thumb != 0 and touch.major > self.device.thumb
if self.is_thumb:
@ -147,16 +145,14 @@ class TouchSequence(object):
return "{:78s}".format("Sequence: no major/minor values recorded")
s = "Sequence: major: [{:3d}..{:3d}] ".format(
self.major_range.min, self.major_range.max
self.major_range.min, self.major_range.max
)
if self.device.has_minor:
s += "minor: [{:3d}..{:3d}] ".format(
self.minor_range.min, self.minor_range.max
)
s += "minor: [{:3d}..{:3d}] ".format(self.minor_range.min, self.minor_range.max)
if self.was_down:
s += " down"
s += " down"
if self.was_palm:
s += " palm"
s += " palm"
if self.was_thumb:
s += " thumb"
@ -164,12 +160,10 @@ class TouchSequence(object):
def _str_state(self):
touch = self.points[-1]
s = "{}, tags: {} {} {}".format(
touch,
"down" if self.is_down else " ",
"palm" if self.is_palm else " ",
"thumb" if self.is_thumb else " "
)
s = "{}, tags: {} {} {}".format(touch,
"down" if self.is_down else " ",
"palm" if self.is_palm else " ",
"thumb" if self.is_thumb else " ")
return s
@ -250,27 +244,27 @@ class Device(libevdev.Device):
libevdev.EV_KEY.BTN_TOOL_QUADTAP,
libevdev.EV_KEY.BTN_TOOL_QUINTTAP]
if event.code in tapcodes and event.value > 0:
print("\rThis tool cannot handle multiple fingers, "
"output will be invalid", file=sys.stderr)
print("\rThis tool cannot handle multiple fingers, "
"output will be invalid", file=sys.stderr)
def handle_abs(self, event):
if event.matches(libevdev.EV_ABS.ABS_MT_TRACKING_ID):
if event.value > -1:
self.start_new_sequence(event.value)
else:
try:
s = self.current_sequence()
s.finalize()
print("\r{}".format(s))
except IndexError:
# If the finger was down during start
pass
if event.value > -1:
self.start_new_sequence(event.value)
else:
try:
s = self.current_sequence()
s.finalize()
print("\r{}".format(s))
except IndexError:
# If the finger was down during start
pass
elif event.matches(libevdev.EV_ABS.ABS_MT_TOUCH_MAJOR):
self.touch.major = event.value
self.touch.major = event.value
elif event.matches(libevdev.EV_ABS.ABS_MT_TOUCH_MINOR):
self.touch.minor = event.value
self.touch.minor = event.value
elif event.matches(libevdev.EV_ABS.ABS_MT_ORIENTATION):
self.touch.orientation = event.value
self.touch.orientation = event.value
def handle_syn(self, event):
if self.touch.dirty:
@ -310,7 +304,7 @@ def colon_tuple(string):
t = tuple([int(x) for x in ts])
if len(t) == 2 and t[0] >= t[1]:
return t
except:
except: # noqa
pass
msg = "{} is not in format N:M (N >= M)".format(string)
@ -318,9 +312,7 @@ def colon_tuple(string):
def main(args):
parser = argparse.ArgumentParser(
description="Measure touch size and orientation"
)
parser = argparse.ArgumentParser(description="Measure touch size and orientation")
parser.add_argument('path', metavar='/dev/input/event0',
nargs='?', type=str, help='Path to device (optional)')
parser.add_argument('--touch-thresholds', metavar='down:up',
@ -345,7 +337,7 @@ def main(args):
except (PermissionError, OSError):
print("Error: failed to open device")
except InvalidDeviceError as e:
print("This device does not have the capabilities for size-based touch detection.");
print("This device does not have the capabilities for size-based touch detection.")
print("Details: {}".format(e))

View file

@ -99,12 +99,12 @@ class TouchSequence(object):
def avg(self):
"""Average pressure value of this sequence"""
return int(sum([p.pressure for p in self.points])/len(self.points))
return int(sum([p.pressure for p in self.points]) / len(self.points))
def median(self):
"""Median pressure value of this sequence"""
ps = sorted([p.pressure for p in self.points])
idx = int(len(self.points)/2)
idx = int(len(self.points) / 2)
return ps[idx]
def __str__(self):
@ -280,7 +280,7 @@ def colon_tuple(string):
t = tuple([int(x) for x in ts])
if len(t) == 2 and t[0] >= t[1]:
return t
except:
except: # noqa
pass
msg = "{} is not in format N:M (N >= M)".format(string)
@ -320,7 +320,7 @@ def main(args):
except (PermissionError, OSError):
print("Error: failed to open device")
except InvalidDeviceError as e:
print("This device does not have the capabilities for pressure-based touch detection.");
print("This device does not have the capabilities for pressure-based touch detection.")
print("Details: {}".format(e))

View file

@ -52,7 +52,7 @@ def tv2us(sec, usec):
def us2ms(us):
return int(us/1000)
return int(us / 1000)
class Touch(object):
@ -103,7 +103,7 @@ class Device(libevdev.Device):
device_node = None
for device in context.list_devices(subsystem='input'):
if (not device.device_node or
not device.device_node.startswith('/dev/input/event')):
not device.device_node.startswith('/dev/input/event')):
continue
# pick the touchpad by default, fallback to the first
@ -165,12 +165,12 @@ class Device(libevdev.Device):
dmax = max(deltas)
dmin = min(deltas)
l = len(deltas)
ndeltas = len(deltas)
davg = sum(deltas)/l
dmedian = deltas[int(l/2)]
d95pc = deltas[int(l * 0.95)]
d90pc = deltas[int(l * 0.90)]
davg = sum(deltas) / ndeltas
dmedian = deltas[int(ndeltas / 2)]
d95pc = deltas[int(ndeltas * 0.95)]
d90pc = deltas[int(ndeltas * 0.90)]
print("Time: ")
print(" Max delta: {}ms".format(int(dmax)))
@ -220,9 +220,7 @@ class Device(libevdev.Device):
def main(args):
parser = argparse.ArgumentParser(
description="Measure tap-to-click properties of devices"
)
parser = argparse.ArgumentParser(description="Measure tap-to-click properties of devices")
parser.add_argument('path', metavar='/dev/input/event0',
nargs='?', type=str, help='Path to device (optional)')
parser.add_argument('--format', metavar='format',

View file

@ -61,7 +61,7 @@ class TestYaml(unittest.TestCase):
for ev in libinput:
if (filter is None or ev['type'] == filter or
isinstance(filter, list) and ev['type'] in filter):
isinstance(filter, list) and ev['type'] in filter):
yield ev
def test_sections_exist(self):
@ -632,7 +632,8 @@ class TestYaml(unittest.TestCase):
self.assertTrue(isinstance(wd, 1))
self.assertGreaterEqual(wd, 0.0)
def sign(x): (1, -1)[x < 0]
def sign(x):
(1, -1)[x < 0]
self.assertTrue(sign(w), sign(wd))
except KeyError:
pass

View file

@ -127,14 +127,14 @@ def replay(device, verbose):
# The first event may have a nonzero offset but we want to replay
# immediately regardless.
if not handled_first_event:
offset -= sec + usec/1.e6
offset -= sec + usec / 1.e6
handled_first_event = True
evtime = sec + usec/1e6 + offset
evtime = sec + usec / 1e6 + offset
now = time.time()
if evtime - now > 150/1e6: # 150 µs error margin
time.sleep(evtime - now - 150/1e6)
if evtime - now > 150 / 1e6: # 150 µs error margin
time.sleep(evtime - now - 150 / 1e6)
evs = [libevdev.InputEvent(libevdev.evbit(e[2], e[3]), value=e[4], sec=e[0], usec=e[1]) for e in evdev]
uinput.send_events(evs)
@ -224,9 +224,7 @@ def check_file(recording):
def main():
parser = argparse.ArgumentParser(
description='Replay a device recording'
)
parser = argparse.ArgumentParser(description='Replay a device recording')
parser.add_argument('recording', metavar='recorded-file.yaml',
type=str, help='Path to device recording')
parser.add_argument('--verbose', action='store_true')

View file

@ -115,28 +115,28 @@ class TestLibinputCommand(TestLibinputTool):
class TestToolWithOptions(object):
options = {
'pattern': ['sendevents'],
# enable/disable options
'enable-disable': [
'tap',
'drag',
'drag-lock',
'middlebutton',
'natural-scrolling',
'left-handed',
'dwt'
],
# options with distinct values
'enums': {
'set-click-method': ['none', 'clickfinger', 'buttonareas'],
'set-scroll-method': ['none', 'twofinger', 'edge', 'button'],
'set-profile': ['adaptive', 'flat'],
'set-tap-map': ['lrm', 'lmr'],
},
# options with a range
'ranges': {
'set-speed': (float, -1.0, +1.0),
}
'pattern': ['sendevents'],
# enable/disable options
'enable-disable': [
'tap',
'drag',
'drag-lock',
'middlebutton',
'natural-scrolling',
'left-handed',
'dwt'
],
# options with distinct values
'enums': {
'set-click-method': ['none', 'clickfinger', 'buttonareas'],
'set-scroll-method': ['none', 'twofinger', 'edge', 'button'],
'set-profile': ['adaptive', 'flat'],
'set-tap-map': ['lrm', 'lmr'],
},
# options with a range
'ranges': {
'set-speed': (float, -1.0, +1.0),
}
}
def test_udev_seat(self):
@ -171,7 +171,7 @@ class TestToolWithOptions(object):
for option, values in self.options['ranges'].items():
range_type, minimum, maximum = values
self.assertEqual(range_type, float)
step = (maximum - minimum)/10.0
step = (maximum - minimum) / 10.0
value = minimum
while value < maximum:
self.run_command_success(['--{}'.format(option), str(value)])
@ -212,7 +212,7 @@ class TestDebugGUI(TestToolWithOptions, TestLibinputTool):
@classmethod
def setUpClass(cls):
# This is set by meson
debug_gui_enabled = @MESON_ENABLED_DEBUG_GUI@
debug_gui_enabled = @MESON_ENABLED_DEBUG_GUI@ # noqa
if not debug_gui_enabled:
raise unittest.SkipTest()