2
# Copyright (c) 2008 Canonical
4
# Written by Marc Tardif <marc@interunion.ca>
6
# This file is part of Checkbox.
8
# Checkbox is free software: you can redistribute it and/or modify
9
# it under the terms of the GNU General Public License as published by
10
# the Free Software Foundation, either version 3 of the License, or
11
# (at your option) any later version.
13
# Checkbox is distributed in the hope that it will be useful,
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
# GNU General Public License for more details.
18
# You should have received a copy of the GNU General Public License
19
# along with Checkbox. If not, see <http://www.gnu.org/licenses/>.
23
from checkbox.lib.cache import cache
24
from checkbox.lib.update import recursive_update
26
from checkbox.registries.command import CommandRegistry
27
from checkbox.registries.data import DataRegistry
28
from checkbox.registries.map import MapRegistry
31
class DeviceRegistry(DataRegistry):
32
"""Registry for HAL device information.
34
Each item contained in this registry consists of the properties of
35
the corresponding HAL device.
42
for line in self.split("\n"):
43
match = re.match(r" (.*) = (.*) \((.*?)\)", line)
45
keys = match.group(1).split(".")
46
value = match.group(2).strip()
47
type_name = match.group(3)
48
if type_name == "bool":
49
value = bool(value == "true")
50
elif type_name == "double":
51
value = float(value.split()[0])
52
elif type_name == "int" or type_name == "uint64":
53
value = int(value.split()[0])
54
elif type_name == "string":
55
value = str(value.strip("'"))
56
elif type_name == "string list":
58
for v in value.strip("{}").split(", ")]
60
raise Exception, "Unknown type: %s" % type_name
62
for key in reversed(keys):
65
recursive_update(all, value)
68
for key, value in all.items():
69
value = MapRegistry(None, value)
70
items.append((key, value))
75
class HalRegistry(CommandRegistry):
76
"""Registry for HAL information.
78
Each item contained in this registry consists of the udi as key and
79
the corresponding device registry as value.
85
for block in self.split("\n\n"):
86
lines = block.split("\n")
89
match = re.match(r"udi = '(.*)'", line)
92
key = udi.split("/")[-1]
96
value = DeviceRegistry(None, "\n".join(lines))
97
items.append((key, value))
102
factory = HalRegistry