2
# This file is part of Checkbox.
4
# Copyright 2014 Canonical Ltd.
6
# Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
8
# Checkbox is free software: you can redistribute it and/or modify
9
# it under the terms of the GNU General Public License version 3,
10
# as published by the Free Software Foundation.
12
# Checkbox is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
17
# You should have received a copy of the GNU General Public License
18
# along with Checkbox. If not, see <http://www.gnu.org/licenses/>.
20
udev2resource -- udev to plainbox resource converter
21
====================================================
23
This script converts the output of 'udev info --export-db' into a RFC822-esque
24
PlainBox resource syntax. It handles the P:, N:, E:, S: and L: "directives"
31
def udev2resource(in_stream, out_stream):
33
Convert the output of 'udev info --export-db' to RFC822 records.
36
Input stream to process
38
Output stream to process
40
The syntax is not documented anywhere that I could find but based on simple
41
experiments it looks like a sequence of lines starting with a one
42
letter-code followed by a colon and a value.
44
The following fields are recognized:
46
'P' - device path relative to /sysfs
47
'N' - device path relative to /dev
48
'E' - a key-value attribute
49
'S' - symlink path relative to /dev
53
for line in in_stream:
57
elif line.startswith("P: "):
58
line = line.replace("P: ", "path: ", 1)
59
elif line.startswith("N: "):
60
line = line.replace("N: ", "name: ", 1)
61
elif line.startswith("E: "):
62
line = re.sub("E: ([A-Za-z0-9_]+)=", "attr_\\1: ", line)
63
elif line.startswith("S: "):
64
line = re.sub("S: ", "symlink_{}: ".format(symlink_count), line)
66
elif line.startswith("L: "):
67
line = line.replace("L: ", "l_something: ", 1)
68
print(line, file=out_stream)
71
if __name__ == '__main__':
72
udev2resource(sys.stdin, sys.stdout)