--- a/common/migration.py Sat Nov 28 10:27:58 2009 +0100
+++ b/common/migration.py Sat Nov 28 11:42:37 2009 +0100
@@ -268,10 +268,17 @@
in interactive mode, display the migration script path, ask for
confirmation and execute it if confirmed
"""
- assert migrscript.endswith('.py'), migrscript
migrscript = os.path.normpath(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:
@@ -287,6 +294,10 @@
self.critical('no %s in script %s', funcname, migrscript)
return None
return func(*args, **kwargs)
+ else: # script_mode == 'doctest'
+ import doctest
+ doctest.testfile(migrscript, module_relative=False,
+ optionflags=doctest.ELLIPSIS, globs=scriptlocals)
def cmd_option_renamed(self, oldname, newname):
"""a configuration option has been renamed"""
--- a/server/migractions.py Sat Nov 28 10:27:58 2009 +0100
+++ b/server/migractions.py Sat Nov 28 11:42:37 2009 +0100
@@ -106,12 +106,12 @@
if migrscript.endswith('.sql'):
if self.execscript_confirm(migrscript):
sqlexec(open(migrscript).read(), self.session.system_sql)
- elif migrscript.endswith('.py'):
+ elif migrscript.endswith('.py') or migrscript.endswith('.txt'):
return super(ServerMigrationHelper, self).cmd_process_script(
migrscript, funcname, *args, **kwargs)
else:
print
- print ('-> ignoring %s, only .py and .sql scripts are considered' %
+ print ('-> ignoring %s, only .py .sql and .txt scripts are considered' %
migrscript)
print
self.commit()