mirror of
https://github.com/flatpak/flatpak.git
synced 2026-01-26 06:07:56 +00:00
usb: Added tool examples to generate device lists
Signed-off-by: Hubert Figuière <hub@figuiere.net>
This commit is contained in:
parent
1d56bd377e
commit
cced00fdb0
24
tools/usb/README.md
Normal file
24
tools/usb/README.md
Normal file
@ -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.
|
||||||
43
tools/usb/epsonscan2-parse.py
Executable file
43
tools/usb/epsonscan2-parse.py
Executable file
@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
# Authors:
|
||||||
|
# Hubert Figuière <hub@figuiere.net>
|
||||||
|
#
|
||||||
|
# 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)))
|
||||||
38
tools/usb/gphoto2-parse.py
Executable file
38
tools/usb/gphoto2-parse.py
Executable file
@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
# Authors:
|
||||||
|
# Hubert Figuière <hub@figuiere.net>
|
||||||
|
#
|
||||||
|
# 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")
|
||||||
37
tools/usb/libsane-parse.py
Executable file
37
tools/usb/libsane-parse.py
Executable file
@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
# Authors:
|
||||||
|
# Hubert Figuière <hub@figuiere.net>
|
||||||
|
#
|
||||||
|
# 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)))
|
||||||
|
|
||||||
36
tools/usb/utsushi-parse.py
Executable file
36
tools/usb/utsushi-parse.py
Executable file
@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
# Authors:
|
||||||
|
# Hubert Figuière <hub@figuiere.net>
|
||||||
|
#
|
||||||
|
# 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)))
|
||||||
Loading…
x
Reference in New Issue
Block a user