##// END OF EJS Templates
extensions: add wrapping functions
Matt Mackall -
r7215:0ab5f21c default
parent child Browse files
Show More
@@ -6,7 +6,7 b''
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 = {}
@@ -87,3 +87,28 b' def loadall(ui):'
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
General Comments 0
You need to be logged in to leave comments. Login now