comparison mercurial/extensions.py @ 7215:0ab5f21c390b

extensions: add wrapping functions
author Matt Mackall <mpm@selenic.com>
date Wed, 22 Oct 2008 17:34:50 -0500
parents 7da76778dbd7
children d9e9dd2b00fb
comparison
equal deleted inserted replaced
7214:0e8a9530d323 7215:0ab5f21c390b
4 # 4 #
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 import imp, os 8 import imp, os
9 import util 9 import util, cmdutil
10 from i18n import _ 10 from i18n import _
11 11
12 _extensions = {} 12 _extensions = {}
13 _order = [] 13 _order = []
14 14
85 ui.warn(_("*** failed to import extension %s: %s\n") 85 ui.warn(_("*** failed to import extension %s: %s\n")
86 % (name, inst)) 86 % (name, inst))
87 if ui.print_exc(): 87 if ui.print_exc():
88 return 1 88 return 1
89 89
90 def wrapcommand(table, command, wrapper):
91 aliases, entry = cmdutil.findcmd(command, table)
92 for alias, e in table.iteritems():
93 if e is entry:
94 key = alias
95 break
96
97 origfn = entry[0]
98 def wrap(*args, **kwargs):
99 return wrapper(origfn, *args, **kwargs)
100
101 wrap.__doc__ = getattr(origfn, '__doc__')
102
103 newentry = list(entry)
104 newentry[0] = wrap
105 table[key] = tuple(newentry)
106 return entry
107
108 def wrapfunction(container, funcname, wrapper):
109 def wrap(*args, **kwargs):
110 return wrapper(origfn, *args, **kwargs)
111
112 origfn = getattr(container, funcname)
113 setattr(container, funcname, wrap)
114 return origfn