comparison mercurial/dispatch.py @ 7388:5751631246de

dispatch: generalize signature checking for extension command wrapping
author Matt Mackall <mpm@selenic.com>
date Tue, 18 Nov 2008 16:02:14 -0600
parents 810ca383da9c
children b2cbced7bb50
comparison
equal deleted inserted replaced
7387:7e9a15fa6c8f 7388:5751631246de
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 from repo import RepoError 9 from repo import RepoError
10 import os, sys, atexit, signal, pdb, traceback, socket, errno, shlex, time 10 import os, sys, atexit, signal, pdb, socket, errno, shlex, time
11 import util, commands, hg, lock, fancyopts, revlog, version, extensions, hook 11 import util, commands, hg, lock, fancyopts, revlog, version, extensions, hook
12 import cmdutil 12 import cmdutil
13 import ui as _ui 13 import ui as _ui
14 14
15 class ParseError(Exception): 15 class ParseError(Exception):
354 return _dispatch(ui, ['--repository', guess] + fullargs) 354 return _dispatch(ui, ['--repository', guess] + fullargs)
355 if not path: 355 if not path:
356 raise RepoError(_("There is no Mercurial repository here" 356 raise RepoError(_("There is no Mercurial repository here"
357 " (.hg not found)")) 357 " (.hg not found)"))
358 raise 358 raise
359 d = lambda: func(ui, repo, *args, **cmdoptions) 359 args.insert(0, repo)
360 else: 360
361 d = lambda: func(ui, *args, **cmdoptions) 361 d = lambda: util.checksignature(func)(ui, *args, **cmdoptions)
362 362
363 # run pre-hook, and abort if it fails 363 # run pre-hook, and abort if it fails
364 ret = hook.hook(lui, repo, "pre-%s" % cmd, False, args=" ".join(fullargs)) 364 ret = hook.hook(lui, repo, "pre-%s" % cmd, False, args=" ".join(fullargs))
365 if ret: 365 if ret:
366 return ret 366 return ret
372 372
373 def _runcommand(ui, options, cmd, cmdfunc): 373 def _runcommand(ui, options, cmd, cmdfunc):
374 def checkargs(): 374 def checkargs():
375 try: 375 try:
376 return cmdfunc() 376 return cmdfunc()
377 except TypeError: 377 except util.SignatureError:
378 # was this an argument error?
379 tb = traceback.extract_tb(sys.exc_info()[2])
380 if len(tb) != 2: # no
381 raise
382 raise ParseError(cmd, _("invalid arguments")) 378 raise ParseError(cmd, _("invalid arguments"))
383 379
384 if options['profile']: 380 if options['profile']:
385 import hotshot, hotshot.stats 381 import hotshot, hotshot.stats
386 prof = hotshot.Profile("hg.prof") 382 prof = hotshot.Profile("hg.prof")