diff options
| author | fw-bot <otis@odoo.com> | 2020-01-24 17:29:50 +0000 |
|---|---|---|
| committer | Julien Castiaux <juc@odoo.com> | 2020-01-28 14:16:02 +0000 |
| commit | 48b51e67c93d16c6030edaaaf36d4fbcafc4b3b4 (patch) | |
| tree | b6c8edb75f74c477ee7356bf322317cf0d52b597 /odoo/modules | |
| parent | f06397b2e68b8cfb1de274e4a96b69a78a85339c (diff) | |
[FIX] module.py: --upgrades-paths dynamic hooks
Migration have long been only accessible thanks to a symlink from
`odoo.base.maintenance` to our private migration repository. Thank to
the change of bbb1a8f it is now possible to give a load the
migrations scripts from a path given in options.
The `initialize_sys_path` function has been updated to hooks the new
paths or the legacy symlink and to provide aliases to the previous
import logic to ensure backward compatibility.
`odoo.upgrades` (`community/odoo/upgrades`) is a new namespace that hook
all `--upgrades-paths` directories or the
`community/odoo/base/maintenance/migrations` symlink if none is previded.
`odoo.addons.base.maintenance.migrations` has been made an alias to
`odoo.upgrades`.
The `odoo.upgrades` is the desired method for accessing migrations
scripts and should be used by all new scripts.
closes odoo/odoo#44117
Task: 2178274
X-original-commit: d963cc05acd882729c4eb5ab940dae2a2197e55a
Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
Diffstat (limited to 'odoo/modules')
| -rw-r--r-- | odoo/modules/migration.py | 10 | ||||
| -rw-r--r-- | odoo/modules/module.py | 23 |
2 files changed, 25 insertions, 8 deletions
diff --git a/odoo/modules/migration.py b/odoo/modules/migration.py index 8faf8735a8d..f1b00a6def7 100644 --- a/odoo/modules/migration.py +++ b/odoo/modules/migration.py @@ -12,7 +12,7 @@ from os.path import join as opj from odoo.modules.module import get_resource_path import odoo.release as release -import odoo.tools as tools +import odoo.upgrades from odoo.tools.parse_version import parse_version _logger = logging.getLogger(__name__) @@ -63,7 +63,7 @@ class MigrationManager(object): def _get_files(self): def _get_upgrades_paths(pkg): - for path in tools.config['upgrades_paths'].split(','): + for path in odoo.upgrades.__path__: upgrade_path = opj(path, pkg) if os.path.exists(upgrade_path): return upgrade_path @@ -86,8 +86,6 @@ class MigrationManager(object): self.migrations[pkg.name] = { 'module': get_scripts(get_resource_path(pkg.name, 'migrations')), 'module_upgrades': get_scripts(get_resource_path(pkg.name, 'upgrades')), - 'maintenance': get_scripts(get_resource_path('base', 'maintenance', 'migrations', pkg.name)), - 'maintenance_upgrades': get_scripts(get_resource_path('base', 'maintenance', 'upgrades', pkg.name)), 'upgrades': get_scripts(_get_upgrades_paths(pkg.name)), } @@ -133,11 +131,9 @@ class MigrationManager(object): mapping = { 'module': opj(pkg.name, 'migrations'), 'module_upgrades': opj(pkg.name, 'upgrades'), - 'maintenance': opj('base', 'maintenance', 'migrations', pkg.name), - 'maintenance_upgrades': opj('base', 'maintenance', 'upgrades', pkg.name), } - for path in tools.config['upgrades_paths'].split(','): + for path in odoo.upgrades.__path__: if os.path.exists(opj(path, pkg.name)): mapping['upgrades'] = opj(path, pkg.name) break diff --git a/odoo/modules/module.py b/odoo/modules/module.py index 851395ba280..dd8fde100f2 100644 --- a/odoo/modules/module.py +++ b/odoo/modules/module.py @@ -39,20 +39,41 @@ def initialize_sys_path(): and explicit directories. """ + # hook odoo.addons on data dir dd = os.path.normcase(tools.config.addons_data_dir) if os.access(dd, os.R_OK) and dd not in odoo.addons.__path__: odoo.addons.__path__.append(dd) + # hook odoo.addons on addons paths for ad in tools.config['addons_path'].split(','): ad = os.path.normcase(os.path.abspath(tools.ustr(ad.strip()))) if ad not in odoo.addons.__path__: odoo.addons.__path__.append(ad) - # add base module path + # hook odoo.addons on base module path base_path = os.path.normcase(os.path.abspath(os.path.join(os.path.dirname(os.path.dirname(__file__)), 'addons'))) if base_path not in odoo.addons.__path__ and os.path.isdir(base_path): odoo.addons.__path__.append(base_path) + # hook odoo.upgrades on upgrades paths + from odoo import upgrades + for up in tools.config['upgrades_paths'].split(','): + up = os.path.normcase(os.path.abspath(tools.ustr(up.strip()))) + if up not in upgrades.__path__: + upgrades.__path__.append(up) + + # hook odoo.upgrades on legacy odoo/addons/base/maintenance/migrations symlink + if not tools.config['upgrades_paths']: + upgrades.__path__.append(os.path.join( + base_path, 'base', 'maintenance', 'migrations')) + + # create decrecated module alias from odoo.addons.base.maintenance.migrations to odoo.upgrades + spec = importlib.machinery.ModuleSpec("odoo.addons.base.maintenance", None, is_package=True) + maintenance_pkg = importlib.util.module_from_spec(spec) + maintenance_pkg.migrations = upgrades + sys.modules["odoo.addons.base.maintenance"] = maintenance_pkg + sys.modules["odoo.addons.base.maintenance.migrations"] = upgrades + def get_module_path(module, downloaded=False, display_warning=True): """Return the path of the given module. |
