##// END OF EJS Templates
fix up previous commit for stable
Brendan Cully -
r5088:1fd3248b default
parent child Browse files
Show More
@@ -1,80 +1,80 b''
1 1 # extensions.py - extension handling for mercurial
2 2 #
3 3 # Copyright 2005-2007 Matt Mackall <mpm@selenic.com>
4 4 #
5 5 # This software may be used and distributed according to the terms
6 6 # of the GNU General Public License, incorporated herein by reference.
7 7
8 8 import imp, os
9 9 import commands, hg, util, sys
10 10 from i18n import _
11 11
12 12 _extensions = {}
13 13
14 14 def find(name):
15 15 '''return module with given extension name'''
16 16 try:
17 17 return _extensions[name]
18 18 except KeyError:
19 19 for k, v in _extensions.iteritems():
20 20 if k.endswith('.' + name) or k.endswith('/' + name):
21 21 return v
22 22 raise KeyError(name)
23 23
24 24 def load(ui, name, path):
25 25 if name in _extensions:
26 26 return
27 _extensions[shortname] = None
27 _extensions[name] = None
28 28 if path:
29 29 # the module will be loaded in sys.modules
30 30 # choose an unique name so that it doesn't
31 31 # conflicts with other modules
32 32 module_name = "hgext_%s" % name.replace('.', '_')
33 33 if os.path.isdir(path):
34 34 # module/__init__.py style
35 35 d, f = os.path.split(path)
36 36 fd, fpath, desc = imp.find_module(f, [d])
37 37 mod = imp.load_module(module_name, fd, fpath, desc)
38 38 else:
39 39 mod = imp.load_source(module_name, path)
40 40 else:
41 41 def importh(name):
42 42 mod = __import__(name)
43 43 components = name.split('.')
44 44 for comp in components[1:]:
45 45 mod = getattr(mod, comp)
46 46 return mod
47 47 try:
48 48 mod = importh("hgext.%s" % name)
49 49 except ImportError:
50 50 mod = importh(name)
51 51 _extensions[name] = mod
52 52
53 53 uisetup = getattr(mod, 'uisetup', None)
54 54 if uisetup:
55 55 uisetup(ui)
56 56 reposetup = getattr(mod, 'reposetup', None)
57 57 if reposetup:
58 58 hg.repo_setup_hooks.append(reposetup)
59 59 cmdtable = getattr(mod, 'cmdtable', {})
60 60 overrides = [cmd for cmd in cmdtable if cmd in commands.table]
61 61 if overrides:
62 62 ui.warn(_("extension '%s' overrides commands: %s\n")
63 63 % (name, " ".join(overrides)))
64 64 commands.table.update(cmdtable)
65 65
66 66 def loadall(ui):
67 67 result = ui.configitems("extensions")
68 68 for i, (name, path) in enumerate(result):
69 69 if path:
70 70 path = os.path.expanduser(path)
71 71 try:
72 72 load(ui, name, path)
73 73 except (util.SignalInterrupt, KeyboardInterrupt):
74 74 raise
75 75 except Exception, inst:
76 76 ui.warn(_("*** failed to import extension %s: %s\n") %
77 77 (name, inst))
78 78 if ui.print_exc():
79 79 return 1
80 80
General Comments 0
You need to be logged in to leave comments. Login now