migration.py
changeset 5430 ed8f71e244f8
parent 5426 0d4853a6e5ee
child 5436 2455ca3a2a3a
--- a/migration.py	Wed Apr 28 12:25:11 2010 +0200
+++ b/migration.py	Wed Apr 28 16:13:56 2010 +0200
@@ -281,14 +281,25 @@
         return context
 
     def cmd_process_script(self, migrscript, funcname=None, *args, **kwargs):
-        """execute a migration script
-        in interactive mode,  display the migration script path, ask for
-        confirmation and execute it if confirmed
+        """execute a migration script in interactive mode
+
+        Display the migration script path, ask for confirmation and execute it
+        if confirmed
+
+        Context environment can have these variables defined:
+        - __name__   : will be determine by funcname parameter
+        - __file__   : is the name of the script if it exists
+        - scriptargs : script arguments coming from command-line
+
+        :param migrscript: name of the script
+        :param funcname: defines __name__ internally (or use __main__)
+        :params args: arguments of the script
+        :keyword args: extra arguments of the script given by command-line
         """
         migrscript = os.path.normpath(migrscript)
         if migrscript.endswith('.py'):
             script_mode = 'python'
-        elif migrscript.endswith('.txt') or migrscript.endswith('.rst'):
+        elif migrscript.endswith(('.txt', '.rst')):
             script_mode = 'doctest'
         else:
             raise Exception('This is not a valid cubicweb shell input')
@@ -300,7 +311,8 @@
                 pyname = '__main__'
             else:
                 pyname = splitext(basename(migrscript))[0]
-            scriptlocals.update({'__file__': migrscript, '__name__': pyname})
+            scriptlocals.update({'__file__': migrscript, '__name__': pyname,
+                                 'scriptargs': kwargs.pop("args", [])})
             execfile(migrscript, scriptlocals)
             if funcname is not None:
                 try: