1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
# bzr-dbus: dbus support for bzr/bzrlib.
# Copyright (C) 2007 Canonical Limited.
# Author: Robert Collins.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
"""System wide hooks to trigger dbus events from bzr activity."""
from bzrlib.branch import Branch
from bzrlib.smart.server import SmartTCPServer
import activity
def install_hooks():
"""Install the dbus hooks into bzrlib."""
if 'post_change_branch_tip' in Branch.hooks:
Branch.hooks.install_named_hook('post_change_branch_tip',
on_post_change_branch_tip, None)
else:
Branch.hooks.install_named_hook('set_rh', on_set_rh, None)
try:
SmartTCPServer.hooks
except AttributeError:
return
SmartTCPServer.hooks.install_named_hook('server_started', on_server_start, None)
SmartTCPServer.hooks.install_named_hook('server_stopped', on_server_stop, None)
def on_set_rh(branch, rev_history):
"""Announce the new revision_history of branch to dbus."""
activity.Activity().advertise_branch(branch)
def on_post_change_branch_tip(params):
"""Announce the new head revision of the branch to dbus."""
activity.Activity().advertise_branch(params.branch)
def on_server_start(local_urls, public_url):
"""Add the servers local and public urls to the session Broadcaster."""
for local_url in local_urls:
activity.Activity().add_url_map(local_url, public_url)
def on_server_stop(local_urls, public_url):
"""The server has shutdown, so remove the servers local and public urls."""
for local_url in local_urls:
activity.Activity().remove_url_map(local_url, public_url)
|