mercurial/commands.py
changeset 2943 8e59010158ce
parent 2842 7706fa503677
child 2944 2efa9b8aed30
equal deleted inserted replaced
2842:7706fa503677 2943:8e59010158ce
  3447         for k, v in external.iteritems():
  3447         for k, v in external.iteritems():
  3448             if k.endswith('.' + name) or k.endswith('/' + name) or v == name:
  3448             if k.endswith('.' + name) or k.endswith('/' + name) or v == name:
  3449                 return sys.modules[v]
  3449                 return sys.modules[v]
  3450         raise KeyError(name)
  3450         raise KeyError(name)
  3451 
  3451 
  3452 def dispatch(args):
  3452 def load_extensions(ui, extensions):
  3453     for name in 'SIGBREAK', 'SIGHUP', 'SIGTERM':
  3453     for ext_name, load_from_name in extensions:
  3454         num = getattr(signal, name, None)
       
  3455         if num: signal.signal(num, catchterm)
       
  3456 
       
  3457     try:
       
  3458         u = ui.ui(traceback='--traceback' in sys.argv[1:])
       
  3459     except util.Abort, inst:
       
  3460         sys.stderr.write(_("abort: %s\n") % inst)
       
  3461         return -1
       
  3462 
       
  3463     for ext_name, load_from_name in u.extensions():
       
  3464         try:
  3454         try:
  3465             if load_from_name:
  3455             if load_from_name:
  3466                 # the module will be loaded in sys.modules
  3456                 # the module will be loaded in sys.modules
  3467                 # choose an unique name so that it doesn't
  3457                 # choose an unique name so that it doesn't
  3468                 # conflicts with other modules
  3458                 # conflicts with other modules
  3481                     mod = importh(ext_name)
  3471                     mod = importh(ext_name)
  3482             external[ext_name] = mod.__name__
  3472             external[ext_name] = mod.__name__
  3483         except (util.SignalInterrupt, KeyboardInterrupt):
  3473         except (util.SignalInterrupt, KeyboardInterrupt):
  3484             raise
  3474             raise
  3485         except Exception, inst:
  3475         except Exception, inst:
  3486             u.warn(_("*** failed to import extension %s: %s\n") % (ext_name, inst))
  3476             ui.warn(_("*** failed to import extension %s: %s\n") %
  3487             if u.print_exc():
  3477                     (ext_name, inst))
       
  3478             if ui.print_exc():
  3488                 return 1
  3479                 return 1
  3489 
  3480 
  3490     for name in external.itervalues():
  3481     for name in external.itervalues():
  3491         mod = sys.modules[name]
  3482         mod = sys.modules[name]
  3492         uisetup = getattr(mod, 'uisetup', None)
  3483         uisetup = getattr(mod, 'uisetup', None)
  3493         if uisetup:
  3484         if uisetup:
  3494             uisetup(u)
  3485             uisetup(u)
  3495         cmdtable = getattr(mod, 'cmdtable', {})
  3486         cmdtable = getattr(mod, 'cmdtable', {})
  3496         for t in cmdtable:
  3487         for t in cmdtable:
  3497             if t in table:
  3488             if t in table:
  3498                 u.warn(_("module %s overrides %s\n") % (name, t))
  3489                 ui.warn(_("module %s overrides %s\n") % (name, t))
  3499         table.update(cmdtable)
  3490         table.update(cmdtable)
       
  3491     
       
  3492 def dispatch(args):
       
  3493     for name in 'SIGBREAK', 'SIGHUP', 'SIGTERM':
       
  3494         num = getattr(signal, name, None)
       
  3495         if num: signal.signal(num, catchterm)
       
  3496 
       
  3497     try:
       
  3498         u = ui.ui(traceback='--traceback' in sys.argv[1:])
       
  3499     except util.Abort, inst:
       
  3500         sys.stderr.write(_("abort: %s\n") % inst)
       
  3501         return -1
       
  3502 
       
  3503     load_extensions(u, u.extensions())
  3500 
  3504 
  3501     try:
  3505     try:
  3502         cmd, func, args, options, cmdoptions = parse(u, args)
  3506         cmd, func, args, options, cmdoptions = parse(u, args)
  3503         if options["time"]:
  3507         if options["time"]:
  3504             def get_times():
  3508             def get_times():