2
# This file is part of Checkbox.
4
# Copyright 2008 Canonical Ltd.
6
# Checkbox is free software: you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation, either version 3 of the License, or
9
# (at your option) any later version.
11
# Checkbox is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License
17
# along with Checkbox. If not, see <http://www.gnu.org/licenses/>.
22
from checkbox.lib.cache import cache
23
from checkbox.lib.conversion import string_to_type
25
from checkbox.properties import Path, String
26
from checkbox.registries.command import CommandRegistry
27
from checkbox.registries.data import DataRegistry
30
class SourceRegistry(DataRegistry):
37
for line in self.split("\n"):
41
match = re.match(r"(\s+(\/)?)(.+)", line)
46
space = len(match.group(1).rstrip("/"))
52
elif match.group(2) is not None:
54
value = SourceRegistry("\n".join(lines))
57
items.append((id, value))
59
id = match.group(3).split("/")[-1].rstrip(":")
61
(key, value) = match.group(3).split(" = ", 1)
62
if value == "(no value set)":
65
match = re.match(r"\[([^\]]*)\]", value)
67
list_string = match.group(1)
69
value = list_string.split(",")
73
value = string_to_type(value)
75
items.append((key, value))
78
value = SourceRegistry("\n".join(lines))
79
items.append((id, value))
84
class GconfRegistry(CommandRegistry):
85
"""Registry for gconf information.
87
Each item contained in this registry consists of the udi as key and
88
the corresponding device registry as value.
91
# Configuration source to use for a user.
92
source = Path(default="~/.gconf")
94
# Command to retrieve gconf information.
95
command = String(default="gconftool-2 -R / "
96
"--direct --config-source xml:readwrite:$source")
98
def __init__(self, *args, **kwargs):
99
super(GconfRegistry, self).__init__(*args, **kwargs)
101
source = posixpath.expanduser(self.source)
102
self.command = self.command.replace("$source", source)
110
for line in self.split("\n"):
111
if line.startswith(" /"):
113
value = SourceRegistry("\n".join(lines))
114
items.append((key, value))
115
key = line.strip().lstrip("/").rstrip(":")
120
value = SourceRegistry("\n".join(lines))
121
items.append((key, value))
126
factory = GconfRegistry