~ubuntu-branches/ubuntu/saucy/wicd/saucy

« back to all changes in this revision

Viewing changes to wicd/dbusmanager.py

  • Committer: Bazaar Package Importer
  • Author(s): David Paleino
  • Date: 2009-06-22 17:59:27 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20090622175927-iax3alden0bmj6zg
Tags: 1.6.1-3
* debian/config, debian/templates updated:
  - only show users to add to netdev, skip those who are already
    members (Closes: #534138)
  - gracefully handle upgrades from previous broken versions, where
    debconf set a value of ${default} for wicd/users
    (Closes: #532112)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
 
 
3
""" The wicd DBus Manager.
 
4
 
 
5
A module for managing wicd's dbus interfaces.
 
6
 
 
7
"""
 
8
 
 
9
#
 
10
#   Copyright (C) 2008-2009 Adam Blackburn
 
11
#   Copyright (C) 2008-2009 Dan O'Reilly
 
12
#
 
13
#   This program is free software; you can redistribute it and/or modify
 
14
#   it under the terms of the GNU General Public License Version 2 as
 
15
#   published by the Free Software Foundation.
 
16
#
 
17
#   This program is distributed in the hope that it will be useful,
 
18
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
19
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
20
#   GNU General Public License for more details.
 
21
#
 
22
#   You should have received a copy of the GNU General Public License
 
23
#   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
24
#
 
25
 
 
26
import dbus
 
27
if getattr(dbus, "version", (0, 0, 0)) < (0, 80, 0):
 
28
    import dbus.glib
 
29
else:
 
30
    from dbus.mainloop.glib import DBusGMainLoop
 
31
    DBusGMainLoop(set_as_default=True)
 
32
    
 
33
DBUS_MANAGER = None
 
34
    
 
35
def get_dbus_ifaces():
 
36
    return DBUS_MANAGER.get_dbus_ifaces()
 
37
 
 
38
def get_interface(iface):
 
39
    return DBUS_MANAGER.get_interface(iface)
 
40
 
 
41
def get_bus():
 
42
    return DBUS_MANAGER.get_bus()
 
43
 
 
44
def set_mainloop():
 
45
    return DBUS_MANAGER.set_mainloop()
 
46
 
 
47
def connect_to_dbus():
 
48
    return DBUS_MANAGER.connect_to_dbus()
 
49
 
 
50
def threads_init():
 
51
    dbus.mainloop.glib.threads_init()
 
52
 
 
53
 
 
54
class DBusManager(object):
 
55
    """ Manages the DBus objects used by wicd. """
 
56
    def __init__(self):
 
57
        self._bus = dbus.SystemBus()
 
58
        self._dbus_ifaces = {}  
 
59
    
 
60
    def get_dbus_ifaces(self):
 
61
        """ Returns a dict of dbus interfaces. """
 
62
        if not self._dbus_ifaces: connect_to_dbus()
 
63
        return self._dbus_ifaces
 
64
    
 
65
    def get_interface(self, iface):
 
66
        """ Returns a DBus Interface. """
 
67
        if not self._dbus_ifaces: connect_to_dbus()
 
68
        return self._dbus_ifaces[iface]
 
69
    
 
70
    def get_bus(self):
 
71
        """ Returns the loaded SystemBus. """
 
72
        return self._bus
 
73
    
 
74
    def set_mainloop(self, loop):
 
75
        dbus.set_default_main_loop(loop)
 
76
    
 
77
    def connect_to_dbus(self):
 
78
        """ Connects to wicd's dbus interfaces and loads them into a dict. """
 
79
        proxy_obj = self._bus.get_object("org.wicd.daemon", '/org/wicd/daemon')
 
80
        daemon = dbus.Interface(proxy_obj, 'org.wicd.daemon')
 
81
        
 
82
        proxy_obj = self._bus.get_object("org.wicd.daemon",
 
83
                                         '/org/wicd/daemon/wireless')
 
84
        wireless = dbus.Interface(proxy_obj, 'org.wicd.daemon.wireless')
 
85
        
 
86
        proxy_obj = self._bus.get_object("org.wicd.daemon",
 
87
                                         '/org/wicd/daemon/wired')
 
88
        wired = dbus.Interface(proxy_obj, 'org.wicd.daemon.wired')
 
89
        
 
90
        self._dbus_ifaces = {"daemon" : daemon, "wireless" : wireless,
 
91
                             "wired" : wired}
 
92
        
 
93
DBUS_MANAGER = DBusManager()
 
 
b'\\ No newline at end of file'