forked from flatpak/flatpak
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
usb: Added tool examples to generate device lists
Signed-off-by: Hubert Figuière <[email protected]>
- Loading branch information
1 parent
1d56bd3
commit cced00f
Showing
5 changed files
with
178 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <[email protected]> | ||
# | ||
# 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))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <[email protected]> | ||
# | ||
# 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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <[email protected]> | ||
# | ||
# 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))) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <[email protected]> | ||
# | ||
# 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))) |