Rev 2: hook logic complete. in file:///home/robertc/source/baz/plugins/dbus/trunk/

Robert Collins robertc at robertcollins.net
Tue Feb 6 03:48:34 GMT 2007


------------------------------------------------------------
revno: 2
revision-id: robertc at robertcollins.net-20070206034833-4nqg6ul9waqgnup8
parent: robertc at robertcollins.net-20070206033059-mpygm0023bioge1w
committer: Robert Collins <robertc at robertcollins.net>
branch nick: trunk
timestamp: Tue 2007-02-06 14:48:33 +1100
message:
  hook logic complete.
added:
  activity.py                    activity.py-20070206034725-q208d0jtkshwu0fx-1
modified:
  TODO                           todo-20070206032729-2b5teqiwctqrfgei-3
  hook.py                        hook.py-20070206032729-2b5teqiwctqrfgei-5
  tests/test_hook.py             test_hook.py-20070206032729-2b5teqiwctqrfgei-8
=== added file 'activity.py'
--- a/activity.py	1970-01-01 00:00:00 +0000
+++ b/activity.py	2007-02-06 03:48:33 +0000
@@ -0,0 +1,40 @@
+# 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
+# 
+
+"""Activity of bzr.
+
+This module provides Activity which supports announcing and recieving messages
+about bzr activity: See the class for more detail.
+"""
+
+
+class Activity(object):
+    """bzrlib object activity tracking."""
+
+    def advertise_branch(self, branch):
+        """Advertise branch to dbus.
+
+        This is a top level convenience function to advertise a branch. No
+        warranties are made about delivery of the advertisement, nor of how
+        long it will be visible to users. Specifically, dbus errors are caught,
+        and the advertisement is not repeated.
+        :param branch: The branch to be advertised. The advertisement is done
+            by announcing the tip revision and the URL of the branch.
+        :return: None
+        :raises: Nothing should be raised.
+        """

=== modified file 'TODO'
--- a/TODO	2007-02-06 03:30:59 +0000
+++ b/TODO	2007-02-06 03:48:33 +0000
@@ -1,7 +1,6 @@
 Plans for dbus and bzr
 ----------------------
 
- * dbus set_rh hook to notify on the tip revision
  * dbus service to act as the broadcast point for revisions
  * bzr server integration to republish tip revisions from file:/// to public
    URLs when one is available.

=== modified file 'hook.py'
--- a/hook.py	2007-02-06 03:30:59 +0000
+++ b/hook.py	2007-02-06 03:48:33 +0000
@@ -21,6 +21,8 @@
 
 from bzrlib.branch import Branch
 
+import activity
+
 
 def install_hooks():
     """Install the dbus hooks into bzrlib."""
@@ -28,4 +30,5 @@
 
 
 def on_set_rh(branch, rev_history):
-    """XXXX"""
+    """Announce the new revision_history of branch to dbus."""
+    activity.Activity().advertise_branch(branch)

=== modified file 'tests/test_hook.py'
--- a/tests/test_hook.py	2007-02-06 03:30:59 +0000
+++ b/tests/test_hook.py	2007-02-06 03:48:33 +0000
@@ -21,7 +21,7 @@
 from bzrlib.branch import Branch
 from bzrlib.tests import TestCaseWithMemoryTransport
 
-from bzrlib.plugins.dbus import hook
+from bzrlib.plugins.dbus import activity, hook
 
 
 class TestHooksAreSet(TestCaseWithMemoryTransport):
@@ -36,3 +36,24 @@
         """dbus.hook.install_hooks() should atler Branch.hooks."""
         hook.install_hooks()
         self.assertTrue(hook.on_set_rh in Branch.hooks['set_rh'])
+
+    def test_on_set_rh_hook(self):
+        """The on_set_rh hook should hand off the branch to advertise it."""
+        # change the global b.p.dbus.activity.Activity to instrument
+        # on_set_rh.
+        calls = []
+        class SampleActivity(object):
+
+            def advertise_branch(self, branch):
+                calls.append(('advertise_branch', branch))
+
+        # prevent api skew: check we can use the API SampleActivity presents.
+        activity.Activity().advertise_branch(self.make_branch('.'))
+        # now test the hook
+        original_class = activity.Activity
+        try:
+            activity.Activity = SampleActivity
+            hook.on_set_rh('branch', 'history')
+        finally:
+            activity.Activity = original_class
+        self.assertEqual([('advertise_branch', 'branch')], calls)



More information about the bazaar-commits mailing list