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