~dstansby-deactivatedaccount/ubuntu/maverick/checkbox/checkbox-fix-525454

« back to all changes in this revision

Viewing changes to registries/gconf.py

  • Committer: Bazaar Package Importer
  • Author(s): Mathias Gug, Marc Tardif
  • Date: 2010-03-09 16:58:36 UTC
  • Revision ID: james.westby@ubuntu.com-20100309165836-26f22oe6ubppzx0d
Tags: 0.9
[ Marc Tardif ]
New upstream release (LP: #532882):
* Introduced job_prompt plugin to treat all jobs (suites, tests, etc.) as composites.
* Replaced the registry and resource scripts and centralized job iteration.
* Replaced dependency on dbus by using sudo/gksu/kdesudo instead.
* Replaced mktemp with mkdtemp for security purposes.
* Fixed strings in fingerprint and modem tests (LP: #457759)
* Fixed client side validation of Launchpad form (LP: #438671)
* Added device information to tags when reporting bugs with apport.
* Added shorthands for blacklist-file and whitelist-file.
* Added support for apport default configuration (LP: #465447)
* Added support for scrolled options list (LP: #411526)
* Added support for tests generated by suites to run as root.
* Added support for requirements in attachments.
* Added support for armv7l processor
* Added Autotest integration
* Added LTP integration
* Added Phoronix integration
* Added qa-regression-testing integration

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#
2
 
# This file is part of Checkbox.
3
 
#
4
 
# Copyright 2008 Canonical Ltd.
5
 
#
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.
10
 
#
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.
15
 
#
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/>.
18
 
#
19
 
import re
20
 
import posixpath
21
 
 
22
 
from checkbox.lib.cache import cache
23
 
from checkbox.lib.conversion import string_to_type
24
 
 
25
 
from checkbox.properties import Path, String
26
 
from checkbox.registries.command import CommandRegistry
27
 
from checkbox.registries.data import DataRegistry
28
 
 
29
 
 
30
 
class SourceRegistry(DataRegistry):
31
 
 
32
 
    def items(self):
33
 
        items = []
34
 
        lines = []
35
 
 
36
 
        id = depth = None
37
 
        for line in self.split("\n"):
38
 
            if not line:
39
 
                continue
40
 
 
41
 
            match = re.match(r"(\s+(\/)?)(.+)", line)
42
 
            if not match:
43
 
                lines[-1] += line
44
 
                continue
45
 
 
46
 
            space = len(match.group(1).rstrip("/"))
47
 
            if depth is None:
48
 
                depth = space
49
 
 
50
 
            if space > depth:
51
 
                lines.append(line)
52
 
            elif match.group(2) is not None:
53
 
                if id is not None:
54
 
                    value = SourceRegistry("\n".join(lines))
55
 
                    lines = []
56
 
 
57
 
                    items.append((id, value))
58
 
 
59
 
                id = match.group(3).split("/")[-1].rstrip(":")
60
 
            else:
61
 
                (key, value) = match.group(3).split(" = ", 1)
62
 
                if value == "(no value set)":
63
 
                    value = None
64
 
                else:
65
 
                    match = re.match(r"\[([^\]]*)\]", value)
66
 
                    if match:
67
 
                        list_string = match.group(1)
68
 
                        if len(list_string):
69
 
                            value = list_string.split(",")
70
 
                        else:
71
 
                            value = []
72
 
                    else:
73
 
                        value = string_to_type(value)
74
 
 
75
 
                items.append((key, value))
76
 
 
77
 
        if lines:
78
 
            value = SourceRegistry("\n".join(lines))
79
 
            items.append((id, value))
80
 
 
81
 
        return items
82
 
 
83
 
 
84
 
class GconfRegistry(CommandRegistry):
85
 
    """Registry for gconf information.
86
 
 
87
 
    Each item contained in this registry consists of the udi as key and
88
 
    the corresponding device registry as value.
89
 
    """
90
 
 
91
 
    # Configuration source to use for a user.
92
 
    source = Path(default="~/.gconf")
93
 
 
94
 
    # Command to retrieve gconf information.
95
 
    command = String(default="gconftool-2 -R / "
96
 
        "--direct --config-source xml:readwrite:$source")
97
 
 
98
 
    def __init__(self, *args, **kwargs):
99
 
        super(GconfRegistry, self).__init__(*args, **kwargs)
100
 
 
101
 
        source = posixpath.expanduser(self.source)
102
 
        self.command = self.command.replace("$source", source)
103
 
 
104
 
    @cache
105
 
    def items(self):
106
 
        items = []
107
 
 
108
 
        key = None
109
 
        lines = []
110
 
        for line in self.split("\n"):
111
 
            if line.startswith(" /"):
112
 
                if lines:
113
 
                    value = SourceRegistry("\n".join(lines))
114
 
                    items.append((key, value))
115
 
                key = line.strip().lstrip("/").rstrip(":")
116
 
            elif line:
117
 
                lines.append(line)
118
 
 
119
 
        if lines:
120
 
            value = SourceRegistry("\n".join(lines))
121
 
            items.append((key, value))
122
 
 
123
 
        return items
124
 
 
125
 
 
126
 
factory = GconfRegistry