Created
March 19, 2024 03:38
-
-
Save hfiguiere/1bb2d135bdaf436031754f963a577409 to your computer and use it in GitHub Desktop.
Convert USB device list for flatpak USB device allow 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
#!/bin/env python3 | |
# | |
# 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
#!/bin/env python3 | |
# | |
# 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))) |
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
#!/bin/env python3 | |
# | |
# 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
#!/bin/env python3 | |
# | |
# 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))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment