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/tools/config.py | |
| 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/tools/config.py')
| -rw-r--r-- | odoo/tools/config.py | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/odoo/tools/config.py b/odoo/tools/config.py index 194da756ef8..81d1f448f7e 100644 --- a/odoo/tools/config.py +++ b/odoo/tools/config.py @@ -9,10 +9,12 @@ except ImportError: import errno import logging import optparse +import glob import os import sys import tempfile import odoo +from os.path import expandvars, expanduser, abspath, realpath from .. import release, conf, loglevels from . import appdirs @@ -488,7 +490,7 @@ class configmanager(object): self._normalize(x) for x in self.options['addons_path'].split(',')) - self.options['upgrades_paths'] = ( + self.options["upgrades_paths"] = ( ",".join(self._normalize(x) for x in self.options['upgrades_paths'].split(',')) if self.options['upgrades_paths'] @@ -546,7 +548,7 @@ class configmanager(object): if not os.path.isdir(res): raise optparse.OptionValueError("option %s: no such directory: %r" % (opt, path)) if not self._is_addons_path(res): - raise optparse.OptionValueError("option %s: The addons-path %r does not seem to a be a valid Addons Directory!" % (opt, path)) + raise optparse.OptionValueError("option %s: the path %r is not a valid addons directory" % (opt, path)) ad_paths.append(res) setattr(parser.values, option.dest, ",".join(ad_paths)) @@ -558,9 +560,18 @@ class configmanager(object): res = self._normalize(path) if not os.path.isdir(res): raise optparse.OptionValueError("option %s: no such directory: %r" % (opt, path)) - upgrades_paths.append(res) + if not self._is_upgrades_path(res): + raise optparse.OptionValueError("option %s: the path %r is not a valid upgrade directory" % (opt, path)) + if res not in upgrades_paths: + upgrades_paths.append(res) setattr(parser.values, option.dest, ",".join(upgrades_paths)) + def _is_upgrades_path(self, res): + return any( + glob.glob(os.path.join(res, f"*/*/{prefix}-*.py")) + for prefix in ["pre", "post", "end"] + ) + def _test_enable_callback(self, option, opt, value, parser): if not parser.values.test_tags: parser.values.test_tags = "+standard" @@ -700,9 +711,7 @@ class configmanager(object): def _normalize(self, path): if not path: return path - return os.path.abspath( - os.path.expanduser( - os.path.expandvars( - path.strip()))) + return realpath(abspath(expanduser(expandvars(path.strip())))) + config = configmanager() |
