##// END OF EJS Templates
Allow explicit disabling of extensions...
Steve Borho -
r5469:b12432b1 default
parent child Browse files
Show More
@@ -1,83 +1,85 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 util, sys
10 10 from i18n import _
11 11
12 12 _extensions = {}
13 13 _order = []
14 14
15 15 def extensions():
16 16 for name in _order:
17 17 module = _extensions[name]
18 18 if module:
19 19 yield name, module
20 20
21 21 def find(name):
22 22 '''return module with given extension name'''
23 23 try:
24 24 return _extensions[name]
25 25 except KeyError:
26 26 for k, v in _extensions.iteritems():
27 27 if k.endswith('.' + name) or k.endswith('/' + name):
28 28 return v
29 29 raise KeyError(name)
30 30
31 31 def load(ui, name, path):
32 32 if name.startswith('hgext.'):
33 33 shortname = name[6:]
34 34 else:
35 35 shortname = name
36 36 if shortname in _extensions:
37 37 return
38 38 _extensions[shortname] = None
39 39 if path:
40 40 # the module will be loaded in sys.modules
41 41 # choose an unique name so that it doesn't
42 42 # conflicts with other modules
43 43 module_name = "hgext_%s" % name.replace('.', '_')
44 44 if os.path.isdir(path):
45 45 # module/__init__.py style
46 46 d, f = os.path.split(path)
47 47 fd, fpath, desc = imp.find_module(f, [d])
48 48 mod = imp.load_module(module_name, fd, fpath, desc)
49 49 else:
50 50 mod = imp.load_source(module_name, path)
51 51 else:
52 52 def importh(name):
53 53 mod = __import__(name)
54 54 components = name.split('.')
55 55 for comp in components[1:]:
56 56 mod = getattr(mod, comp)
57 57 return mod
58 58 try:
59 59 mod = importh("hgext.%s" % name)
60 60 except ImportError:
61 61 mod = importh(name)
62 62 _extensions[shortname] = mod
63 63 _order.append(shortname)
64 64
65 65 uisetup = getattr(mod, 'uisetup', None)
66 66 if uisetup:
67 67 uisetup(ui)
68 68
69 69 def loadall(ui):
70 70 result = ui.configitems("extensions")
71 71 for i, (name, path) in enumerate(result):
72 72 if path:
73 if path[0] == '!':
74 continue
73 75 path = os.path.expanduser(path)
74 76 try:
75 77 load(ui, name, path)
76 78 except (util.SignalInterrupt, KeyboardInterrupt):
77 79 raise
78 80 except Exception, inst:
79 81 ui.warn(_("*** failed to import extension %s: %s\n") %
80 82 (name, inst))
81 83 if ui.print_exc():
82 84 return 1
83 85
General Comments 0
You need to be logged in to leave comments. Login now