diff --git a/tools/usb/README.md b/tools/usb/README.md new file mode 100644 index 00000000..0cfe6678 --- /dev/null +++ b/tools/usb/README.md @@ -0,0 +1,24 @@ +# USB device list generators + +These are examples of functional Python 3 scripts to generate the USB +devices lists from some well-known packages. + +## epsonscan2-parse.py + +This will generate the list for Epson Scan2 based on the udev rules +shipped with the package. + +## gphoto2-parse.py + +This will parse the output of `print-camera-list` from libgphoto to +generate the list of USB devices. + +## libsane-parse.py + +This will generate the list for SANE based on the udev rules shipped +with the package. + +## utsushi-parse.py + +This will parse the SANE .desc shipping with Utsushi to generate the +USB device list. diff --git a/tools/usb/epsonscan2-parse.py b/tools/usb/epsonscan2-parse.py new file mode 100755 index 00000000..d56a9aa4 --- /dev/null +++ b/tools/usb/epsonscan2-parse.py @@ -0,0 +1,43 @@ +#!/bin/env python3 +# +# Copyright © 2024 GNOME Foundation, Inc. +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library. If not, see . +# +# Authors: +# Hubert Figuière +# +# Convert epsonscan2 rules. + + +import re + +vendor_match = re.compile(r"^ATTR\{idVendor\}!=\"([\dabcdef]*)\"") +device_match = re.compile(r"^ATTRS\{idProduct\}==\"([\dabcdef]*)\"") +file = open('epsonscan2.rules', 'r') + +vendor = 0 +while True: + line = file.readline() + if not line: + break + line = line.strip() + m = vendor_match.match(line) + if m is not None: + vendor = m.group(1) + continue + + m = device_match.match(line) + if m is not None: + print("--usb=vnd:{}+dev:{}".format(vendor, m.group(1))) diff --git a/tools/usb/gphoto2-parse.py b/tools/usb/gphoto2-parse.py new file mode 100755 index 00000000..f2b5ac37 --- /dev/null +++ b/tools/usb/gphoto2-parse.py @@ -0,0 +1,38 @@ +#!/bin/env python3 +# +# Copyright © 2024 GNOME Foundation, Inc. +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library. If not, see . +# +# Authors: +# Hubert Figuière +# +# Convert the output of libgphoto2 print-camera-list. + +import subprocess +import re + +device_match = re.compile(r"^([\dabcdef]*):([\dabcdef]*)") +file = subprocess.Popen(['./packaging/generic/print-camera-list', 'idlist'], stdout=subprocess.PIPE).stdout + +vendor = 0 +while True: + line = file.readline() + if not line: + break + line = line.decode('utf-8') + m = device_match.match(line) + if m is not None: + print("--usb=vnd:{}+dev:{}".format(m.group(1), m.group(2))) + print("--usb=cls:6") diff --git a/tools/usb/libsane-parse.py b/tools/usb/libsane-parse.py new file mode 100755 index 00000000..f5905706 --- /dev/null +++ b/tools/usb/libsane-parse.py @@ -0,0 +1,37 @@ +#!/bin/env python3 +# +# Copyright © 2024 GNOME Foundation, Inc. +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library. If not, see . +# +# Authors: +# Hubert Figuière +# +# Convert libsane udev rules. + +import re + +device_match = re.compile(r"ATTR\{idVendor\}==\"([\dabcdef]*)\",[\s]*ATTR\{idProduct\}==\"([\dabcdef]*)\"") +file = open('libsane.rules', 'r') + +vendor = 0 +while True: + line = file.readline() + if not line: + break + + m = device_match.match(line) + if m is not None: + print("--usb=vnd:{}+dev:{}".format(m.group(1), m.group(2))) + diff --git a/tools/usb/utsushi-parse.py b/tools/usb/utsushi-parse.py new file mode 100755 index 00000000..d292e7b0 --- /dev/null +++ b/tools/usb/utsushi-parse.py @@ -0,0 +1,36 @@ +#!/bin/env python3 +# +# Copyright © 2024 GNOME Foundation, Inc. +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library. If not, see . +# +# Authors: +# Hubert Figuière +# +# Convert utsushi device list (SANE .desc). + +import subprocess +import re + +device_match = re.compile(r"^:usbid[\s]+\"0x([\dabcdef]*)\"[\s]+\"0x([\dabcdef]*)\"") +file = open('sane/utsushi.desc', 'r') + +vendor = 0 +while True: + line = file.readline() + if not line: + break + m = device_match.match(line) + if m is not None: + print("--usb=vnd:{}+dev:{}".format(m.group(1), m.group(2)))