Show More
@@ -3242,18 +3242,11 b' def findext(name):' | |||||
3242 | return sys.modules[v] |
|
3242 | return sys.modules[v] | |
3243 | raise KeyError(name) |
|
3243 | raise KeyError(name) | |
3244 |
|
3244 | |||
3245 | def dispatch(args): |
|
3245 | def load_extensions(ui): | |
3246 | for name in 'SIGBREAK', 'SIGHUP', 'SIGTERM': |
|
3246 | added = [] | |
3247 | num = getattr(signal, name, None) |
|
3247 | for ext_name, load_from_name in ui.extensions(): | |
3248 | if num: signal.signal(num, catchterm) |
|
3248 | if ext_name in external: | |
3249 |
|
3249 | continue | ||
3250 | try: |
|
|||
3251 | u = ui.ui(traceback='--traceback' in sys.argv[1:]) |
|
|||
3252 | except util.Abort, inst: |
|
|||
3253 | sys.stderr.write(_("abort: %s\n") % inst) |
|
|||
3254 | return -1 |
|
|||
3255 |
|
||||
3256 | for ext_name, load_from_name in u.extensions(): |
|
|||
3257 | try: |
|
3250 | try: | |
3258 | if load_from_name: |
|
3251 | if load_from_name: | |
3259 | # the module will be loaded in sys.modules |
|
3252 | # the module will be loaded in sys.modules | |
@@ -3273,23 +3266,36 b' def dispatch(args):' | |||||
3273 | except ImportError: |
|
3266 | except ImportError: | |
3274 | mod = importh(ext_name) |
|
3267 | mod = importh(ext_name) | |
3275 | external[ext_name] = mod.__name__ |
|
3268 | external[ext_name] = mod.__name__ | |
|
3269 | added.append((mod, ext_name)) | |||
3276 | except (util.SignalInterrupt, KeyboardInterrupt): |
|
3270 | except (util.SignalInterrupt, KeyboardInterrupt): | |
3277 | raise |
|
3271 | raise | |
3278 | except Exception, inst: |
|
3272 | except Exception, inst: | |
3279 |
u.warn(_("*** failed to import extension %s: %s\n") % |
|
3273 | ui.warn(_("*** failed to import extension %s: %s\n") % | |
3280 | if u.print_exc(): |
|
3274 | (ext_name, inst)) | |
|
3275 | if ui.print_exc(): | |||
3281 | return 1 |
|
3276 | return 1 | |
3282 |
|
3277 | |||
3283 | for name in external.itervalues(): |
|
3278 | for mod, name in added: | |
3284 | mod = sys.modules[name] |
|
|||
3285 | uisetup = getattr(mod, 'uisetup', None) |
|
3279 | uisetup = getattr(mod, 'uisetup', None) | |
3286 | if uisetup: |
|
3280 | if uisetup: | |
3287 | uisetup(u) |
|
3281 | uisetup(ui) | |
3288 | cmdtable = getattr(mod, 'cmdtable', {}) |
|
3282 | cmdtable = getattr(mod, 'cmdtable', {}) | |
3289 | for t in cmdtable: |
|
3283 | for t in cmdtable: | |
3290 | if t in table: |
|
3284 | if t in table: | |
3291 | u.warn(_("module %s overrides %s\n") % (name, t)) |
|
3285 | ui.warn(_("module %s overrides %s\n") % (name, t)) | |
3292 | table.update(cmdtable) |
|
3286 | table.update(cmdtable) | |
|
3287 | ||||
|
3288 | def dispatch(args): | |||
|
3289 | for name in 'SIGBREAK', 'SIGHUP', 'SIGTERM': | |||
|
3290 | num = getattr(signal, name, None) | |||
|
3291 | if num: signal.signal(num, catchterm) | |||
|
3292 | ||||
|
3293 | try: | |||
|
3294 | u = ui.ui(traceback='--traceback' in sys.argv[1:], | |||
|
3295 | readhooks=[load_extensions]) | |||
|
3296 | except util.Abort, inst: | |||
|
3297 | sys.stderr.write(_("abort: %s\n") % inst) | |||
|
3298 | return -1 | |||
3293 |
|
3299 | |||
3294 | try: |
|
3300 | try: | |
3295 | cmd, func, args, options, cmdoptions = parse(u, args) |
|
3301 | cmd, func, args, options, cmdoptions = parse(u, args) |
@@ -12,11 +12,13 b' demandload(globals(), "ConfigParser mdif' | |||||
12 |
|
12 | |||
13 | class ui(object): |
|
13 | class ui(object): | |
14 | def __init__(self, verbose=False, debug=False, quiet=False, |
|
14 | def __init__(self, verbose=False, debug=False, quiet=False, | |
15 |
interactive=True, traceback=False, parentui=None |
|
15 | interactive=True, traceback=False, parentui=None, | |
|
16 | readhooks=[]): | |||
16 | self.overlay = {} |
|
17 | self.overlay = {} | |
17 | if parentui is None: |
|
18 | if parentui is None: | |
18 | # this is the parent of all ui children |
|
19 | # this is the parent of all ui children | |
19 | self.parentui = None |
|
20 | self.parentui = None | |
|
21 | self.readhooks = list(readhooks) | |||
20 | self.cdata = ConfigParser.SafeConfigParser() |
|
22 | self.cdata = ConfigParser.SafeConfigParser() | |
21 | self.readconfig(util.rcpath()) |
|
23 | self.readconfig(util.rcpath()) | |
22 |
|
24 | |||
@@ -34,6 +36,7 b' class ui(object):' | |||||
34 | else: |
|
36 | else: | |
35 | # parentui may point to an ui object which is already a child |
|
37 | # parentui may point to an ui object which is already a child | |
36 | self.parentui = parentui.parentui or parentui |
|
38 | self.parentui = parentui.parentui or parentui | |
|
39 | self.readhooks = list(parentui.readhooks or readhooks) | |||
37 | parent_cdata = self.parentui.cdata |
|
40 | parent_cdata = self.parentui.cdata | |
38 | self.cdata = ConfigParser.SafeConfigParser(parent_cdata.defaults()) |
|
41 | self.cdata = ConfigParser.SafeConfigParser(parent_cdata.defaults()) | |
39 | # make interpolation work |
|
42 | # make interpolation work | |
@@ -78,6 +81,8 b' class ui(object):' | |||||
78 | for name, path in self.configitems("paths"): |
|
81 | for name, path in self.configitems("paths"): | |
79 | if path and "://" not in path and not os.path.isabs(path): |
|
82 | if path and "://" not in path and not os.path.isabs(path): | |
80 | self.cdata.set("paths", name, os.path.join(root, path)) |
|
83 | self.cdata.set("paths", name, os.path.join(root, path)) | |
|
84 | for hook in self.readhooks: | |||
|
85 | hook(self) | |||
81 |
|
86 | |||
82 | def setconfig(self, section, name, val): |
|
87 | def setconfig(self, section, name, val): | |
83 | self.overlay[(section, name)] = val |
|
88 | self.overlay[(section, name)] = val |
General Comments 0
You need to be logged in to leave comments.
Login now