From 8c0dad2c87056c7ee5a42dcb1efc1278af5da04f Mon Sep 17 00:00:00 2001 From: Sandy Carter Date: Tue, 3 Jun 2014 17:09:59 +0200 Subject: [PATCH] Simplify migration calling, fix breakpoint use Don't write to a temp file Use `load_module` instead of `load_source` This allows the use of breakpoints in IDEs and in pdb Signed-off-by: Sandy Carter --- openerp/modules/migration.py | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/openerp/modules/migration.py b/openerp/modules/migration.py index ad67df966599..9aef265b7865 100644 --- a/openerp/modules/migration.py +++ b/openerp/modules/migration.py @@ -157,17 +157,14 @@ def mergedict(a, b): name, ext = os.path.splitext(os.path.basename(pyfile)) if ext.lower() != '.py': continue - mod = fp = fp2 = None + # OpenUpgrade edit start: + # Removed a copy of migration script to temp directory + # Replaced call to load_source with load_module so frame isn't lost and breakpoints can be set + mod = fp = None try: - fp = tools.file_open(pyfile) - - # imp.load_source need a real file object, so we create - # one from the file-like object we get from file_open - fp2 = os.tmpfile() - fp2.write(fp.read()) - fp2.seek(0) + fp, pathname = tools.file_open(pyfile, pathinfo=True) try: - mod = imp.load_source(name, pyfile, fp2) + mod = imp.load_module(name, fp, pathname, ('.py', 'r', imp.PY_SOURCE)) _logger.info('module %(addon)s: Running migration %(version)s %(name)s', mergedict({'name': mod.__name__}, strfmt)) except ImportError: @@ -186,10 +183,9 @@ def mergedict(a, b): finally: if fp: fp.close() - if fp2: - fp2.close() if mod: del mod + # OpenUpgrade edit end # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: