~dobey/changeup/trunk

3 by Rodney Dawes
Move client.py code into changeup/__init__.py
1
# -*- coding: utf-8 -*-
2
#
3
# Author: Rodney Dawes <rodney.dawes@canonical.com>
4
#
5
# Copyright 2009 Canonical Ltd.
6
#
7
# This program is free software: you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License version 3, as published
9
# by the Free Software Foundation.
10
#
11
# This program is distributed in the hope that it will be useful, but
12
# WITHOUT ANY WARRANTY; without even the implied warranties of
13
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
14
# PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with this program.  If not, see <http://www.gnu.org/licenses/>.
18
import dbus
19
20
CHANGEUP_BUS_NAME = 'org.freedesktop.ChangeUp'
21
22
23
def register_restart_handler(appname, handler):
24
    """Register a restart handler for ChangeUp."""
25
    def restart_handler(app):
26
        if app == appname:
27
            handler()
28
29
    bus = dbus.SystemBus()
30
    bus.add_signal_receiver(handler_function=restart_handler,
31
                            signal_name='RestartDispatched',
32
                            dbus_interface=CHANGEUP_BUS_NAME)