summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2021-04-22 15:35:03 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2021-04-28 14:00:42 +1000
commit68c0ba58aa1e3bc12695aa16330ef0b4836ff217 (patch)
tree9476590ddff951eb15c9a52df2980bd6b01c4d19
parentc582cb3d07de2adbbf7741f33dc84dbaa78dfc75 (diff)
downloadlibwacom-68c0ba58aa1e3bc12695aa16330ef0b4836ff217.tar.gz
tools: use a YAML-compatible format by default
Let's output something that is both human- and machine-readable. This makes it easier to search for specific devices with YAML parsers, e.g. to select all bluetooth devices one could use: $ libwacom-list-devices | yq '.devices[] | select(.bus == "bluetooth") | .name' Output for list-devices is now: devices: - { bus: 'i2c', vid: '0x056a', pid: '0x5169', name: 'Wacom ISDv4 5169' } ... Output for list-local-devices is now for example: devices: - name: 'Wacom Intuos Pro M' bus: 'usb' vid: '0x056a' pid: '0x0357' nodes: - /dev/input/event24 - /dev/input/event23 - /dev/input/event22 Output for list-compatible-stylis is now for example: - name: 'ISDv4 0163' styli: - { id: '0x1', name: 'AES Pen' } - { id: '0x11', name: 'AES Pen' } - { id: '0x19', name: 'AES Pen' } Note that as shown above, all hex numbers are encoded as strings. This prevents automatic conversion to decimal when using yq or other yaml formatters since the final result of the processing is almost always for human consumption (and thus needs the hex codes). Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
-rw-r--r--.github/workflows/main.yml14
-rw-r--r--tools/libwacom-list-devices.man10
-rw-r--r--tools/list-compatible-styli.c18
-rw-r--r--tools/list-devices.c19
-rw-r--r--tools/list-local-devices.c59
5 files changed, 73 insertions, 47 deletions
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index 07d6e42..2a2b080 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -5,7 +5,7 @@ on: [ push, pull_request ]
env:
CFLAGS: "-Werror -Wall -Wextra -Wno-error=sign-compare -Wno-error=unused-parameter -Wno-error=missing-field-initializers"
UBUNTU_PACKAGES: libgudev-1.0-dev libxml++2.6-dev valgrind tree python3-pip python3-setuptools libevdev2
- PIP_PACKAGES: meson ninja libevdev pyudev pytest
+ PIP_PACKAGES: meson ninja libevdev pyudev pytest yq
jobs:
###
@@ -197,7 +197,7 @@ jobs:
ninja_args: install
ninja_precmd: sudo
- name: list devices with database in /usr
- run: libwacom-list-devices --format=oneline > devicelist.default.txt
+ run: libwacom-list-devices --format=yaml > devicelist.default.txt
- run: sudo mkdir /etc/libwacom
# We override a Cintiq 27QHD with a single device match, and one of
# the multiple matches of the Intuos Pro L.
@@ -206,17 +206,17 @@ jobs:
sed -e 's/27QHD/27QHD MODIFIED/' data/cintiq-27hd.tablet | sudo tee /etc/libwacom/modified-cintiq.tablet
sed -e 's/Pro L/Pro L MODIFIED/' -e 's/usb:056a:0358;//' data/intuos-pro-2-l.tablet | sudo tee /etc/libwacom/modified-intuos.tablet
- name: list all devices for debugging
- run: libwacom-list-devices --format=oneline
+ run: libwacom-list-devices --format=yaml
# We expect the modified tablets to be listed
# We expect the remaining match for a modified tablet to be listed
# We expect the overridden match *not* to be listed
- name: check for the expected devices to be present (or not present)
run: |
- libwacom-list-devices --format=oneline | grep "usb:056a:032a:Wacom Cintiq 27QHD MODIFIED"
- libwacom-list-devices --format=oneline | grep "bluetooth:056a:0361:Wacom Intuos Pro L MODIFIED"
- test $(libwacom-list-devices --format=oneline | grep "usb:056a:0358" | wc -l) -eq 1
- test $(libwacom-list-devices --format=oneline | grep "usb:056a:032a:Wacom Cintiq 27QHD M" | wc -l) -eq 1
+ test "$(libwacom-list-devices --format=yaml | yq -r '.devices[] | select(.bus == "usb") | select(.vid == "0x056a") | select(.pid == "0x032a") | .name')" == "Wacom Cintiq 27QHD MODIFIED"
+ test "$(libwacom-list-devices --format=yaml | yq -r '.devices[] | select(.bus == "bluetooth") | select(.vid == "0x056a") | select(.pid == "0x0361") | .name')" == "Wacom Intuos Pro L MODIFIED"
+ test $(libwacom-list-devices --format=yaml | yq -r '.devices[] | select(.bus == "usb") | select(.vid == "0x056a") | select(.pid == "0x0358") | .name' | wc -l) -eq 1
+ test $(libwacom-list-devices --format=yaml | yq -r '.devices[] | select(.bus == "usb") | select(.vid == "0x056a") | select(.pid == "0x032a") | .name' | wc -l) -eq 1
###
#
diff --git a/tools/libwacom-list-devices.man b/tools/libwacom-list-devices.man
index 0f02063..27b9978 100644
--- a/tools/libwacom-list-devices.man
+++ b/tools/libwacom-list-devices.man
@@ -4,7 +4,7 @@
libwacom-list-devices - utility to list supported tablet devices
.SH SYNOPSIS
-.B libwacom-list-devices [--format=oneline|datafile]
+.B libwacom-list-devices [--format=yaml|datafile]
.SH DESCRIPTION
libwacom-list-devices is a debug utility to list all supported tablet
@@ -12,8 +12,8 @@ devices identified by libwacom. It is usually used to check whether a
libwacom installation is correct after adding custom data files.
.SH OPTIONS
.TP 8
-.B --format=oneline|datafile
-Sets the output format to be used. If \fIoneline\fR, the output format is a
-one-line format comprising the bus type, vendor and product ID and the
+.B --format=yaml|datafile
+Sets the output format to be used. If \fIyaml\fR, the output format is
+YAML comprising the bus type, vendor and product ID and the
device name. If \fIdatafile\fR, the output format matches
-the tablet data files. The default is \fIoneline\fR.
+the tablet data files. The default is \fIyaml\fR.
diff --git a/tools/list-compatible-styli.c b/tools/list-compatible-styli.c
index 277e75c..536ecee 100644
--- a/tools/list-compatible-styli.c
+++ b/tools/list-compatible-styli.c
@@ -40,24 +40,26 @@ print_device_info(const WacomDeviceDatabase *db, const WacomDevice *device)
const int *styli;
int nstyli;
- printf("%s", libwacom_get_name(device));
+ printf("- name: '%s'\n", libwacom_get_name(device));
if (libwacom_get_model_name(device)) {
- printf(" (%s)", libwacom_get_model_name(device));
+ printf(" model: '%s'\n", libwacom_get_model_name(device));
}
- printf(":\n");
-
if (!libwacom_has_stylus(device)) {
- printf("\tno styli defined\n");
+ printf(" styli: [] # no styli defined\n");
return;
}
+ printf(" styli:\n");
+
styli = libwacom_get_supported_styli(device, &nstyli);
for (int i = 0; i < nstyli; i++) {
const WacomStylus *s;
+ char id[64];
s = libwacom_stylus_get_for_id(db, styli[i]);
- printf("\t%#8x:\t%s\n",
- libwacom_stylus_get_id(s),
+ snprintf(id, sizeof(id), "0x%x", libwacom_stylus_get_id(s));
+ printf(" - { id: %*s'%s', name: '%s' }\n",
+ (int)(7 - strlen(id)), " ", id,
libwacom_stylus_get_name(s));
}
}
@@ -68,7 +70,7 @@ int main(int argc, char **argv)
WacomDevice **list, **p;
if (argc > 1) {
- printf("Usage: %s [--help] - list all supported devices\n",
+ printf("Usage: %s [--help] - list compatible styli\n",
basename(argv[0]));
return !!(strcmp(argv[1], "--help"));
}
diff --git a/tools/list-devices.c b/tools/list-devices.c
index f797b14..3dd7517 100644
--- a/tools/list-devices.c
+++ b/tools/list-devices.c
@@ -37,9 +37,9 @@
#include "libwacom.h"
static enum output_format {
- ONELINE,
+ YAML,
DATAFILE,
-} output_format = ONELINE;
+} output_format = YAML;
static void print_device_info (WacomDevice *device, WacomBusType bus_type_filter,
enum output_format format)
@@ -57,7 +57,7 @@ static void print_device_info (WacomDevice *device, WacomBusType bus_type_filter
dprintf(STDOUT_FILENO, "---------------------------------------------------------------\n");
} else {
const char *name = libwacom_get_name(device);
- const char *bus = NULL;
+ const char *bus = "unknown";
int vid = libwacom_match_get_vendor_id(*match);
int pid = libwacom_match_get_product_id(*match);
@@ -72,7 +72,9 @@ static void print_device_info (WacomDevice *device, WacomBusType bus_type_filter
/* We don't need to print the generic device */
if (vid != 0 || pid != 0 || bus != 0)
- printf("%s:%04x:%04x:%s\n", bus ? bus : "unknown", vid, pid, name);
+ printf("- { bus: '%s',%*svid: '0x%04x', pid: '0x%04x', name: '%s' }\n",
+ bus, (int)(10 - strlen(bus)), " ",
+ vid, pid, name);
}
}
}
@@ -82,15 +84,15 @@ check_format(const gchar *option_name, const gchar *value, gpointer data, GError
{
if (g_str_equal(value, "datafile"))
output_format = DATAFILE;
- else if (g_str_equal(value, "oneline"))
- output_format = ONELINE;
+ else if (g_str_equal(value, "yaml"))
+ output_format = YAML;
else
return FALSE;
return TRUE;
}
static GOptionEntry opts[] = {
- { "format", 0, 0, G_OPTION_ARG_CALLBACK, check_format, N_("Output format, one of 'oneline', 'datafile'"), NULL },
+ { "format", 0, 0, G_OPTION_ARG_CALLBACK, check_format, N_("Output format, one of 'yaml', 'datafile'"), NULL },
{ .long_name = NULL}
};
@@ -124,6 +126,9 @@ int main(int argc, char **argv)
return 1;
}
+ if (output_format == YAML)
+ printf("devices:\n");
+
for (p = list; *p; p++)
print_device_info ((WacomDevice *) *p, WBUSTYPE_USB, output_format);
diff --git a/tools/list-local-devices.c b/tools/list-local-devices.c
index 5fffe40..0ba6cce 100644
--- a/tools/list-local-devices.c
+++ b/tools/list-local-devices.c
@@ -38,9 +38,9 @@
#include "libwacom.h"
static enum output_format {
- ONELINE,
+ YAML,
DATAFILE,
-} output_format = ONELINE;
+} output_format = YAML;
static char *database_path;
@@ -92,17 +92,34 @@ tablet_print(gpointer data, gpointer user_data)
static void
print_str(gpointer data, gpointer user_data)
{
- printf("%s ", (char *)data);
+ printf(" - %s\n", (char *)data);
}
static void
-tablet_print_oneline(gpointer data, gpointer user_data)
+tablet_print_yaml(gpointer data, gpointer user_data)
{
struct tablet *d = data;
+ const char *name = libwacom_get_name(d->dev);
+ const char *bus = "unknown";
+ int vid = libwacom_get_vendor_id(d->dev);
+ int pid = libwacom_get_product_id(d->dev);
+ WacomBusType bustype = libwacom_get_bustype(d->dev);
+
+ switch (bustype) {
+ case WBUSTYPE_USB: bus = "usb"; break;
+ case WBUSTYPE_SERIAL: bus = "serial"; break;
+ case WBUSTYPE_BLUETOOTH:bus = "bluetooth"; break;
+ case WBUSTYPE_I2C: bus = "i2c"; break;
+ default:
+ break;
+ }
- printf("%s: ", libwacom_get_name(d->dev));
+ printf("- name: '%s'\n", name);
+ printf(" bus: '%s'\n", bus);
+ printf(" vid: '0x%04x'\n", vid);
+ printf(" pid: '0x%04x'\n", pid);
+ printf(" nodes: \n");
g_list_foreach(d->nodes, print_str, NULL);
- printf("\n");
}
static void
@@ -129,8 +146,8 @@ check_format(const gchar *option_name, const gchar *value, gpointer data, GError
{
if (g_str_equal(value, "datafile"))
output_format = DATAFILE;
- else if (g_str_equal(value, "oneline"))
- output_format = ONELINE;
+ else if (g_str_equal(value, "yaml"))
+ output_format = YAML;
else
return FALSE;
return TRUE;
@@ -138,7 +155,7 @@ check_format(const gchar *option_name, const gchar *value, gpointer data, GError
static GOptionEntry opts[] = {
{"database", 0, 0, G_OPTION_ARG_FILENAME, &database_path, N_("Path to device database"), NULL },
- { "format", 0, 0, G_OPTION_ARG_CALLBACK, check_format, N_("Output format, one of 'oneline', 'datafile'"), NULL },
+ { "format", 0, 0, G_OPTION_ARG_CALLBACK, check_format, N_("Output format, one of 'yaml', 'datafile'"), NULL },
{ .long_name = NULL}
};
@@ -214,18 +231,20 @@ int main(int argc, char **argv)
}
}
- if (!tabletlist)
+ if (!tabletlist) {
fprintf(stderr, "Failed to find any devices known to libwacom.\n");
-
- switch (output_format) {
- case DATAFILE:
- g_list_foreach(tabletlist, tablet_print, NULL);
- break;
- case ONELINE:
- g_list_foreach(tabletlist, tablet_print_oneline, NULL);
- break;
- default:
- abort();
+ } else {
+ switch (output_format) {
+ case DATAFILE:
+ g_list_foreach(tabletlist, tablet_print, NULL);
+ break;
+ case YAML:
+ printf("devices:\n");
+ g_list_foreach(tabletlist, tablet_print_yaml, NULL);
+ break;
+ default:
+ abort();
+ }
}
g_list_free_full(tabletlist, tablet_destroy);