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
|
# 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
from server_mainloop import (
MainloopThread, install_hooks as install_mainloop_hooks)
def install_hooks():
"""Install the dbus hooks into bzrlib."""
Branch.hooks.install_hook('set_rh', on_set_rh)
install_mainloop_hooks()
MainloopThread.hooks.install_hook('server_started', on_server_start)
MainloopThread.hooks.install_hook('server_stopped', on_server_stop)
def on_set_rh(branch, rev_history):
"""Announce the new revision_history of branch to dbus."""
activity.Activity().advertise_branch(branch)
_announcer = None
def get_announcer():
global _announcer
if _announcer is None:
_announcer = activity.ServerAnnouncer()
return _announcer
def on_server_start(mainloop, backing_urls, public_url):
"""Add the servers local and public urls to the session Broadcaster."""
get_announcer().on_server_started(backing_urls, public_url)
def on_server_stop(mainloop, backing_urls, public_url):
"""The server has shutdown, so remove the servers local and public urls."""
get_announcer().on_server_stopped(backing_urls, public_url)
|