1
# telepathy-python - Base classes defining the interfaces of the Telepathy framework
3
# Copyright (C) 2005 Collabora Limited
4
# Copyright (C) 2005 Nokia Corporation
6
# This library is free software; you can redistribute it and/or
7
# modify it under the terms of the GNU Lesser General Public
8
# License as published by the Free Software Foundation; either
9
# version 2.1 of the License, or (at your option) any later version.
11
# This library 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 GNU
14
# Lesser General Public License for more details.
16
# You should have received a copy of the GNU Lesser General Public
17
# License along with this library; if not, write to the Free Software
18
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
Loads .manager files according to
22
http://telepathy.freedesktop.org/wiki/FileFormats.
25
import ConfigParser, os
31
_dbus_py_version = getattr(dbus, 'version', (0,0,0))
33
def _convert_pathlist(pathlist):
34
dirlist = pathlist.split(":")
35
# Reverse so least-important is first
40
path = os.path.abspath(os.path.expanduser(path))
41
dirs.append(os.path.join(path, "telepathy", "managers"))
44
class ManagerRegistry:
48
def LoadManager(self, path):
49
config = ConfigParser.RawConfigParser()
52
cm_name = os.path.basename(path)[:-len(".manager")]
53
self.services[cm_name] = {
55
"busname": "org.freedesktop.Telepathy.ConnectionManager.%s" % cm_name,
56
"objectpath": "/org/freedesktop/Telepathy/ConnectionManager/%s" % cm_name,
60
for section in set(config.sections()):
61
if section.startswith('Protocol '):
62
proto_name = section[len('Protocol '):]
63
protocols[proto_name] = dict(config.items(section))
66
raise ConfigParser.NoSectionError("no protocols found (%s)" % path)
68
self.services[cm_name]["protos"] = protocols
70
def LoadManagers(self):
72
Searches local and system wide configurations
74
Can raise all ConfigParser errors. Generally filename member will be
75
set to the name of the erronous file.
78
# Later items in the list are _more_ important
80
if os.environ.has_key("XDG_DATA_DIRS"):
81
all_paths += _convert_pathlist(os.environ["XDG_DATA_DIRS"])
83
all_paths.append('/usr/share/telepathy/managers')
84
all_paths.append('/usr/local/share/telepathy/managers')
86
home = os.path.expanduser("~")
87
if os.environ.has_key("XDG_DATA_HOME"):
88
all_paths += _convert_pathlist(os.environ["XDG_DATA_HOME"])
90
all_paths.append(os.path.join(home, ".local", "share", \
91
"telepathy", "managers"))
93
all_paths.append(os.path.join(home, ".telepathy", "managers"))
95
for path in all_paths:
96
if os.path.exists(path):
97
for name in dircache.listdir(path):
98
if name.endswith('.manager'):
99
self.LoadManager(os.path.join(path, name))
103
returns a list of protocols supported on this system
106
for service in self.services.keys():
107
if self.services[service].has_key("protos"):
108
protos.update(self.services[service]["protos"].keys())
111
def GetManagers(self, proto):
113
Returns names of managers that can handle the given protocol.
116
for service in self.services.keys():
117
if "protos" in self.services[service]:
118
if self.services[service]["protos"].has_key(proto):
119
managers.append(service)
122
def GetBusName(self, manager):
123
assert(manager in self.services)
124
assert('busname' in self.services[manager])
125
return self.services[manager]['busname']
127
def GetObjectPath(self, manager):
128
assert(manager in self.services)
129
assert('objectpath' in self.services[manager])
130
return self.services[manager]['objectpath']
132
def GetManager(self, manager):
133
return telepathy.client.ConnectionManager(
134
self.services[manager]['busname'],
135
self.services[manager]['objectpath'])
137
def GetParams(self, manager, proto):
139
Returns a dict of paramters for the given proto on the given manager.
140
The keys will be the parameters names, and the values a tuple of (dbus
141
type, default value, flags). If no default value is specified, the
142
second item in the tuple will be None.
146
config = self.services[manager]["protos"][proto]
148
for key, val in config.iteritems():
149
if not key.startswith('param-'):
152
name = key[len('param-'):]
158
if "register" in values:
159
flags |= telepathy.CONN_MGR_PARAM_FLAG_REGISTER
161
if "required" in values:
162
flags |= telepathy.CONN_MGR_PARAM_FLAG_REQUIRED
164
for key, val in config.iteritems():
165
if key.strip().startswith("default-"+name):
166
if _dbus_py_version < (0, 80):
167
default = dbus.Variant(val.strip(), signature=type)
169
default = val.strip()
170
if type in 'uiqntxy':
171
default = int(default)
173
if default.lower() in ('0', 'false'):
178
default = float(default)
179
# we don't support non-basic types
180
flags |= telepathy.CONN_MGR_PARAM_FLAG_HAS_DEFAULT
182
params[name] = (type, default, flags)