File: libsane-parse.py

package info (click to toggle)
flatpak 1.16.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,020 kB
  • sloc: ansic: 101,028; xml: 11,453; sh: 4,871; python: 2,251; yacc: 1,236; makefile: 86; csh: 20
file content (37 lines) | stat: -rwxr-xr-x 1,171 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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)))