5 # This software may be used and distributed according to the terms |
5 # This software may be used and distributed according to the terms |
6 # of the GNU General Public License, incorporated herein by reference. |
6 # of the GNU General Public License, incorporated herein by reference. |
7 |
7 |
8 from i18n import _ |
8 from i18n import _ |
9 import util, os, sys |
9 import util, os, sys |
|
10 from mercurial import extensions |
10 |
11 |
11 def _pythonhook(ui, repo, name, hname, funcname, args, throw): |
12 def _pythonhook(ui, repo, name, hname, funcname, args, throw): |
12 '''call python hook. hook is callable object, looked up as |
13 '''call python hook. hook is callable object, looked up as |
13 name in python module. if callable returns "true", hook |
14 name in python module. if callable returns "true", hook |
14 fails, else passes. if hook raises exception, treated as |
15 fails, else passes. if hook raises exception, treated as |
107 if hname.split('.')[0] != name or not cmd: |
108 if hname.split('.')[0] != name or not cmd: |
108 continue |
109 continue |
109 if callable(cmd): |
110 if callable(cmd): |
110 r = _pythonhook(ui, repo, name, hname, cmd, args, throw) or r |
111 r = _pythonhook(ui, repo, name, hname, cmd, args, throw) or r |
111 elif cmd.startswith('python:'): |
112 elif cmd.startswith('python:'): |
112 r = _pythonhook(ui, repo, name, hname, cmd[7:].strip(), |
113 if cmd.count(':') == 2: |
113 args, throw) or r |
114 path, cmd = cmd[7:].split(':') |
|
115 mod = extensions.loadpath(path, 'hgkook.%s' % hname) |
|
116 hookfn = getattr(mod, cmd) |
|
117 else: |
|
118 hookfn = cmd[7:].strip() |
|
119 r = _pythonhook(ui, repo, name, hname, hookfn, args, throw) or r |
114 else: |
120 else: |
115 r = _exthook(ui, repo, hname, cmd, args, throw) or r |
121 r = _exthook(ui, repo, hname, cmd, args, throw) or r |
116 finally: |
122 finally: |
117 if _redirect: |
123 if _redirect: |
118 os.dup2(oldstdout, sys.__stdout__.fileno()) |
124 os.dup2(oldstdout, sys.__stdout__.fileno()) |