# HG changeset patch # User Nicolas Chauvat # Date 1257713598 -3600 # Node ID 5b75fd66c80edaf903a212a17fb19026dee61a55 # Parent 3ef8cdb5fb1c5ed5b240166725095f398d8855f9 #509981: cw-ctl shell file.txt runs doctest.testfile diff -r 3ef8cdb5fb1c -r 5b75fd66c80e common/migration.py --- a/common/migration.py Wed Oct 21 17:32:20 2009 +0200 +++ b/common/migration.py Sun Nov 08 21:53:18 2009 +0100 @@ -268,9 +268,16 @@ in interactive mode, display the migration script path, ask for confirmation and execute it if confirmed """ - assert migrscript.endswith('.py'), migrscript - if self.execscript_confirm(migrscript): - scriptlocals = self._create_context().copy() + if migrscript.endswith('.py'): + script_mode = 'python' + elif migrscript.endswith('.txt') or migrscript.endswith('.rst'): + script_mode = 'doctest' + else: + raise Exception('This is not a valid cubicweb shell input') + if not self.execscript_confirm(migrscript): + return + scriptlocals = self._create_context().copy() + if script_mode == 'python': if funcname is None: pyname = '__main__' else: @@ -286,6 +293,10 @@ self.critical('no %s in script %s', funcname, migrscript) return None return func(*args, **kwargs) + else: # script_mode == 'doctest' + import doctest + doctest.testfile(os.path.abspath(migrscript), module_relative=False, + optionflags=doctest.ELLIPSIS, globs=scriptlocals) def cmd_option_renamed(self, oldname, newname): """a configuration option has been renamed"""