From a480df10e4e0104e0070609b3f9fbaa7ddeff9c7 Mon Sep 17 00:00:00 2001 From: Israel Eduardo Lugo Date: Fri, 28 Jul 2023 22:12:48 +0200 Subject: [PATCH 1/2] Fix failures with libwacom >= 1.10 Depending on how old the version of libwacom, most likely no devices will ever be detected. libwacom-list-local-devices, since April 28, 2021 (release 1.10, see ref. below) uses the YAML format by default, which looks like: ``` $ libwacom-list-local-devices --database /usr/share/libwacom/ devices: - name: 'Wacom Intuos Pro L' bus: 'usb' vid: '0x056a' pid: '0x0317' nodes: - /dev/input/event30 - /dev/input/event29 - /dev/input/event28 ``` ...while wacom-gui expects a different format, thus the parsing is wrong, and the 'detected' dictionary in get_connected_tablets() is wrong and an exception is thrown. To get the format expected by wacom-gui, we need to add the `--format=datafile` argument. In addition, we are quoting the '%s' to avoid an exception in a case where the path would have spaces. NOTE: this change breaks compatibility with libwacom < 1.10. See libwacom's project commit referenced below. References: - libwacom commit https://github.com/linuxwacom/libwacom/commit/68c0ba58aa1e3bc12695aa16330ef0b4836ff217 "tools: use a YAML-compatible format by default" - https://github.com/linuxwacom/libwacom/releases/tag/libwacom-1.10 --- wacom-gui/wacom_data.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wacom-gui/wacom_data.py b/wacom-gui/wacom_data.py index c273f53..4854c32 100644 --- a/wacom-gui/wacom_data.py +++ b/wacom-gui/wacom_data.py @@ -122,7 +122,7 @@ def get_connected_tablets(self): def __get_libwacom_data(self): - p = subprocess.Popen("libwacom-list-local-devices --database %s" % self.db_path, shell=True, + p = subprocess.Popen("libwacom-list-local-devices --database '%s' --format=datafile" % self.db_path, shell=True, stdout=subprocess.PIPE) output = p.communicate()[0].decode('utf-8').split('\n') cur_device = None From 6de2d6637c64db36e18dbef78bb820d6e739e136 Mon Sep 17 00:00:00 2001 From: Israel Eduardo Lugo Date: Sun, 30 Jul 2023 20:00:16 +0200 Subject: [PATCH 2/2] Be compatible with both old and versions of libwacom libwacom 1.10 introduced a breaking change to the output format of libwacom-list-local-devices. Commit a480df1 makes us compatible with the new format, at the expense of breaking compatibility with older versions. This commit reintroduces compatibility with BOTH versions. The strategy is to first try running libwacom-list-local-devices with the new syntax, and fall back to the old syntax if necessary. --- wacom-gui/wacom_data.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/wacom-gui/wacom_data.py b/wacom-gui/wacom_data.py index 4854c32..af30fe0 100644 --- a/wacom-gui/wacom_data.py +++ b/wacom-gui/wacom_data.py @@ -121,10 +121,25 @@ def get_connected_tablets(self): warning.exec_() + def __list_local_devices(self): + def aux(format_arg): + """aux calls libwacom-list-local-devices with an optional format argument. + + Returns the contents of the child's stdout, and its numeric exit code.""" + p = subprocess.Popen( + "libwacom-list-local-devices --database '%s' %s" % (self.db_path, format_arg), shell=True, stdout=subprocess.PIPE + ) + return p.communicate()[0], p.returncode + + # This will fail for libwacom <1.10, which doesn't have the + # --format option. + stdout, returncode = aux("--format=datafile") + if returncode != 0: # Retry in <1.10 syntax + stdout, returncode = aux("") + return stdout.decode('utf-8').split('\n') + def __get_libwacom_data(self): - p = subprocess.Popen("libwacom-list-local-devices --database '%s' --format=datafile" % self.db_path, shell=True, - stdout=subprocess.PIPE) - output = p.communicate()[0].decode('utf-8').split('\n') + output = self.__list_local_devices() cur_device = None buttons = False for line in output: