~lidaobing/ubuntu-tweak/ubuntu-ubuntu-tweak

« back to all changes in this revision

Viewing changes to ubuntutweak/policykit/dbusproxy.py

  • Committer: LI Daobing
  • Date: 2010-07-31 10:10:26 UTC
  • mto: This revision was merged to the branch mainline in revision 13.
  • Revision ID: lidaobing@gmail.com-20100731101026-9o3m59258q5perbo
Tags: upstream-0.5.5
ImportĀ upstreamĀ versionĀ 0.5.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/python
2
2
 
3
 
# Ubuntu Tweak - PyGTK based desktop configure tool
 
3
# Ubuntu Tweak - PyGTK based desktop configuration tool
4
4
#
5
5
# Copyright (C) 2007-2008 TualatriX <tualatrix@gmail.com>
6
6
#
19
19
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
20
20
 
21
21
import dbus
 
22
import logging
 
23
 
 
24
from IN import INT_MAX
 
25
 
 
26
MAX_DBUS_TIMEOUT = INT_MAX / 1000.0
 
27
 
 
28
log = logging.getLogger("DbusProxy")
 
29
 
 
30
SHOWED = False
 
31
 
 
32
def show_message():
 
33
    from ubuntutweak.widgets.dialogs import ErrorDialog
 
34
    message = _('The daemon of Ubuntu Tweak doesn\'t start correctly, that means some '
 
35
            'advanced features may not work.\n'
 
36
            'If you want to help developer to debug, try to run "<b>sudo ubuntu-tweak-daemon</b>" under terminal.')
 
37
    ErrorDialog(message).launch()
 
38
 
 
39
def nothing():
 
40
    return None
22
41
 
23
42
class DbusProxy:
24
43
    INTERFACE = "com.ubuntu_tweak.daemon"
25
44
 
26
45
    try:
27
46
        __system_bus = dbus.SystemBus()
28
 
        __proxy = __system_bus.get_object('com.ubuntu_tweak.daemon', '/com/ubuntu_tweak/daemon')
29
 
    except dbus.exceptions.DBusException:
30
 
        __proxy = None
 
47
        __object = __system_bus.get_object('com.ubuntu_tweak.daemon', '/com/ubuntu_tweak/daemon')
 
48
    except Exception, e:
 
49
        __object = None
31
50
 
32
51
    def __getattr__(self, name):
33
 
        return self.__proxy.get_dbus_method(name, dbus_interface = self.INTERFACE)
 
52
        global SHOWED
 
53
        try:
 
54
            return self.__object.get_dbus_method(name, dbus_interface=self.INTERFACE)
 
55
        except Exception, e:
 
56
            log.error(e)
 
57
            if not SHOWED:
 
58
                SHOWED = True
 
59
                return show_message
 
60
            else:
 
61
                return nothing
34
62
 
35
 
    def get_proxy(self):
36
 
        return self.__proxy
 
63
    def get_object(self):
 
64
        return self.__object
37
65
 
38
66
proxy = DbusProxy()
39
67