22 import os |
22 import os |
23 import logging |
23 import logging |
24 import tempfile |
24 import tempfile |
25 from os.path import exists, join, basename, splitext |
25 from os.path import exists, join, basename, splitext |
26 from itertools import chain |
26 from itertools import chain |
27 from warnings import warn |
|
28 |
27 |
29 from six import string_types |
28 from six import string_types |
30 |
29 |
31 from logilab.common import IGNORED_EXTENSIONS |
30 from logilab.common import IGNORED_EXTENSIONS |
32 from logilab.common.decorators import cached |
31 from logilab.common.decorators import cached |
353 else: |
352 else: |
354 pyname = splitext(basename(migrscript))[0] |
353 pyname = splitext(basename(migrscript))[0] |
355 scriptlocals['__name__'] = pyname |
354 scriptlocals['__name__'] = pyname |
356 with open(migrscript, 'rb') as fobj: |
355 with open(migrscript, 'rb') as fobj: |
357 fcontent = fobj.read() |
356 fcontent = fobj.read() |
358 try: |
357 code = compile(fcontent, migrscript, 'exec') |
359 code = compile(fcontent, migrscript, 'exec') |
|
360 except SyntaxError: |
|
361 # try without print_function |
|
362 code = compile(fcontent, migrscript, 'exec', 0, True) |
|
363 warn('[3.22] script %r should be updated to work with print_function' |
|
364 % migrscript, DeprecationWarning) |
|
365 exec(code, scriptlocals) |
358 exec(code, scriptlocals) |
366 if funcname is not None: |
359 if funcname is not None: |
367 try: |
360 try: |
368 func = scriptlocals[funcname] |
361 func = scriptlocals[funcname] |
369 self.info('found %s in locals', funcname) |
362 self.info('found %s in locals', funcname) |