Skip to content

Commit

Permalink
tools: flake8 fixes for the various python files
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
  • Loading branch information
whot committed Sep 11, 2019
1 parent 975ff2f commit 2763255
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 105 deletions.
9 changes: 9 additions & 0 deletions .gitlab-ci.yml
Expand Up @@ -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
#
Expand Down
36 changes: 18 additions & 18 deletions tools/libinput-measure-fuzz.py
Expand Up @@ -101,10 +101,10 @@ def check_property(self):
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:
Expand All @@ -122,7 +122,7 @@ def check_property(self):
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)
Expand All @@ -138,12 +138,12 @@ def check_axes(self):
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)
Expand All @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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:
Expand Down
72 changes: 32 additions & 40 deletions tools/libinput-measure-touch-size.py
Expand Up @@ -87,9 +87,9 @@ def orientation(self, orientation):
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


Expand Down Expand Up @@ -119,17 +119,15 @@ def append(self, touch):
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:
Expand All @@ -147,29 +145,25 @@ def _str_summary(self):
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"

return s

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


Expand Down Expand Up @@ -250,27 +244,27 @@ def handle_key(self, event):
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:
Expand Down Expand Up @@ -310,17 +304,15 @@ 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)
raise argparse.ArgumentTypeError(msg)


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',
Expand All @@ -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))


Expand Down
8 changes: 4 additions & 4 deletions tools/libinput-measure-touchpad-pressure.py
Expand Up @@ -99,12 +99,12 @@ def finalize(self):

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):
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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))


Expand Down
18 changes: 8 additions & 10 deletions tools/libinput-measure-touchpad-tap.py
Expand Up @@ -52,7 +52,7 @@ def tv2us(sec, usec):


def us2ms(us):
return int(us/1000)
return int(us / 1000)


class Touch(object):
Expand Down Expand Up @@ -103,7 +103,7 @@ def _find_touch_device(self):
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
Expand Down Expand Up @@ -165,12 +165,12 @@ def print_summary(self):
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)))
Expand Down Expand Up @@ -220,9 +220,7 @@ def print(self, format):


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',
Expand Down
5 changes: 3 additions & 2 deletions tools/libinput-record-verify-yaml.py
Expand Up @@ -61,7 +61,7 @@ def libinput_events(self, filter=None):

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):
Expand Down Expand Up @@ -632,7 +632,8 @@ def test_events_libinput_tablet_tool_axes(self):
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
Expand Down
12 changes: 5 additions & 7 deletions tools/libinput-replay
Expand Up @@ -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)
Expand Down Expand Up @@ -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')
Expand Down

0 comments on commit 2763255

Please sign in to comment.