mirror of
https://github.com/bringout/oca-ocb-core.git
synced 2026-04-20 03:52:01 +02:00
18.0 vanilla
This commit is contained in:
parent
d72e748793
commit
0a7ae8db93
337 changed files with 399651 additions and 232598 deletions
|
|
@ -2,13 +2,14 @@
|
|||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
""" Modules migration handling. """
|
||||
|
||||
from collections import defaultdict
|
||||
import glob
|
||||
import importlib.util
|
||||
import inspect
|
||||
import itertools
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
from collections import defaultdict
|
||||
from os.path import join as opj
|
||||
|
||||
import odoo.release as release
|
||||
|
|
@ -220,23 +221,39 @@ class MigrationManager(object):
|
|||
for pyfile in _get_migration_files(pkg, version, stage):
|
||||
exec_script(self.cr, installed_version, pyfile, pkg.name, stage, stageformat[stage] % version)
|
||||
|
||||
|
||||
VALID_MIGRATE_PARAMS = list(itertools.product(
|
||||
['cr', '_cr'],
|
||||
['version', '_version'],
|
||||
))
|
||||
|
||||
def exec_script(cr, installed_version, pyfile, addon, stage, version=None):
|
||||
version = version or installed_version
|
||||
name, ext = os.path.splitext(os.path.basename(pyfile))
|
||||
if ext.lower() != '.py':
|
||||
return
|
||||
mod = None
|
||||
try:
|
||||
mod = load_script(pyfile, name)
|
||||
_logger.info('module %(addon)s: Running migration %(version)s %(name)s' % dict(locals(), name=mod.__name__))
|
||||
migrate = mod.migrate
|
||||
except ImportError:
|
||||
_logger.exception('module %(addon)s: Unable to load %(stage)s-migration file %(file)s' % dict(locals(), file=pyfile))
|
||||
raise
|
||||
except AttributeError:
|
||||
_logger.error('module %(addon)s: Each %(stage)s-migration file must have a "migrate(cr, installed_version)" function' % locals())
|
||||
else:
|
||||
migrate(cr, installed_version)
|
||||
finally:
|
||||
if mod:
|
||||
del mod
|
||||
except ImportError as e:
|
||||
raise ImportError('module %(addon)s: Unable to load %(stage)s-migration file %(file)s' % dict(locals(), file=pyfile)) from e
|
||||
|
||||
if not hasattr(mod, 'migrate'):
|
||||
raise AttributeError(
|
||||
'module %(addon)s: Each %(stage)s-migration file must have a "migrate(cr, installed_version)" function, not found in %(file)s' % dict(
|
||||
locals(),
|
||||
file=pyfile,
|
||||
))
|
||||
|
||||
try:
|
||||
sig = inspect.signature(mod.migrate)
|
||||
except TypeError as e:
|
||||
raise TypeError("module %(addon)s: `migrate` needs to be a function, got %(migrate)r" % dict(locals(), migrate=mod.migrate)) from e
|
||||
|
||||
if not (
|
||||
tuple(sig.parameters.keys()) in VALID_MIGRATE_PARAMS
|
||||
and all(p.kind in (p.POSITIONAL_ONLY, p.POSITIONAL_OR_KEYWORD) for p in sig.parameters.values())
|
||||
):
|
||||
raise TypeError("module %(addon)s: `migrate`'s signature should be `(cr, version)`, %(func)s is %(sig)s" % dict(locals(), func=mod.migrate, sig=sig))
|
||||
|
||||
_logger.info('module %(addon)s: Running migration %(version)s %(name)s' % dict(locals(), name=mod.__name__)) # noqa: G002
|
||||
mod.migrate(cr, installed_version)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue