285 |
285 |
286 Display the migration script path, ask for confirmation and execute it |
286 Display the migration script path, ask for confirmation and execute it |
287 if confirmed |
287 if confirmed |
288 |
288 |
289 Context environment can have these variables defined: |
289 Context environment can have these variables defined: |
290 - __name__ : will be determine by funcname parameter |
290 - __name__ : will be determine by funcname parameter |
291 - __file__ : is the name of the script if it exists |
291 - __file__ : is the name of the script if it exists |
292 - scriptargs : script arguments coming from command-line |
292 - __args__ : script arguments coming from command-line |
293 |
293 |
294 :param migrscript: name of the script |
294 :param migrscript: name of the script |
295 :param funcname: defines __name__ internally (or use __main__) |
295 :param funcname: defines __name__ inside the shell (or use __main__) |
296 :params args: arguments of the script |
296 :params args: optional arguments for funcname |
297 :keyword args: extra arguments of the script given by command-line |
297 :keyword scriptargs: optional arguments of the script |
298 """ |
298 """ |
299 migrscript = os.path.normpath(migrscript) |
299 migrscript = os.path.normpath(migrscript) |
300 if migrscript.endswith('.py'): |
300 if migrscript.endswith('.py'): |
301 script_mode = 'python' |
301 script_mode = 'python' |
302 elif migrscript.endswith(('.txt', '.rst')): |
302 elif migrscript.endswith(('.txt', '.rst')): |
310 if funcname is None: |
310 if funcname is None: |
311 pyname = '__main__' |
311 pyname = '__main__' |
312 else: |
312 else: |
313 pyname = splitext(basename(migrscript))[0] |
313 pyname = splitext(basename(migrscript))[0] |
314 scriptlocals.update({'__file__': migrscript, '__name__': pyname, |
314 scriptlocals.update({'__file__': migrscript, '__name__': pyname, |
315 'scriptargs': kwargs.pop("args", [])}) |
315 '__args__': kwargs.pop("scriptargs", [])}) |
316 execfile(migrscript, scriptlocals) |
316 execfile(migrscript, scriptlocals) |
317 if funcname is not None: |
317 if funcname is not None: |
318 try: |
318 try: |
319 func = scriptlocals[funcname] |
319 func = scriptlocals[funcname] |
320 self.info('found %s in locals', funcname) |
320 self.info('found %s in locals', funcname) |