From 8458b7ef4ae033839d786b0d6cd921ef857f113d Mon Sep 17 00:00:00 2001 From: Sylvain Pineau Date: Tue, 14 Jul 2020 13:33:13 +0200 Subject: bin:touchpad_driver_info -> touchpad_driver_info.py --- bin/touchpad_driver_info | 82 --------------------------------------------- bin/touchpad_driver_info.py | 82 +++++++++++++++++++++++++++++++++++++++++++++ units/info/jobs.pxu | 2 +- units/touchpad/jobs.pxu | 2 +- 4 files changed, 84 insertions(+), 84 deletions(-) delete mode 100755 bin/touchpad_driver_info create mode 100755 bin/touchpad_driver_info.py diff --git a/bin/touchpad_driver_info b/bin/touchpad_driver_info deleted file mode 100755 index 431b874..0000000 --- a/bin/touchpad_driver_info +++ /dev/null @@ -1,82 +0,0 @@ -#!/usr/bin/env python3 - -import sys -from io import StringIO -from subprocess import Popen, PIPE, check_output, STDOUT, CalledProcessError -from checkbox_support.parsers.udevadm import UdevadmParser -from checkbox_support.parsers.modinfo import ModinfoParser - -# Command to retrieve udev information. -COMMAND = 'udevadm info --export-db' - - -class TouchResult: - - attributes = {} - - def addDevice(self, device): - if getattr(device, 'category') == 'TOUCHPAD': - self.attributes['driver'] = getattr(device, 'driver') - self.attributes['product'] = getattr(device, 'product') - - -class TouchpadDriver(): - - def __init__(self, driver): - self._driver = driver - self.driver_version = self._find_driver_version() - - def _find_driver_version(self): - cmd = ['/sbin/modinfo', self._driver] - try: - stream = check_output(cmd, stderr=STDOUT, - universal_newlines=True) - except CalledProcessError as err: - print("Error communicating with modinfo.") - print(err.output) - return None - - if not stream: - print("Error: modinfo returned nothing.") - else: - parser = ModinfoParser(stream) - version = parser.get_field('version') - if not version: - version = parser.get_field('vermagic').split()[0] - - return version - - -def get_touch_attributes(): - output, err = Popen(COMMAND, stdout=PIPE, shell=True).communicate() - if err: - print("Error running $s" % ' '.join(COMMAND)) - print(err) - return None - - udev = UdevadmParser(StringIO(output.decode("unicode-escape"))) - - result = TouchResult() - udev.run(result) - - return result.attributes - - -def main(): - attributes = get_touch_attributes() - if attributes: - modinfo = TouchpadDriver(attributes['driver']) - attributes['version'] = modinfo.driver_version - print("%s: %s\n%s: %s\n%s: %s\n" % - ('Device', attributes['product'], - 'Driver', attributes['driver'], - 'Driver Version', attributes['version'])) - else: - print("No Touchpad Detected") - return 1 - - return 0 - - -if __name__ == "__main__": - sys.exit(main()) diff --git a/bin/touchpad_driver_info.py b/bin/touchpad_driver_info.py new file mode 100755 index 0000000..431b874 --- /dev/null +++ b/bin/touchpad_driver_info.py @@ -0,0 +1,82 @@ +#!/usr/bin/env python3 + +import sys +from io import StringIO +from subprocess import Popen, PIPE, check_output, STDOUT, CalledProcessError +from checkbox_support.parsers.udevadm import UdevadmParser +from checkbox_support.parsers.modinfo import ModinfoParser + +# Command to retrieve udev information. +COMMAND = 'udevadm info --export-db' + + +class TouchResult: + + attributes = {} + + def addDevice(self, device): + if getattr(device, 'category') == 'TOUCHPAD': + self.attributes['driver'] = getattr(device, 'driver') + self.attributes['product'] = getattr(device, 'product') + + +class TouchpadDriver(): + + def __init__(self, driver): + self._driver = driver + self.driver_version = self._find_driver_version() + + def _find_driver_version(self): + cmd = ['/sbin/modinfo', self._driver] + try: + stream = check_output(cmd, stderr=STDOUT, + universal_newlines=True) + except CalledProcessError as err: + print("Error communicating with modinfo.") + print(err.output) + return None + + if not stream: + print("Error: modinfo returned nothing.") + else: + parser = ModinfoParser(stream) + version = parser.get_field('version') + if not version: + version = parser.get_field('vermagic').split()[0] + + return version + + +def get_touch_attributes(): + output, err = Popen(COMMAND, stdout=PIPE, shell=True).communicate() + if err: + print("Error running $s" % ' '.join(COMMAND)) + print(err) + return None + + udev = UdevadmParser(StringIO(output.decode("unicode-escape"))) + + result = TouchResult() + udev.run(result) + + return result.attributes + + +def main(): + attributes = get_touch_attributes() + if attributes: + modinfo = TouchpadDriver(attributes['driver']) + attributes['version'] = modinfo.driver_version + print("%s: %s\n%s: %s\n%s: %s\n" % + ('Device', attributes['product'], + 'Driver', attributes['driver'], + 'Driver Version', attributes['version'])) + else: + print("No Touchpad Detected") + return 1 + + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/units/info/jobs.pxu b/units/info/jobs.pxu index 45878ea..337305f 100644 --- a/units/info/jobs.pxu +++ b/units/info/jobs.pxu @@ -290,7 +290,7 @@ plugin: attachment category_id: com.canonical.plainbox::info id: info/touchpad_driver requires: device.category == 'TOUCHPAD' -command: touchpad_driver_info +command: touchpad_driver_info.py estimated_duration: 0.384 _description: Returns the name, driver name and driver version of any touchpad discovered on diff --git a/units/touchpad/jobs.pxu b/units/touchpad/jobs.pxu index a7b7e35..0c89823 100644 --- a/units/touchpad/jobs.pxu +++ b/units/touchpad/jobs.pxu @@ -189,7 +189,7 @@ id: touchpad/detected-as-mouse requires: dmi.product in ['Notebook','Laptop','Portable','Convertible'] estimated_duration: 1.2 command: - info=`touchpad_driver_info` + info=`touchpad_driver_info.py` if [ $? -eq 0 ]; then echo -e "touchpad detected with:\n$info" else -- cgit v1.2.3