##// END OF EJS Templates
dispatch: fix for-loop variable name
Idan Kamara -
r14618:110d75f0 default
parent child Browse files
Show More
@@ -1,709 +1,709 b''
1 # dispatch.py - command dispatching for mercurial
1 # dispatch.py - command dispatching for mercurial
2 #
2 #
3 # Copyright 2005-2007 Matt Mackall <mpm@selenic.com>
3 # Copyright 2005-2007 Matt Mackall <mpm@selenic.com>
4 #
4 #
5 # This software may be used and distributed according to the terms of the
5 # This software may be used and distributed according to the terms of the
6 # GNU General Public License version 2 or any later version.
6 # GNU General Public License version 2 or any later version.
7
7
8 from i18n import _
8 from i18n import _
9 import os, sys, atexit, signal, pdb, socket, errno, shlex, time, traceback, re
9 import os, sys, atexit, signal, pdb, socket, errno, shlex, time, traceback, re
10 import util, commands, hg, fancyopts, extensions, hook, error
10 import util, commands, hg, fancyopts, extensions, hook, error
11 import cmdutil, encoding
11 import cmdutil, encoding
12 import ui as uimod
12 import ui as uimod
13
13
14 class request(object):
14 class request(object):
15 def __init__(self, args, ui=None, repo=None, fin=None, fout=None, ferr=None):
15 def __init__(self, args, ui=None, repo=None, fin=None, fout=None, ferr=None):
16 self.args = args
16 self.args = args
17 self.ui = ui
17 self.ui = ui
18 self.repo = repo
18 self.repo = repo
19
19
20 # input/output/error streams
20 # input/output/error streams
21 self.fin = fin
21 self.fin = fin
22 self.fout = fout
22 self.fout = fout
23 self.ferr = ferr
23 self.ferr = ferr
24
24
25 def run():
25 def run():
26 "run the command in sys.argv"
26 "run the command in sys.argv"
27 sys.exit(dispatch(request(sys.argv[1:])))
27 sys.exit(dispatch(request(sys.argv[1:])))
28
28
29 def dispatch(req):
29 def dispatch(req):
30 "run the command specified in req.args"
30 "run the command specified in req.args"
31 if req.ferr:
31 if req.ferr:
32 ferr = req.ferr
32 ferr = req.ferr
33 elif req.ui:
33 elif req.ui:
34 ferr = req.ui.ferr
34 ferr = req.ui.ferr
35 else:
35 else:
36 ferr = sys.stderr
36 ferr = sys.stderr
37
37
38 try:
38 try:
39 if not req.ui:
39 if not req.ui:
40 req.ui = uimod.ui()
40 req.ui = uimod.ui()
41 if '--traceback' in req.args:
41 if '--traceback' in req.args:
42 req.ui.setconfig('ui', 'traceback', 'on')
42 req.ui.setconfig('ui', 'traceback', 'on')
43
43
44 # set ui streams from the request
44 # set ui streams from the request
45 if req.fin:
45 if req.fin:
46 req.ui.fin = req.fin
46 req.ui.fin = req.fin
47 if req.fout:
47 if req.fout:
48 req.ui.fout = req.fout
48 req.ui.fout = req.fout
49 if req.ferr:
49 if req.ferr:
50 req.ui.ferr = req.ferr
50 req.ui.ferr = req.ferr
51 except util.Abort, inst:
51 except util.Abort, inst:
52 ferr.write(_("abort: %s\n") % inst)
52 ferr.write(_("abort: %s\n") % inst)
53 if inst.hint:
53 if inst.hint:
54 ferr.write(_("(%s)\n") % inst.hint)
54 ferr.write(_("(%s)\n") % inst.hint)
55 return -1
55 return -1
56 except error.ParseError, inst:
56 except error.ParseError, inst:
57 if len(inst.args) > 1:
57 if len(inst.args) > 1:
58 ferr.write(_("hg: parse error at %s: %s\n") %
58 ferr.write(_("hg: parse error at %s: %s\n") %
59 (inst.args[1], inst.args[0]))
59 (inst.args[1], inst.args[0]))
60 else:
60 else:
61 ferr.write(_("hg: parse error: %s\n") % inst.args[0])
61 ferr.write(_("hg: parse error: %s\n") % inst.args[0])
62 return -1
62 return -1
63
63
64 return _runcatch(req)
64 return _runcatch(req)
65
65
66 def _runcatch(req):
66 def _runcatch(req):
67 def catchterm(*args):
67 def catchterm(*args):
68 raise error.SignalInterrupt
68 raise error.SignalInterrupt
69
69
70 ui = req.ui
70 ui = req.ui
71 try:
71 try:
72 for name in 'SIGBREAK', 'SIGHUP', 'SIGTERM':
72 for name in 'SIGBREAK', 'SIGHUP', 'SIGTERM':
73 num = getattr(signal, name, None)
73 num = getattr(signal, name, None)
74 if num:
74 if num:
75 signal.signal(num, catchterm)
75 signal.signal(num, catchterm)
76 except ValueError:
76 except ValueError:
77 pass # happens if called in a thread
77 pass # happens if called in a thread
78
78
79 try:
79 try:
80 try:
80 try:
81 # enter the debugger before command execution
81 # enter the debugger before command execution
82 if '--debugger' in req.args:
82 if '--debugger' in req.args:
83 ui.warn(_("entering debugger - "
83 ui.warn(_("entering debugger - "
84 "type c to continue starting hg or h for help\n"))
84 "type c to continue starting hg or h for help\n"))
85 pdb.set_trace()
85 pdb.set_trace()
86 try:
86 try:
87 return _dispatch(req)
87 return _dispatch(req)
88 finally:
88 finally:
89 ui.flush()
89 ui.flush()
90 except:
90 except:
91 # enter the debugger when we hit an exception
91 # enter the debugger when we hit an exception
92 if '--debugger' in req.args:
92 if '--debugger' in req.args:
93 traceback.print_exc()
93 traceback.print_exc()
94 pdb.post_mortem(sys.exc_info()[2])
94 pdb.post_mortem(sys.exc_info()[2])
95 ui.traceback()
95 ui.traceback()
96 raise
96 raise
97
97
98 # Global exception handling, alphabetically
98 # Global exception handling, alphabetically
99 # Mercurial-specific first, followed by built-in and library exceptions
99 # Mercurial-specific first, followed by built-in and library exceptions
100 except error.AmbiguousCommand, inst:
100 except error.AmbiguousCommand, inst:
101 ui.warn(_("hg: command '%s' is ambiguous:\n %s\n") %
101 ui.warn(_("hg: command '%s' is ambiguous:\n %s\n") %
102 (inst.args[0], " ".join(inst.args[1])))
102 (inst.args[0], " ".join(inst.args[1])))
103 except error.ParseError, inst:
103 except error.ParseError, inst:
104 if len(inst.args) > 1:
104 if len(inst.args) > 1:
105 ui.warn(_("hg: parse error at %s: %s\n") %
105 ui.warn(_("hg: parse error at %s: %s\n") %
106 (inst.args[1], inst.args[0]))
106 (inst.args[1], inst.args[0]))
107 else:
107 else:
108 ui.warn(_("hg: parse error: %s\n") % inst.args[0])
108 ui.warn(_("hg: parse error: %s\n") % inst.args[0])
109 return -1
109 return -1
110 except error.LockHeld, inst:
110 except error.LockHeld, inst:
111 if inst.errno == errno.ETIMEDOUT:
111 if inst.errno == errno.ETIMEDOUT:
112 reason = _('timed out waiting for lock held by %s') % inst.locker
112 reason = _('timed out waiting for lock held by %s') % inst.locker
113 else:
113 else:
114 reason = _('lock held by %s') % inst.locker
114 reason = _('lock held by %s') % inst.locker
115 ui.warn(_("abort: %s: %s\n") % (inst.desc or inst.filename, reason))
115 ui.warn(_("abort: %s: %s\n") % (inst.desc or inst.filename, reason))
116 except error.LockUnavailable, inst:
116 except error.LockUnavailable, inst:
117 ui.warn(_("abort: could not lock %s: %s\n") %
117 ui.warn(_("abort: could not lock %s: %s\n") %
118 (inst.desc or inst.filename, inst.strerror))
118 (inst.desc or inst.filename, inst.strerror))
119 except error.CommandError, inst:
119 except error.CommandError, inst:
120 if inst.args[0]:
120 if inst.args[0]:
121 ui.warn(_("hg %s: %s\n") % (inst.args[0], inst.args[1]))
121 ui.warn(_("hg %s: %s\n") % (inst.args[0], inst.args[1]))
122 commands.help_(ui, inst.args[0], full=False, command=True)
122 commands.help_(ui, inst.args[0], full=False, command=True)
123 else:
123 else:
124 ui.warn(_("hg: %s\n") % inst.args[1])
124 ui.warn(_("hg: %s\n") % inst.args[1])
125 commands.help_(ui, 'shortlist')
125 commands.help_(ui, 'shortlist')
126 except error.RepoError, inst:
126 except error.RepoError, inst:
127 ui.warn(_("abort: %s!\n") % inst)
127 ui.warn(_("abort: %s!\n") % inst)
128 except error.ResponseError, inst:
128 except error.ResponseError, inst:
129 ui.warn(_("abort: %s") % inst.args[0])
129 ui.warn(_("abort: %s") % inst.args[0])
130 if not isinstance(inst.args[1], basestring):
130 if not isinstance(inst.args[1], basestring):
131 ui.warn(" %r\n" % (inst.args[1],))
131 ui.warn(" %r\n" % (inst.args[1],))
132 elif not inst.args[1]:
132 elif not inst.args[1]:
133 ui.warn(_(" empty string\n"))
133 ui.warn(_(" empty string\n"))
134 else:
134 else:
135 ui.warn("\n%r\n" % util.ellipsis(inst.args[1]))
135 ui.warn("\n%r\n" % util.ellipsis(inst.args[1]))
136 except error.RevlogError, inst:
136 except error.RevlogError, inst:
137 ui.warn(_("abort: %s!\n") % inst)
137 ui.warn(_("abort: %s!\n") % inst)
138 except error.SignalInterrupt:
138 except error.SignalInterrupt:
139 ui.warn(_("killed!\n"))
139 ui.warn(_("killed!\n"))
140 except error.UnknownCommand, inst:
140 except error.UnknownCommand, inst:
141 ui.warn(_("hg: unknown command '%s'\n") % inst.args[0])
141 ui.warn(_("hg: unknown command '%s'\n") % inst.args[0])
142 try:
142 try:
143 # check if the command is in a disabled extension
143 # check if the command is in a disabled extension
144 # (but don't check for extensions themselves)
144 # (but don't check for extensions themselves)
145 commands.help_(ui, inst.args[0], unknowncmd=True)
145 commands.help_(ui, inst.args[0], unknowncmd=True)
146 except error.UnknownCommand:
146 except error.UnknownCommand:
147 commands.help_(ui, 'shortlist')
147 commands.help_(ui, 'shortlist')
148 except util.Abort, inst:
148 except util.Abort, inst:
149 ui.warn(_("abort: %s\n") % inst)
149 ui.warn(_("abort: %s\n") % inst)
150 if inst.hint:
150 if inst.hint:
151 ui.warn(_("(%s)\n") % inst.hint)
151 ui.warn(_("(%s)\n") % inst.hint)
152 except ImportError, inst:
152 except ImportError, inst:
153 ui.warn(_("abort: %s!\n") % inst)
153 ui.warn(_("abort: %s!\n") % inst)
154 m = str(inst).split()[-1]
154 m = str(inst).split()[-1]
155 if m in "mpatch bdiff".split():
155 if m in "mpatch bdiff".split():
156 ui.warn(_("(did you forget to compile extensions?)\n"))
156 ui.warn(_("(did you forget to compile extensions?)\n"))
157 elif m in "zlib".split():
157 elif m in "zlib".split():
158 ui.warn(_("(is your Python install correct?)\n"))
158 ui.warn(_("(is your Python install correct?)\n"))
159 except IOError, inst:
159 except IOError, inst:
160 if hasattr(inst, "code"):
160 if hasattr(inst, "code"):
161 ui.warn(_("abort: %s\n") % inst)
161 ui.warn(_("abort: %s\n") % inst)
162 elif hasattr(inst, "reason"):
162 elif hasattr(inst, "reason"):
163 try: # usually it is in the form (errno, strerror)
163 try: # usually it is in the form (errno, strerror)
164 reason = inst.reason.args[1]
164 reason = inst.reason.args[1]
165 except (AttributeError, IndexError):
165 except (AttributeError, IndexError):
166 # it might be anything, for example a string
166 # it might be anything, for example a string
167 reason = inst.reason
167 reason = inst.reason
168 ui.warn(_("abort: error: %s\n") % reason)
168 ui.warn(_("abort: error: %s\n") % reason)
169 elif hasattr(inst, "args") and inst.args[0] == errno.EPIPE:
169 elif hasattr(inst, "args") and inst.args[0] == errno.EPIPE:
170 if ui.debugflag:
170 if ui.debugflag:
171 ui.warn(_("broken pipe\n"))
171 ui.warn(_("broken pipe\n"))
172 elif getattr(inst, "strerror", None):
172 elif getattr(inst, "strerror", None):
173 if getattr(inst, "filename", None):
173 if getattr(inst, "filename", None):
174 ui.warn(_("abort: %s: %s\n") % (inst.strerror, inst.filename))
174 ui.warn(_("abort: %s: %s\n") % (inst.strerror, inst.filename))
175 else:
175 else:
176 ui.warn(_("abort: %s\n") % inst.strerror)
176 ui.warn(_("abort: %s\n") % inst.strerror)
177 else:
177 else:
178 raise
178 raise
179 except OSError, inst:
179 except OSError, inst:
180 if getattr(inst, "filename", None):
180 if getattr(inst, "filename", None):
181 ui.warn(_("abort: %s: %s\n") % (inst.strerror, inst.filename))
181 ui.warn(_("abort: %s: %s\n") % (inst.strerror, inst.filename))
182 else:
182 else:
183 ui.warn(_("abort: %s\n") % inst.strerror)
183 ui.warn(_("abort: %s\n") % inst.strerror)
184 except KeyboardInterrupt:
184 except KeyboardInterrupt:
185 try:
185 try:
186 ui.warn(_("interrupted!\n"))
186 ui.warn(_("interrupted!\n"))
187 except IOError, inst:
187 except IOError, inst:
188 if inst.errno == errno.EPIPE:
188 if inst.errno == errno.EPIPE:
189 if ui.debugflag:
189 if ui.debugflag:
190 ui.warn(_("\nbroken pipe\n"))
190 ui.warn(_("\nbroken pipe\n"))
191 else:
191 else:
192 raise
192 raise
193 except MemoryError:
193 except MemoryError:
194 ui.warn(_("abort: out of memory\n"))
194 ui.warn(_("abort: out of memory\n"))
195 except SystemExit, inst:
195 except SystemExit, inst:
196 # Commands shouldn't sys.exit directly, but give a return code.
196 # Commands shouldn't sys.exit directly, but give a return code.
197 # Just in case catch this and and pass exit code to caller.
197 # Just in case catch this and and pass exit code to caller.
198 return inst.code
198 return inst.code
199 except socket.error, inst:
199 except socket.error, inst:
200 ui.warn(_("abort: %s\n") % inst.args[-1])
200 ui.warn(_("abort: %s\n") % inst.args[-1])
201 except:
201 except:
202 ui.warn(_("** unknown exception encountered,"
202 ui.warn(_("** unknown exception encountered,"
203 " please report by visiting\n"))
203 " please report by visiting\n"))
204 ui.warn(_("** http://mercurial.selenic.com/wiki/BugTracker\n"))
204 ui.warn(_("** http://mercurial.selenic.com/wiki/BugTracker\n"))
205 ui.warn(_("** Python %s\n") % sys.version.replace('\n', ''))
205 ui.warn(_("** Python %s\n") % sys.version.replace('\n', ''))
206 ui.warn(_("** Mercurial Distributed SCM (version %s)\n")
206 ui.warn(_("** Mercurial Distributed SCM (version %s)\n")
207 % util.version())
207 % util.version())
208 ui.warn(_("** Extensions loaded: %s\n")
208 ui.warn(_("** Extensions loaded: %s\n")
209 % ", ".join([x[0] for x in extensions.extensions()]))
209 % ", ".join([x[0] for x in extensions.extensions()]))
210 raise
210 raise
211
211
212 return -1
212 return -1
213
213
214 def aliasargs(fn, givenargs):
214 def aliasargs(fn, givenargs):
215 args = getattr(fn, 'args', [])
215 args = getattr(fn, 'args', [])
216 if args and givenargs:
216 if args and givenargs:
217 cmd = ' '.join(map(util.shellquote, args))
217 cmd = ' '.join(map(util.shellquote, args))
218
218
219 nums = []
219 nums = []
220 def replacer(m):
220 def replacer(m):
221 num = int(m.group(1)) - 1
221 num = int(m.group(1)) - 1
222 nums.append(num)
222 nums.append(num)
223 return givenargs[num]
223 return givenargs[num]
224 cmd = re.sub(r'\$(\d+|\$)', replacer, cmd)
224 cmd = re.sub(r'\$(\d+|\$)', replacer, cmd)
225 givenargs = [x for i, x in enumerate(givenargs)
225 givenargs = [x for i, x in enumerate(givenargs)
226 if i not in nums]
226 if i not in nums]
227 args = shlex.split(cmd)
227 args = shlex.split(cmd)
228 return args + givenargs
228 return args + givenargs
229
229
230 class cmdalias(object):
230 class cmdalias(object):
231 def __init__(self, name, definition, cmdtable):
231 def __init__(self, name, definition, cmdtable):
232 self.name = self.cmd = name
232 self.name = self.cmd = name
233 self.cmdname = ''
233 self.cmdname = ''
234 self.definition = definition
234 self.definition = definition
235 self.args = []
235 self.args = []
236 self.opts = []
236 self.opts = []
237 self.help = ''
237 self.help = ''
238 self.norepo = True
238 self.norepo = True
239 self.badalias = False
239 self.badalias = False
240
240
241 try:
241 try:
242 aliases, entry = cmdutil.findcmd(self.name, cmdtable)
242 aliases, entry = cmdutil.findcmd(self.name, cmdtable)
243 for alias, e in cmdtable.iteritems():
243 for alias, e in cmdtable.iteritems():
244 if e is entry:
244 if e is entry:
245 self.cmd = alias
245 self.cmd = alias
246 break
246 break
247 self.shadows = True
247 self.shadows = True
248 except error.UnknownCommand:
248 except error.UnknownCommand:
249 self.shadows = False
249 self.shadows = False
250
250
251 if not self.definition:
251 if not self.definition:
252 def fn(ui, *args):
252 def fn(ui, *args):
253 ui.warn(_("no definition for alias '%s'\n") % self.name)
253 ui.warn(_("no definition for alias '%s'\n") % self.name)
254 return 1
254 return 1
255 self.fn = fn
255 self.fn = fn
256 self.badalias = True
256 self.badalias = True
257
257
258 return
258 return
259
259
260 if self.definition.startswith('!'):
260 if self.definition.startswith('!'):
261 self.shell = True
261 self.shell = True
262 def fn(ui, *args):
262 def fn(ui, *args):
263 env = {'HG_ARGS': ' '.join((self.name,) + args)}
263 env = {'HG_ARGS': ' '.join((self.name,) + args)}
264 def _checkvar(m):
264 def _checkvar(m):
265 if m.groups()[0] == '$':
265 if m.groups()[0] == '$':
266 return m.group()
266 return m.group()
267 elif int(m.groups()[0]) <= len(args):
267 elif int(m.groups()[0]) <= len(args):
268 return m.group()
268 return m.group()
269 else:
269 else:
270 ui.debug(_("No argument found for substitution "
270 ui.debug(_("No argument found for substitution "
271 "of %i variable in alias '%s' definition.")
271 "of %i variable in alias '%s' definition.")
272 % (int(m.groups()[0]), self.name))
272 % (int(m.groups()[0]), self.name))
273 return ''
273 return ''
274 cmd = re.sub(r'\$(\d+|\$)', _checkvar, self.definition[1:])
274 cmd = re.sub(r'\$(\d+|\$)', _checkvar, self.definition[1:])
275 replace = dict((str(i + 1), arg) for i, arg in enumerate(args))
275 replace = dict((str(i + 1), arg) for i, arg in enumerate(args))
276 replace['0'] = self.name
276 replace['0'] = self.name
277 replace['@'] = ' '.join(args)
277 replace['@'] = ' '.join(args)
278 cmd = util.interpolate(r'\$', replace, cmd, escape_prefix=True)
278 cmd = util.interpolate(r'\$', replace, cmd, escape_prefix=True)
279 return util.system(cmd, environ=env)
279 return util.system(cmd, environ=env)
280 self.fn = fn
280 self.fn = fn
281 return
281 return
282
282
283 args = shlex.split(self.definition)
283 args = shlex.split(self.definition)
284 self.cmdname = cmd = args.pop(0)
284 self.cmdname = cmd = args.pop(0)
285 args = map(util.expandpath, args)
285 args = map(util.expandpath, args)
286
286
287 for invalidarg in ("--cwd", "-R", "--repository", "--repo"):
287 for invalidarg in ("--cwd", "-R", "--repository", "--repo"):
288 if _earlygetopt([invalidarg], args):
288 if _earlygetopt([invalidarg], args):
289 def fn(ui, *args):
289 def fn(ui, *args):
290 ui.warn(_("error in definition for alias '%s': %s may only "
290 ui.warn(_("error in definition for alias '%s': %s may only "
291 "be given on the command line\n")
291 "be given on the command line\n")
292 % (self.name, invalidarg))
292 % (self.name, invalidarg))
293 return 1
293 return 1
294
294
295 self.fn = fn
295 self.fn = fn
296 self.badalias = True
296 self.badalias = True
297 return
297 return
298
298
299 try:
299 try:
300 tableentry = cmdutil.findcmd(cmd, cmdtable, False)[1]
300 tableentry = cmdutil.findcmd(cmd, cmdtable, False)[1]
301 if len(tableentry) > 2:
301 if len(tableentry) > 2:
302 self.fn, self.opts, self.help = tableentry
302 self.fn, self.opts, self.help = tableentry
303 else:
303 else:
304 self.fn, self.opts = tableentry
304 self.fn, self.opts = tableentry
305
305
306 self.args = aliasargs(self.fn, args)
306 self.args = aliasargs(self.fn, args)
307 if cmd not in commands.norepo.split(' '):
307 if cmd not in commands.norepo.split(' '):
308 self.norepo = False
308 self.norepo = False
309 if self.help.startswith("hg " + cmd):
309 if self.help.startswith("hg " + cmd):
310 # drop prefix in old-style help lines so hg shows the alias
310 # drop prefix in old-style help lines so hg shows the alias
311 self.help = self.help[4 + len(cmd):]
311 self.help = self.help[4 + len(cmd):]
312 self.__doc__ = self.fn.__doc__
312 self.__doc__ = self.fn.__doc__
313
313
314 except error.UnknownCommand:
314 except error.UnknownCommand:
315 def fn(ui, *args):
315 def fn(ui, *args):
316 ui.warn(_("alias '%s' resolves to unknown command '%s'\n") \
316 ui.warn(_("alias '%s' resolves to unknown command '%s'\n") \
317 % (self.name, cmd))
317 % (self.name, cmd))
318 try:
318 try:
319 # check if the command is in a disabled extension
319 # check if the command is in a disabled extension
320 commands.help_(ui, cmd, unknowncmd=True)
320 commands.help_(ui, cmd, unknowncmd=True)
321 except error.UnknownCommand:
321 except error.UnknownCommand:
322 pass
322 pass
323 return 1
323 return 1
324 self.fn = fn
324 self.fn = fn
325 self.badalias = True
325 self.badalias = True
326 except error.AmbiguousCommand:
326 except error.AmbiguousCommand:
327 def fn(ui, *args):
327 def fn(ui, *args):
328 ui.warn(_("alias '%s' resolves to ambiguous command '%s'\n") \
328 ui.warn(_("alias '%s' resolves to ambiguous command '%s'\n") \
329 % (self.name, cmd))
329 % (self.name, cmd))
330 return 1
330 return 1
331 self.fn = fn
331 self.fn = fn
332 self.badalias = True
332 self.badalias = True
333
333
334 def __call__(self, ui, *args, **opts):
334 def __call__(self, ui, *args, **opts):
335 if self.shadows:
335 if self.shadows:
336 ui.debug("alias '%s' shadows command '%s'\n" %
336 ui.debug("alias '%s' shadows command '%s'\n" %
337 (self.name, self.cmdname))
337 (self.name, self.cmdname))
338
338
339 if hasattr(self, 'shell'):
339 if hasattr(self, 'shell'):
340 return self.fn(ui, *args, **opts)
340 return self.fn(ui, *args, **opts)
341 else:
341 else:
342 try:
342 try:
343 util.checksignature(self.fn)(ui, *args, **opts)
343 util.checksignature(self.fn)(ui, *args, **opts)
344 except error.SignatureError:
344 except error.SignatureError:
345 args = ' '.join([self.cmdname] + self.args)
345 args = ' '.join([self.cmdname] + self.args)
346 ui.debug("alias '%s' expands to '%s'\n" % (self.name, args))
346 ui.debug("alias '%s' expands to '%s'\n" % (self.name, args))
347 raise
347 raise
348
348
349 def addaliases(ui, cmdtable):
349 def addaliases(ui, cmdtable):
350 # aliases are processed after extensions have been loaded, so they
350 # aliases are processed after extensions have been loaded, so they
351 # may use extension commands. Aliases can also use other alias definitions,
351 # may use extension commands. Aliases can also use other alias definitions,
352 # but only if they have been defined prior to the current definition.
352 # but only if they have been defined prior to the current definition.
353 for alias, definition in ui.configitems('alias'):
353 for alias, definition in ui.configitems('alias'):
354 aliasdef = cmdalias(alias, definition, cmdtable)
354 aliasdef = cmdalias(alias, definition, cmdtable)
355 cmdtable[aliasdef.cmd] = (aliasdef, aliasdef.opts, aliasdef.help)
355 cmdtable[aliasdef.cmd] = (aliasdef, aliasdef.opts, aliasdef.help)
356 if aliasdef.norepo:
356 if aliasdef.norepo:
357 commands.norepo += ' %s' % alias
357 commands.norepo += ' %s' % alias
358
358
359 def _parse(ui, args):
359 def _parse(ui, args):
360 options = {}
360 options = {}
361 cmdoptions = {}
361 cmdoptions = {}
362
362
363 try:
363 try:
364 args = fancyopts.fancyopts(args, commands.globalopts, options)
364 args = fancyopts.fancyopts(args, commands.globalopts, options)
365 except fancyopts.getopt.GetoptError, inst:
365 except fancyopts.getopt.GetoptError, inst:
366 raise error.CommandError(None, inst)
366 raise error.CommandError(None, inst)
367
367
368 if args:
368 if args:
369 cmd, args = args[0], args[1:]
369 cmd, args = args[0], args[1:]
370 aliases, entry = cmdutil.findcmd(cmd, commands.table,
370 aliases, entry = cmdutil.findcmd(cmd, commands.table,
371 ui.config("ui", "strict"))
371 ui.config("ui", "strict"))
372 cmd = aliases[0]
372 cmd = aliases[0]
373 args = aliasargs(entry[0], args)
373 args = aliasargs(entry[0], args)
374 defaults = ui.config("defaults", cmd)
374 defaults = ui.config("defaults", cmd)
375 if defaults:
375 if defaults:
376 args = map(util.expandpath, shlex.split(defaults)) + args
376 args = map(util.expandpath, shlex.split(defaults)) + args
377 c = list(entry[1])
377 c = list(entry[1])
378 else:
378 else:
379 cmd = None
379 cmd = None
380 c = []
380 c = []
381
381
382 # combine global options into local
382 # combine global options into local
383 for o in commands.globalopts:
383 for o in commands.globalopts:
384 c.append((o[0], o[1], options[o[1]], o[3]))
384 c.append((o[0], o[1], options[o[1]], o[3]))
385
385
386 try:
386 try:
387 args = fancyopts.fancyopts(args, c, cmdoptions, True)
387 args = fancyopts.fancyopts(args, c, cmdoptions, True)
388 except fancyopts.getopt.GetoptError, inst:
388 except fancyopts.getopt.GetoptError, inst:
389 raise error.CommandError(cmd, inst)
389 raise error.CommandError(cmd, inst)
390
390
391 # separate global options back out
391 # separate global options back out
392 for o in commands.globalopts:
392 for o in commands.globalopts:
393 n = o[1]
393 n = o[1]
394 options[n] = cmdoptions[n]
394 options[n] = cmdoptions[n]
395 del cmdoptions[n]
395 del cmdoptions[n]
396
396
397 return (cmd, cmd and entry[0] or None, args, options, cmdoptions)
397 return (cmd, cmd and entry[0] or None, args, options, cmdoptions)
398
398
399 def _parseconfig(ui, config):
399 def _parseconfig(ui, config):
400 """parse the --config options from the command line"""
400 """parse the --config options from the command line"""
401 for cfg in config:
401 for cfg in config:
402 try:
402 try:
403 name, value = cfg.split('=', 1)
403 name, value = cfg.split('=', 1)
404 section, name = name.split('.', 1)
404 section, name = name.split('.', 1)
405 if not section or not name:
405 if not section or not name:
406 raise IndexError
406 raise IndexError
407 ui.setconfig(section, name, value)
407 ui.setconfig(section, name, value)
408 except (IndexError, ValueError):
408 except (IndexError, ValueError):
409 raise util.Abort(_('malformed --config option: %r '
409 raise util.Abort(_('malformed --config option: %r '
410 '(use --config section.name=value)') % cfg)
410 '(use --config section.name=value)') % cfg)
411
411
412 def _earlygetopt(aliases, args):
412 def _earlygetopt(aliases, args):
413 """Return list of values for an option (or aliases).
413 """Return list of values for an option (or aliases).
414
414
415 The values are listed in the order they appear in args.
415 The values are listed in the order they appear in args.
416 The options and values are removed from args.
416 The options and values are removed from args.
417 """
417 """
418 try:
418 try:
419 argcount = args.index("--")
419 argcount = args.index("--")
420 except ValueError:
420 except ValueError:
421 argcount = len(args)
421 argcount = len(args)
422 shortopts = [opt for opt in aliases if len(opt) == 2]
422 shortopts = [opt for opt in aliases if len(opt) == 2]
423 values = []
423 values = []
424 pos = 0
424 pos = 0
425 while pos < argcount:
425 while pos < argcount:
426 if args[pos] in aliases:
426 if args[pos] in aliases:
427 if pos + 1 >= argcount:
427 if pos + 1 >= argcount:
428 # ignore and let getopt report an error if there is no value
428 # ignore and let getopt report an error if there is no value
429 break
429 break
430 del args[pos]
430 del args[pos]
431 values.append(args.pop(pos))
431 values.append(args.pop(pos))
432 argcount -= 2
432 argcount -= 2
433 elif args[pos][:2] in shortopts:
433 elif args[pos][:2] in shortopts:
434 # short option can have no following space, e.g. hg log -Rfoo
434 # short option can have no following space, e.g. hg log -Rfoo
435 values.append(args.pop(pos)[2:])
435 values.append(args.pop(pos)[2:])
436 argcount -= 1
436 argcount -= 1
437 else:
437 else:
438 pos += 1
438 pos += 1
439 return values
439 return values
440
440
441 def runcommand(lui, repo, cmd, fullargs, ui, options, d, cmdpats, cmdoptions):
441 def runcommand(lui, repo, cmd, fullargs, ui, options, d, cmdpats, cmdoptions):
442 # run pre-hook, and abort if it fails
442 # run pre-hook, and abort if it fails
443 ret = hook.hook(lui, repo, "pre-%s" % cmd, False, args=" ".join(fullargs),
443 ret = hook.hook(lui, repo, "pre-%s" % cmd, False, args=" ".join(fullargs),
444 pats=cmdpats, opts=cmdoptions)
444 pats=cmdpats, opts=cmdoptions)
445 if ret:
445 if ret:
446 return ret
446 return ret
447 ret = _runcommand(ui, options, cmd, d)
447 ret = _runcommand(ui, options, cmd, d)
448 # run post-hook, passing command result
448 # run post-hook, passing command result
449 hook.hook(lui, repo, "post-%s" % cmd, False, args=" ".join(fullargs),
449 hook.hook(lui, repo, "post-%s" % cmd, False, args=" ".join(fullargs),
450 result=ret, pats=cmdpats, opts=cmdoptions)
450 result=ret, pats=cmdpats, opts=cmdoptions)
451 return ret
451 return ret
452
452
453 def _getlocal(ui, rpath):
453 def _getlocal(ui, rpath):
454 """Return (path, local ui object) for the given target path.
454 """Return (path, local ui object) for the given target path.
455
455
456 Takes paths in [cwd]/.hg/hgrc into account."
456 Takes paths in [cwd]/.hg/hgrc into account."
457 """
457 """
458 try:
458 try:
459 wd = os.getcwd()
459 wd = os.getcwd()
460 except OSError, e:
460 except OSError, e:
461 raise util.Abort(_("error getting current working directory: %s") %
461 raise util.Abort(_("error getting current working directory: %s") %
462 e.strerror)
462 e.strerror)
463 path = cmdutil.findrepo(wd) or ""
463 path = cmdutil.findrepo(wd) or ""
464 if not path:
464 if not path:
465 lui = ui
465 lui = ui
466 else:
466 else:
467 lui = ui.copy()
467 lui = ui.copy()
468 lui.readconfig(os.path.join(path, ".hg", "hgrc"), path)
468 lui.readconfig(os.path.join(path, ".hg", "hgrc"), path)
469
469
470 if rpath:
470 if rpath:
471 path = lui.expandpath(rpath[-1])
471 path = lui.expandpath(rpath[-1])
472 lui = ui.copy()
472 lui = ui.copy()
473 lui.readconfig(os.path.join(path, ".hg", "hgrc"), path)
473 lui.readconfig(os.path.join(path, ".hg", "hgrc"), path)
474
474
475 return path, lui
475 return path, lui
476
476
477 def _checkshellalias(ui, args):
477 def _checkshellalias(ui, args):
478 cwd = os.getcwd()
478 cwd = os.getcwd()
479 norepo = commands.norepo
479 norepo = commands.norepo
480 options = {}
480 options = {}
481
481
482 try:
482 try:
483 args = fancyopts.fancyopts(args, commands.globalopts, options)
483 args = fancyopts.fancyopts(args, commands.globalopts, options)
484 except fancyopts.getopt.GetoptError:
484 except fancyopts.getopt.GetoptError:
485 return
485 return
486
486
487 if not args:
487 if not args:
488 return
488 return
489
489
490 _parseconfig(ui, options['config'])
490 _parseconfig(ui, options['config'])
491 if options['cwd']:
491 if options['cwd']:
492 os.chdir(options['cwd'])
492 os.chdir(options['cwd'])
493
493
494 path, lui = _getlocal(ui, [options['repository']])
494 path, lui = _getlocal(ui, [options['repository']])
495
495
496 cmdtable = commands.table.copy()
496 cmdtable = commands.table.copy()
497 addaliases(lui, cmdtable)
497 addaliases(lui, cmdtable)
498
498
499 cmd = args[0]
499 cmd = args[0]
500 try:
500 try:
501 aliases, entry = cmdutil.findcmd(cmd, cmdtable, lui.config("ui", "strict"))
501 aliases, entry = cmdutil.findcmd(cmd, cmdtable, lui.config("ui", "strict"))
502 except (error.AmbiguousCommand, error.UnknownCommand):
502 except (error.AmbiguousCommand, error.UnknownCommand):
503 commands.norepo = norepo
503 commands.norepo = norepo
504 os.chdir(cwd)
504 os.chdir(cwd)
505 return
505 return
506
506
507 cmd = aliases[0]
507 cmd = aliases[0]
508 fn = entry[0]
508 fn = entry[0]
509
509
510 if cmd and hasattr(fn, 'shell'):
510 if cmd and hasattr(fn, 'shell'):
511 d = lambda: fn(ui, *args[1:])
511 d = lambda: fn(ui, *args[1:])
512 return lambda: runcommand(lui, None, cmd, args[:1], ui, options, d, [], {})
512 return lambda: runcommand(lui, None, cmd, args[:1], ui, options, d, [], {})
513
513
514 commands.norepo = norepo
514 commands.norepo = norepo
515 os.chdir(cwd)
515 os.chdir(cwd)
516
516
517 _loaded = set()
517 _loaded = set()
518 def _dispatch(req):
518 def _dispatch(req):
519 args = req.args
519 args = req.args
520 ui = req.ui
520 ui = req.ui
521
521
522 shellaliasfn = _checkshellalias(ui, args)
522 shellaliasfn = _checkshellalias(ui, args)
523 if shellaliasfn:
523 if shellaliasfn:
524 return shellaliasfn()
524 return shellaliasfn()
525
525
526 # read --config before doing anything else
526 # read --config before doing anything else
527 # (e.g. to change trust settings for reading .hg/hgrc)
527 # (e.g. to change trust settings for reading .hg/hgrc)
528 _parseconfig(ui, _earlygetopt(['--config'], args))
528 _parseconfig(ui, _earlygetopt(['--config'], args))
529
529
530 # check for cwd
530 # check for cwd
531 cwd = _earlygetopt(['--cwd'], args)
531 cwd = _earlygetopt(['--cwd'], args)
532 if cwd:
532 if cwd:
533 os.chdir(cwd[-1])
533 os.chdir(cwd[-1])
534
534
535 rpath = _earlygetopt(["-R", "--repository", "--repo"], args)
535 rpath = _earlygetopt(["-R", "--repository", "--repo"], args)
536 path, lui = _getlocal(ui, rpath)
536 path, lui = _getlocal(ui, rpath)
537
537
538 # Configure extensions in phases: uisetup, extsetup, cmdtable, and
538 # Configure extensions in phases: uisetup, extsetup, cmdtable, and
539 # reposetup. Programs like TortoiseHg will call _dispatch several
539 # reposetup. Programs like TortoiseHg will call _dispatch several
540 # times so we keep track of configured extensions in _loaded.
540 # times so we keep track of configured extensions in _loaded.
541 extensions.loadall(lui)
541 extensions.loadall(lui)
542 exts = [ext for ext in extensions.extensions() if ext[0] not in _loaded]
542 exts = [ext for ext in extensions.extensions() if ext[0] not in _loaded]
543 # Propagate any changes to lui.__class__ by extensions
543 # Propagate any changes to lui.__class__ by extensions
544 ui.__class__ = lui.__class__
544 ui.__class__ = lui.__class__
545
545
546 # (uisetup and extsetup are handled in extensions.loadall)
546 # (uisetup and extsetup are handled in extensions.loadall)
547
547
548 for name, module in exts:
548 for name, module in exts:
549 cmdtable = getattr(module, 'cmdtable', {})
549 cmdtable = getattr(module, 'cmdtable', {})
550 overrides = [cmd for cmd in cmdtable if cmd in commands.table]
550 overrides = [cmd for cmd in cmdtable if cmd in commands.table]
551 if overrides:
551 if overrides:
552 ui.warn(_("extension '%s' overrides commands: %s\n")
552 ui.warn(_("extension '%s' overrides commands: %s\n")
553 % (name, " ".join(overrides)))
553 % (name, " ".join(overrides)))
554 commands.table.update(cmdtable)
554 commands.table.update(cmdtable)
555 _loaded.add(name)
555 _loaded.add(name)
556
556
557 # (reposetup is handled in hg.repository)
557 # (reposetup is handled in hg.repository)
558
558
559 addaliases(lui, commands.table)
559 addaliases(lui, commands.table)
560
560
561 # check for fallback encoding
561 # check for fallback encoding
562 fallback = lui.config('ui', 'fallbackencoding')
562 fallback = lui.config('ui', 'fallbackencoding')
563 if fallback:
563 if fallback:
564 encoding.fallbackencoding = fallback
564 encoding.fallbackencoding = fallback
565
565
566 fullargs = args
566 fullargs = args
567 cmd, func, args, options, cmdoptions = _parse(lui, args)
567 cmd, func, args, options, cmdoptions = _parse(lui, args)
568
568
569 if options["config"]:
569 if options["config"]:
570 raise util.Abort(_("option --config may not be abbreviated!"))
570 raise util.Abort(_("option --config may not be abbreviated!"))
571 if options["cwd"]:
571 if options["cwd"]:
572 raise util.Abort(_("option --cwd may not be abbreviated!"))
572 raise util.Abort(_("option --cwd may not be abbreviated!"))
573 if options["repository"]:
573 if options["repository"]:
574 raise util.Abort(_(
574 raise util.Abort(_(
575 "Option -R has to be separated from other options (e.g. not -qR) "
575 "Option -R has to be separated from other options (e.g. not -qR) "
576 "and --repository may only be abbreviated as --repo!"))
576 "and --repository may only be abbreviated as --repo!"))
577
577
578 if options["encoding"]:
578 if options["encoding"]:
579 encoding.encoding = options["encoding"]
579 encoding.encoding = options["encoding"]
580 if options["encodingmode"]:
580 if options["encodingmode"]:
581 encoding.encodingmode = options["encodingmode"]
581 encoding.encodingmode = options["encodingmode"]
582 if options["time"]:
582 if options["time"]:
583 def get_times():
583 def get_times():
584 t = os.times()
584 t = os.times()
585 if t[4] == 0.0: # Windows leaves this as zero, so use time.clock()
585 if t[4] == 0.0: # Windows leaves this as zero, so use time.clock()
586 t = (t[0], t[1], t[2], t[3], time.clock())
586 t = (t[0], t[1], t[2], t[3], time.clock())
587 return t
587 return t
588 s = get_times()
588 s = get_times()
589 def print_time():
589 def print_time():
590 t = get_times()
590 t = get_times()
591 ui.warn(_("Time: real %.3f secs (user %.3f+%.3f sys %.3f+%.3f)\n") %
591 ui.warn(_("Time: real %.3f secs (user %.3f+%.3f sys %.3f+%.3f)\n") %
592 (t[4]-s[4], t[0]-s[0], t[2]-s[2], t[1]-s[1], t[3]-s[3]))
592 (t[4]-s[4], t[0]-s[0], t[2]-s[2], t[1]-s[1], t[3]-s[3]))
593 atexit.register(print_time)
593 atexit.register(print_time)
594
594
595 if options['verbose'] or options['debug'] or options['quiet']:
595 if options['verbose'] or options['debug'] or options['quiet']:
596 for ui in (ui, lui):
596 for ui_ in (ui, lui):
597 ui.setconfig('ui', 'verbose', str(bool(options['verbose'])))
597 ui_.setconfig('ui', 'verbose', str(bool(options['verbose'])))
598 ui.setconfig('ui', 'debug', str(bool(options['debug'])))
598 ui_.setconfig('ui', 'debug', str(bool(options['debug'])))
599 ui.setconfig('ui', 'quiet', str(bool(options['quiet'])))
599 ui_.setconfig('ui', 'quiet', str(bool(options['quiet'])))
600 if options['traceback']:
600 if options['traceback']:
601 for ui in (ui, lui):
601 for ui_ in (ui, lui):
602 ui.setconfig('ui', 'traceback', 'on')
602 ui_.setconfig('ui', 'traceback', 'on')
603 if options['noninteractive']:
603 if options['noninteractive']:
604 for ui in (ui, lui):
604 for ui_ in (ui, lui):
605 ui.setconfig('ui', 'interactive', 'off')
605 ui_.setconfig('ui', 'interactive', 'off')
606
606
607 if cmdoptions.get('insecure', False):
607 if cmdoptions.get('insecure', False):
608 for ui in (ui, lui):
608 for ui_ in (ui, lui):
609 ui.setconfig('web', 'cacerts', '')
609 ui_.setconfig('web', 'cacerts', '')
610
610
611 if options['help']:
611 if options['help']:
612 return commands.help_(ui, cmd, options['version'])
612 return commands.help_(ui, cmd, options['version'])
613 elif options['version']:
613 elif options['version']:
614 return commands.version_(ui)
614 return commands.version_(ui)
615 elif not cmd:
615 elif not cmd:
616 return commands.help_(ui, 'shortlist')
616 return commands.help_(ui, 'shortlist')
617
617
618 repo = None
618 repo = None
619 cmdpats = args[:]
619 cmdpats = args[:]
620 if cmd not in commands.norepo.split():
620 if cmd not in commands.norepo.split():
621 # use the repo from the request only if we don't have -R
621 # use the repo from the request only if we don't have -R
622 if not rpath:
622 if not rpath:
623 repo = req.repo
623 repo = req.repo
624
624
625 if not repo:
625 if not repo:
626 try:
626 try:
627 repo = hg.repository(ui, path=path)
627 repo = hg.repository(ui, path=path)
628 ui = repo.ui
628 ui = repo.ui
629 if not repo.local():
629 if not repo.local():
630 raise util.Abort(_("repository '%s' is not local") % path)
630 raise util.Abort(_("repository '%s' is not local") % path)
631 ui.setconfig("bundle", "mainreporoot", repo.root)
631 ui.setconfig("bundle", "mainreporoot", repo.root)
632 except error.RequirementError:
632 except error.RequirementError:
633 raise
633 raise
634 except error.RepoError:
634 except error.RepoError:
635 if cmd not in commands.optionalrepo.split():
635 if cmd not in commands.optionalrepo.split():
636 if args and not path: # try to infer -R from command args
636 if args and not path: # try to infer -R from command args
637 repos = map(cmdutil.findrepo, args)
637 repos = map(cmdutil.findrepo, args)
638 guess = repos[0]
638 guess = repos[0]
639 if guess and repos.count(guess) == len(repos):
639 if guess and repos.count(guess) == len(repos):
640 req.args = ['--repository', guess] + fullargs
640 req.args = ['--repository', guess] + fullargs
641 return _dispatch(req)
641 return _dispatch(req)
642 if not path:
642 if not path:
643 raise error.RepoError(_("no repository found in %r"
643 raise error.RepoError(_("no repository found in %r"
644 " (.hg not found)") % os.getcwd())
644 " (.hg not found)") % os.getcwd())
645 raise
645 raise
646 args.insert(0, repo)
646 args.insert(0, repo)
647 elif rpath:
647 elif rpath:
648 ui.warn(_("warning: --repository ignored\n"))
648 ui.warn(_("warning: --repository ignored\n"))
649
649
650 msg = ' '.join(' ' in a and repr(a) or a for a in fullargs)
650 msg = ' '.join(' ' in a and repr(a) or a for a in fullargs)
651 ui.log("command", msg + "\n")
651 ui.log("command", msg + "\n")
652 d = lambda: util.checksignature(func)(ui, *args, **cmdoptions)
652 d = lambda: util.checksignature(func)(ui, *args, **cmdoptions)
653 try:
653 try:
654 return runcommand(lui, repo, cmd, fullargs, ui, options, d,
654 return runcommand(lui, repo, cmd, fullargs, ui, options, d,
655 cmdpats, cmdoptions)
655 cmdpats, cmdoptions)
656 finally:
656 finally:
657 if repo:
657 if repo:
658 repo.close()
658 repo.close()
659
659
660 def _runcommand(ui, options, cmd, cmdfunc):
660 def _runcommand(ui, options, cmd, cmdfunc):
661 def checkargs():
661 def checkargs():
662 try:
662 try:
663 return cmdfunc()
663 return cmdfunc()
664 except error.SignatureError:
664 except error.SignatureError:
665 raise error.CommandError(cmd, _("invalid arguments"))
665 raise error.CommandError(cmd, _("invalid arguments"))
666
666
667 if options['profile']:
667 if options['profile']:
668 format = ui.config('profiling', 'format', default='text')
668 format = ui.config('profiling', 'format', default='text')
669
669
670 if not format in ['text', 'kcachegrind']:
670 if not format in ['text', 'kcachegrind']:
671 ui.warn(_("unrecognized profiling format '%s'"
671 ui.warn(_("unrecognized profiling format '%s'"
672 " - Ignored\n") % format)
672 " - Ignored\n") % format)
673 format = 'text'
673 format = 'text'
674
674
675 output = ui.config('profiling', 'output')
675 output = ui.config('profiling', 'output')
676
676
677 if output:
677 if output:
678 path = ui.expandpath(output)
678 path = ui.expandpath(output)
679 ostream = open(path, 'wb')
679 ostream = open(path, 'wb')
680 else:
680 else:
681 ostream = sys.stderr
681 ostream = sys.stderr
682
682
683 try:
683 try:
684 from mercurial import lsprof
684 from mercurial import lsprof
685 except ImportError:
685 except ImportError:
686 raise util.Abort(_(
686 raise util.Abort(_(
687 'lsprof not available - install from '
687 'lsprof not available - install from '
688 'http://codespeak.net/svn/user/arigo/hack/misc/lsprof/'))
688 'http://codespeak.net/svn/user/arigo/hack/misc/lsprof/'))
689 p = lsprof.Profiler()
689 p = lsprof.Profiler()
690 p.enable(subcalls=True)
690 p.enable(subcalls=True)
691 try:
691 try:
692 return checkargs()
692 return checkargs()
693 finally:
693 finally:
694 p.disable()
694 p.disable()
695
695
696 if format == 'kcachegrind':
696 if format == 'kcachegrind':
697 import lsprofcalltree
697 import lsprofcalltree
698 calltree = lsprofcalltree.KCacheGrind(p)
698 calltree = lsprofcalltree.KCacheGrind(p)
699 calltree.output(ostream)
699 calltree.output(ostream)
700 else:
700 else:
701 # format == 'text'
701 # format == 'text'
702 stats = lsprof.Stats(p.getstats())
702 stats = lsprof.Stats(p.getstats())
703 stats.sort()
703 stats.sort()
704 stats.pprint(top=10, file=ostream, climit=5)
704 stats.pprint(top=10, file=ostream, climit=5)
705
705
706 if output:
706 if output:
707 ostream.close()
707 ostream.close()
708 else:
708 else:
709 return checkargs()
709 return checkargs()
General Comments 0
You need to be logged in to leave comments. Login now