equal
deleted
inserted
replaced
120 self._option_changes = [] |
120 self._option_changes = [] |
121 self.__context = {'confirm': self.confirm, |
121 self.__context = {'confirm': self.confirm, |
122 'config': self.config, |
122 'config': self.config, |
123 'interactive_mode': interactive, |
123 'interactive_mode': interactive, |
124 } |
124 } |
|
125 self._context_stack = [] |
125 |
126 |
126 def __getattribute__(self, name): |
127 def __getattribute__(self, name): |
127 try: |
128 try: |
128 return object.__getattribute__(self, name) |
129 return object.__getattribute__(self, name) |
129 except AttributeError: |
130 except AttributeError: |
282 context[attr[4:]] = getattr(self, attr[4:]) |
283 context[attr[4:]] = getattr(self, attr[4:]) |
283 else: |
284 else: |
284 context[attr[4:]] = getattr(self, attr) |
285 context[attr[4:]] = getattr(self, attr) |
285 return context |
286 return context |
286 |
287 |
|
288 def update_context(self, key, value): |
|
289 for context in self._context_stack: |
|
290 context[key] = value |
|
291 self.__context[key] = value |
|
292 |
287 def cmd_process_script(self, migrscript, funcname=None, *args, **kwargs): |
293 def cmd_process_script(self, migrscript, funcname=None, *args, **kwargs): |
288 """execute a migration script in interactive mode |
294 """execute a migration script in interactive mode |
289 |
295 |
290 Display the migration script path, ask for confirmation and execute it |
296 Display the migration script path, ask for confirmation and execute it |
291 if confirmed |
297 if confirmed |
325 msg = 'ignoring %s, not a valid script extension (%s)' |
331 msg = 'ignoring %s, not a valid script extension (%s)' |
326 raise ExecutionError(msg % (migrscript, ftypes)) |
332 raise ExecutionError(msg % (migrscript, ftypes)) |
327 if not self.execscript_confirm(migrscript): |
333 if not self.execscript_confirm(migrscript): |
328 return |
334 return |
329 scriptlocals = self._create_context().copy() |
335 scriptlocals = self._create_context().copy() |
|
336 self._context_stack.append(scriptlocals) |
330 if script_mode == 'python': |
337 if script_mode == 'python': |
331 if funcname is None: |
338 if funcname is None: |
332 pyname = '__main__' |
339 pyname = '__main__' |
333 else: |
340 else: |
334 pyname = splitext(basename(migrscript))[0] |
341 pyname = splitext(basename(migrscript))[0] |
350 self.commit() |
357 self.commit() |
351 else: # script_mode == 'doctest' |
358 else: # script_mode == 'doctest' |
352 import doctest |
359 import doctest |
353 doctest.testfile(migrscript, module_relative=False, |
360 doctest.testfile(migrscript, module_relative=False, |
354 optionflags=doctest.ELLIPSIS, globs=scriptlocals) |
361 optionflags=doctest.ELLIPSIS, globs=scriptlocals) |
|
362 del self._context_stack[-1] |
355 |
363 |
356 def cmd_option_renamed(self, oldname, newname): |
364 def cmd_option_renamed(self, oldname, newname): |
357 """a configuration option has been renamed""" |
365 """a configuration option has been renamed""" |
358 self._option_changes.append(('renamed', oldname, newname)) |
366 self._option_changes.append(('renamed', oldname, newname)) |
359 |
367 |