Show More
@@ -0,0 +1,69 b'' | |||||
|
1 | # extensions.py - extension handling for mercurial | |||
|
2 | # | |||
|
3 | # Copyright 2005, 2006 Matt Mackall <mpm@selenic.com> | |||
|
4 | # | |||
|
5 | # This software may be used and distributed according to the terms | |||
|
6 | # of the GNU General Public License, incorporated herein by reference. | |||
|
7 | ||||
|
8 | import imp, commands, hg, util | |||
|
9 | from i18n import _ | |||
|
10 | ||||
|
11 | _extensions = {} | |||
|
12 | ||||
|
13 | def find(name): | |||
|
14 | '''return module with given extension name''' | |||
|
15 | try: | |||
|
16 | return _extensions[name] | |||
|
17 | except KeyError: | |||
|
18 | for k, v in _extensions.iteritems(): | |||
|
19 | if k.endswith('.' + name) or k.endswith('/' + name) or v == name: | |||
|
20 | return sys.modules[v] | |||
|
21 | raise KeyError(name) | |||
|
22 | ||||
|
23 | def load(ui, name, path): | |||
|
24 | if name in _extensions: | |||
|
25 | return | |||
|
26 | if path: | |||
|
27 | # the module will be loaded in sys.modules | |||
|
28 | # choose an unique name so that it doesn't | |||
|
29 | # conflicts with other modules | |||
|
30 | module_name = "hgext_%s" % name.replace('.', '_') | |||
|
31 | mod = imp.load_source(module_name, path) | |||
|
32 | else: | |||
|
33 | def importh(name): | |||
|
34 | mod = __import__(name) | |||
|
35 | components = name.split('.') | |||
|
36 | for comp in components[1:]: | |||
|
37 | mod = getattr(mod, comp) | |||
|
38 | return mod | |||
|
39 | try: | |||
|
40 | mod = importh("hgext.%s" % name) | |||
|
41 | except ImportError: | |||
|
42 | mod = importh(name) | |||
|
43 | _extensions[name] = mod | |||
|
44 | ||||
|
45 | uisetup = getattr(mod, 'uisetup', None) | |||
|
46 | if uisetup: | |||
|
47 | uisetup(ui) | |||
|
48 | reposetup = getattr(mod, 'reposetup', None) | |||
|
49 | if reposetup: | |||
|
50 | hg.repo_setup_hooks.append(reposetup) | |||
|
51 | cmdtable = getattr(mod, 'cmdtable', {}) | |||
|
52 | overrides = [cmd for cmd in cmdtable if cmd in commands.table] | |||
|
53 | if overrides: | |||
|
54 | ui.warn(_("extension '%s' overrides commands: %s\n") | |||
|
55 | % (name, " ".join(overrides))) | |||
|
56 | commands.table.update(cmdtable) | |||
|
57 | ||||
|
58 | def loadall(ui): | |||
|
59 | for name, path in ui.extensions(): | |||
|
60 | try: | |||
|
61 | load(ui, name, path) | |||
|
62 | except (util.SignalInterrupt, KeyboardInterrupt): | |||
|
63 | raise | |||
|
64 | except Exception, inst: | |||
|
65 | ui.warn(_("*** failed to import extension %s: %s\n") % | |||
|
66 | (name, inst)) | |||
|
67 | if ui.print_exc(): | |||
|
68 | return 1 | |||
|
69 |
@@ -8,8 +8,8 b'' | |||||
8 | import demandimport; demandimport.enable() |
|
8 | import demandimport; demandimport.enable() | |
9 | from node import * |
|
9 | from node import * | |
10 | from i18n import _ |
|
10 | from i18n import _ | |
11 |
import bisect, os, re, sys, signal, |
|
11 | import bisect, os, re, sys, signal, urllib, pdb, shlex, stat | |
12 | import fancyopts, ui, hg, util, lock, revlog, bundlerepo |
|
12 | import fancyopts, ui, hg, util, lock, revlog, bundlerepo, extensions | |
13 | import difflib, patch, time, help, mdiff, tempfile |
|
13 | import difflib, patch, time, help, mdiff, tempfile | |
14 | import traceback, errno, version, atexit, socket |
|
14 | import traceback, errno, version, atexit, socket | |
15 | import archival, changegroup, cmdutil, hgweb.server, sshserver |
|
15 | import archival, changegroup, cmdutil, hgweb.server, sshserver | |
@@ -1371,7 +1371,7 b' def help_(ui, name=None, with_version=Fa' | |||||
1371 |
|
1371 | |||
1372 | def helpext(name): |
|
1372 | def helpext(name): | |
1373 | try: |
|
1373 | try: | |
1374 |
mod = find |
|
1374 | mod = extensions.find(name) | |
1375 | except KeyError: |
|
1375 | except KeyError: | |
1376 | raise UnknownCommand(name) |
|
1376 | raise UnknownCommand(name) | |
1377 |
|
1377 | |||
@@ -3137,65 +3137,6 b' def parseconfig(config):' | |||||
3137 | raise util.Abort(_('malformed --config option: %s') % cfg) |
|
3137 | raise util.Abort(_('malformed --config option: %s') % cfg) | |
3138 | return parsed |
|
3138 | return parsed | |
3139 |
|
3139 | |||
3140 | external = {} |
|
|||
3141 |
|
||||
3142 | def findext(name): |
|
|||
3143 | '''return module with given extension name''' |
|
|||
3144 | try: |
|
|||
3145 | return sys.modules[external[name]] |
|
|||
3146 | except KeyError: |
|
|||
3147 | for k, v in external.iteritems(): |
|
|||
3148 | if k.endswith('.' + name) or k.endswith('/' + name) or v == name: |
|
|||
3149 | return sys.modules[v] |
|
|||
3150 | raise KeyError(name) |
|
|||
3151 |
|
||||
3152 | def load_extension(ui, name, load): |
|
|||
3153 | if name in external: |
|
|||
3154 | return |
|
|||
3155 | if load: |
|
|||
3156 | # the module will be loaded in sys.modules |
|
|||
3157 | # choose an unique name so that it doesn't |
|
|||
3158 | # conflicts with other modules |
|
|||
3159 | module_name = "hgext_%s" % name.replace('.', '_') |
|
|||
3160 | mod = imp.load_source(module_name, load) |
|
|||
3161 | else: |
|
|||
3162 | def importh(name): |
|
|||
3163 | mod = __import__(name) |
|
|||
3164 | components = name.split('.') |
|
|||
3165 | for comp in components[1:]: |
|
|||
3166 | mod = getattr(mod, comp) |
|
|||
3167 | return mod |
|
|||
3168 | try: |
|
|||
3169 | mod = importh("hgext.%s" % name) |
|
|||
3170 | except ImportError: |
|
|||
3171 | mod = importh(name) |
|
|||
3172 | external[name] = mod.__name__ |
|
|||
3173 |
|
||||
3174 | uisetup = getattr(mod, 'uisetup', None) |
|
|||
3175 | if uisetup: |
|
|||
3176 | uisetup(ui) |
|
|||
3177 | reposetup = getattr(mod, 'reposetup', None) |
|
|||
3178 | if reposetup: |
|
|||
3179 | hg.repo_setup_hooks.append(reposetup) |
|
|||
3180 | cmdtable = getattr(mod, 'cmdtable', {}) |
|
|||
3181 | overrides = [cmd for cmd in cmdtable if cmd in table] |
|
|||
3182 | if overrides: |
|
|||
3183 | ui.warn(_("extension '%s' overrides commands: %s\n") |
|
|||
3184 | % (name, " ".join(overrides))) |
|
|||
3185 | table.update(cmdtable) |
|
|||
3186 |
|
||||
3187 | def load_extensions(ui): |
|
|||
3188 | for name, load in ui.extensions(): |
|
|||
3189 | try: |
|
|||
3190 | load_extension(ui, name, load) |
|
|||
3191 | except (util.SignalInterrupt, KeyboardInterrupt): |
|
|||
3192 | raise |
|
|||
3193 | except Exception, inst: |
|
|||
3194 | ui.warn(_("*** failed to import extension %s: %s\n") % |
|
|||
3195 | (name, inst)) |
|
|||
3196 | if ui.print_exc(): |
|
|||
3197 | return 1 |
|
|||
3198 |
|
||||
3199 | def catchterm(*args): |
|
3140 | def catchterm(*args): | |
3200 | raise util.SignalInterrupt |
|
3141 | raise util.SignalInterrupt | |
3201 |
|
3142 | |||
@@ -3210,8 +3151,8 b' def dispatch(args):' | |||||
3210 | sys.stderr.write(_("abort: %s\n") % inst) |
|
3151 | sys.stderr.write(_("abort: %s\n") % inst) | |
3211 | return -1 |
|
3152 | return -1 | |
3212 |
|
3153 | |||
3213 |
|
|
3154 | extensions.loadall(u) | |
3214 |
u.addreadhook( |
|
3155 | u.addreadhook(extensions.loadall) | |
3215 |
|
3156 | |||
3216 | try: |
|
3157 | try: | |
3217 | cmd, func, args, options, cmdoptions = parse(u, args) |
|
3158 | cmd, func, args, options, cmdoptions = parse(u, args) |
General Comments 0
You need to be logged in to leave comments.
Login now