source: repositoryhooksystemplugin/0.11/repository_hook_system/interface.py

Last change on this file was 5056, checked in by Jeff Hammel, 15 years ago

check for plugin enablability and display HTML accordingly; closes #4104

File size: 2.7 KB
Line 
1"""
2interfaces for listening to repository changes
3and configuration of hooks
4"""
5
6from trac.core import Interface
7
8### interfaces for subscribers
9
10class IRepositoryHookSubscriber(Interface):
11    """
12    interface for subscribers to repository hooks
13    """
14
15    def is_available(repository, hookname):
16        """can this subscriber be invoked on this hook?"""       
17
18    def invoke(changeset):
19        """what to do on a commit"""
20
21### interfaces for the hook system
22
23class IRepositoryChangeListener(Interface):
24    """listeners to changes from repository hooks"""
25
26    def type():
27        """list of types of repository to listen for changes"""
28
29    def available_hooks():
30        """hooks available for the repository"""
31
32    def changeset(repo, hookname, *args):
33        """return the changeset as specified by the SCM-specific arguments"""
34
35    def subscribers(hookname): # XXX needed? -> elsewhere?
36        """returns activated subscribers for a given hook"""
37        # XXX this should probably be moved, as it puts
38        # the burden of knowing the subscriber on essentially
39        # the repository.  This is better done in infrastructure
40        # outside the repository;
41        # or maybe this isn't horrible if an abstract base class
42        # is used for this interface
43
44    def invoke_hook(repo, hookname, *args):
45        """fires the given hook"""
46
47class IRepositoryHookSetup(Interface):
48    """participants capable of setting up hooks"""
49
50    def enable(hookname):
51        """enable the RepositoryChangeListener callback for a given hook"""
52
53    def disable(hookname):
54        """disable the RepositoryChangeListener callback for a given hook"""
55
56    def is_enabled(hookname):
57        """
58        whether the hook has been set up; 
59        contingent upon enable marking the hook in such a way that it can be identified as enabled
60        """
61
62    def can_enable(hookname):
63        """
64        whether the hook can be set up
65        """
66
67class IRepositoryHookAdminContributer(Interface):
68    """
69    contributes to the webadmin panel for the RepositoryHookSystem
70    """
71    # XXX there should probably an equivalent on the level of IRepositoryHookSubscribers
72
73    def render(hookname, req):
74        """extra HTML to display in the webadmin panel for the hook"""
75       
76    def process_post(hookname, req):
77        """what to do on a POST request"""
78
79class IRepositoryHookSystem(IRepositoryChangeListener, IRepositoryHookSetup, IRepositoryHookAdminContributer):
80    """
81    mixed-in interface for a complete hook system;
82    implementers should be able to listen for changes (IRepositoryChangeListener)
83    as well as setup the hooks (IRepositoryHookSetup)
84    and contribute to the webadmin interface (IRepositoryHookAdminContributer)
85    """
Note: See TracBrowser for help on using the repository browser.