1#!/usr/bin/env python3

2

3 import sys

4 from subprocess import check_output, CalledProcessError

5 from checkbox_support.parsers.udevadm import UdevadmParser

6

7

8 class TouchpadDevices:

9

10 def __init__(self):

11 self.devices = {}

12 self._collect_devices()

13

14 def _collect_devices(self):

15 cmd = ["udevadm", "info", "--export-db"]

16 try:

17 output = check_output(cmd).decode(

18 sys.stdout.encoding, errors="ignore"

19 )

20 except CalledProcessError as err:

21 sys.stderr.write(err)

22 return

23 udev = UdevadmParser(output)

24 for device in udev.run():

25 if getattr(device, "category") == "TOUCHPAD":

26 self.devices[getattr(device, "product_slug")] = getattr(

27 device, "path"

28 )

29

30

31 def main():

32 if len(sys.argv) != 2:

33 raise SystemExit("ERROR: expected a product slug")

34 product_slug = sys.argv[1]

35

36 path = TouchpadDevices().devices[product_slug]

37 abs_path = "/sys" + path + "/capabilities/abs"

38

39 f = open(abs_path, "r")

40 abs_cap_str = f.readline()

41 f.close()

42 support = (int(abs_cap_str[-15], 16) & 8) >> 3

43

44 if support == 0:

45 modalias_path = "/sys" + path + "/modalias"

46 f = open(modalias_path, "r")

47 modalias_str = f.readline()

48 f.close()

49 print("Touchpad modalias: {}".format(modalias_str[0:-2]))

50 print("Touchpad EV_ABS capabilities: {}".format(abs_cap_str[0:-2]))

51 sys.exit(1)

52

53 return 0

54

55

56 if __name__ == "__main__":

57 main()