Sketch in skeleton of module from bzr-email
[bzrirker.git] / __init__.py
diff --git a/__init__.py b/__init__.py
new file mode 100644 (file)
index 0000000..31a2680
--- /dev/null
@@ -0,0 +1,60 @@
+# -*- coding: utf-8 -*-
+# vim:fileencoding=utf-8 ai ts=4 sts=4 et sw=4
+# Copyright 2012 Neil Muller
+# GPL 2+ - see COPYING for details
+"""Sending irker notifications for commits and branch changes.
+
+Details to follow
+"""
+
+from bzrlib.config import option_registry
+from bzrlib.lazy_import import lazy_import
+
+# lazy_import so that it doesn't get loaded if it isn't used
+# Approach borrowed from bzr-email
+lazy_import(globals(), """\
+from bzrlib.plugins.irkerhook import irkerhook as _irkerhook
+""")
+
+
+def post_commit(branch, revision_id):
+    """This is the post_commit hook that should get run after commit."""
+    _irkerhook.IrkerSender(branch, revision_id,
+            branch.get_config_stack()).send_maybe()
+
+
+def branch_commit_hook(local, master, old_revno, old_revid,
+        new_revno, new_revid):
+    """This is the post_commit hook that runs after commit."""
+    _irkerhook.IrkerSender(master, new_revid, master.get_config_stack(),
+                         local_branch=local).send_maybe()
+
+
+def branch_post_change_hook(params):
+    """This is the post_change_branch_tip hook."""
+    # (branch, old_revno, new_revno, old_revid, new_revid)
+    _irker.IrkerSender(params.branch, params.new_revid,
+        params.branch.get_config_stack(), local_branch=None,
+        op='change').send_maybe()
+
+
+def test_suite():
+    from unittest import TestSuite
+    import bzrlib.plugins.irkerhook.tests
+    result = TestSuite()
+    result.addTest(bzrlib.plugins.irkerhook.tests.test_suite())
+    return result
+
+
+option_registry.register_lazy("irker_channels",
+    "bzrlib.plugins.irkerhook.irkerhook", "opt_irker_channels")
+option_registry.register_lazy("irker_colours",
+    "bzrlib.plugins.irkerhook.irkerhook", "opt_irker_colours")
+option_registry.register_lazy("irker_url",
+    "bzrlib.plugins.irkerhook.irkerhook", "opt_irker_url")
+
+from bzrlib.hooks import install_lazy_named_hook
+install_lazy_named_hook("bzrlib.branch", "Branch.hooks", 'post_commit',
+        branch_commit_hook, 'bzr-irker')
+install_lazy_named_hook("bzrlib.branch", "Branch.hooks",
+        'post_change_branch_tip', branch_post_change_hook, 'bzr-irker')