[RFR] upgrade_path not user writable
parent
790aabe077
commit
b0913f935e
|
@ -2,6 +2,5 @@ from . import odoo_patch
|
||||||
from . import models
|
from . import models
|
||||||
from . import wizards
|
from . import wizards
|
||||||
from . import blacklist
|
from . import blacklist
|
||||||
from . import apriori
|
|
||||||
from . import compare
|
from . import compare
|
||||||
from . import upgrade_log
|
from . import upgrade_log
|
||||||
|
|
|
@ -1,31 +0,0 @@
|
||||||
""" Encode any known changes to the database here
|
|
||||||
to help the matching process
|
|
||||||
"""
|
|
||||||
|
|
||||||
import logging
|
|
||||||
|
|
||||||
_logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
try:
|
|
||||||
from odoo.addons.openupgrade_scripts.apriori import merged_modules, renamed_modules
|
|
||||||
except ImportError:
|
|
||||||
renamed_modules = {}
|
|
||||||
merged_modules = {}
|
|
||||||
_logger.warning(
|
|
||||||
"You are using upgrade_analysis without having"
|
|
||||||
" openupgrade_scripts module available."
|
|
||||||
" The analysis process will not work properly,"
|
|
||||||
" if you are generating analysis for the odoo modules"
|
|
||||||
" in an openupgrade context."
|
|
||||||
)
|
|
||||||
|
|
||||||
renamed_modules.update({})
|
|
||||||
|
|
||||||
merged_modules.update({})
|
|
||||||
|
|
||||||
# only used here for upgrade_analysis
|
|
||||||
renamed_models = {}
|
|
||||||
|
|
||||||
# only used here for upgrade_analysis
|
|
||||||
merged_models = {}
|
|
|
@ -11,7 +11,19 @@
|
||||||
import collections
|
import collections
|
||||||
import copy
|
import copy
|
||||||
|
|
||||||
from . import apriori
|
try:
|
||||||
|
from odoo.addons.openupgrade_scripts import apriori
|
||||||
|
except ImportError:
|
||||||
|
from dataclasses import dataclass, field
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class NullApriori:
|
||||||
|
renamed_modules: dict = field(default_factory=dict)
|
||||||
|
merged_modules: dict = field(default_factory=dict)
|
||||||
|
renamed_models: dict = field(default_factory=dict)
|
||||||
|
merged_models: dict = field(default_factory=dict)
|
||||||
|
|
||||||
|
apriori = NullApriori()
|
||||||
|
|
||||||
|
|
||||||
def module_map(module):
|
def module_map(module):
|
||||||
|
|
|
@ -24,6 +24,9 @@ class UpgradeAttribute(models.Model):
|
||||||
def _compute_is_odoo_module(self):
|
def _compute_is_odoo_module(self):
|
||||||
for module in self:
|
for module in self:
|
||||||
module_path = get_module_path(module.name)
|
module_path = get_module_path(module.name)
|
||||||
|
if not module_path:
|
||||||
|
module.is_odoo_module = False
|
||||||
|
continue
|
||||||
absolute_repo_path = os.path.split(module_path)[0]
|
absolute_repo_path = os.path.split(module_path)[0]
|
||||||
x, relative_repo_path = os.path.split(absolute_repo_path)
|
x, relative_repo_path = os.path.split(absolute_repo_path)
|
||||||
module.is_odoo_module = relative_repo_path == "addons"
|
module.is_odoo_module = relative_repo_path == "addons"
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
from odoo import fields, models
|
from odoo import fields, models
|
||||||
from odoo.exceptions import UserError
|
from odoo.exceptions import UserError
|
||||||
|
@ -18,11 +17,6 @@ from .. import compare
|
||||||
_logger = logging.getLogger(__name__)
|
_logger = logging.getLogger(__name__)
|
||||||
_IGNORE_MODULES = ["openupgrade_records", "upgrade_analysis"]
|
_IGNORE_MODULES = ["openupgrade_records", "upgrade_analysis"]
|
||||||
|
|
||||||
try:
|
|
||||||
from odoo.addons.openupgrade_scripts import apriori
|
|
||||||
except ImportError:
|
|
||||||
apriori = False
|
|
||||||
|
|
||||||
|
|
||||||
class UpgradeAnalysis(models.Model):
|
class UpgradeAnalysis(models.Model):
|
||||||
_name = "upgrade.analysis"
|
_name = "upgrade.analysis"
|
||||||
|
@ -42,28 +36,28 @@ class UpgradeAnalysis(models.Model):
|
||||||
|
|
||||||
log = fields.Text(readonly=True)
|
log = fields.Text(readonly=True)
|
||||||
upgrade_path = fields.Char(
|
upgrade_path = fields.Char(
|
||||||
default=lambda x: x._default_upgrade_path(),
|
compute="_compute_upgrade_path",
|
||||||
|
readonly=True,
|
||||||
help=(
|
help=(
|
||||||
"The base file path to save the analyse files of Odoo modules. "
|
"The base file path to save the analyse files of Odoo modules. "
|
||||||
"Default is taken from Odoo's --upgrade-path command line option. "
|
"Taken from Odoo's --upgrade-path command line option or the "
|
||||||
|
"'scripts' subdirectory in the openupgrade_scripts addon."
|
||||||
),
|
),
|
||||||
required=True,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
write_files = fields.Boolean(
|
write_files = fields.Boolean(
|
||||||
help="Write analysis files to the module directories", default=True
|
help="Write analysis files to the module directories", default=True
|
||||||
)
|
)
|
||||||
|
|
||||||
def _default_upgrade_path(self):
|
def _compute_upgrade_path(self):
|
||||||
# Return upgrade_path value, if exists
|
"""Return the --upgrade-path configuration option or the `scripts`
|
||||||
config_value = config.get("upgrade_path", False)
|
directory in `openupgrade_scripts` if available
|
||||||
if config_value:
|
"""
|
||||||
return config_value
|
res = config.get("upgrade_path", False)
|
||||||
# Otherwise, try to guess, with the openupgrade_scripts path
|
if not res:
|
||||||
elif apriori:
|
module_path = get_module_path("openupgrade_scripts", display_warning=False)
|
||||||
apriori_path = Path(os.path.abspath(apriori.__file__))
|
if module_path:
|
||||||
return os.path.join(apriori_path.parent, "scripts")
|
res = os.path.join(module_path, "scripts")
|
||||||
return False
|
self.upgrade_path = res
|
||||||
|
|
||||||
def _get_remote_model(self, connection, model):
|
def _get_remote_model(self, connection, model):
|
||||||
self.ensure_one()
|
self.ensure_one()
|
||||||
|
@ -79,13 +73,16 @@ class UpgradeAnalysis(models.Model):
|
||||||
):
|
):
|
||||||
module = self.env["ir.module.module"].search([("name", "=", module_name)])[0]
|
module = self.env["ir.module.module"].search([("name", "=", module_name)])[0]
|
||||||
if module.is_odoo_module:
|
if module.is_odoo_module:
|
||||||
module_path = os.path.join(self.upgrade_path, module_name)
|
if not self.upgrade_path:
|
||||||
full_path = os.path.join(module_path, version)
|
return (
|
||||||
|
"ERROR: no upgrade_path set when writing analysis of %s\n"
|
||||||
|
% module_name
|
||||||
|
)
|
||||||
|
full_path = os.path.join(self.upgrade_path, module_name, version)
|
||||||
else:
|
else:
|
||||||
module_path = get_module_path(module_name)
|
full_path = os.path.join(
|
||||||
full_path = os.path.join(module_path, "migrations", version)
|
get_module_path(module_name, "migrations", version)
|
||||||
if not module_path:
|
)
|
||||||
return "ERROR: could not find module path of '%s':\n" % (module_name)
|
|
||||||
if not os.path.exists(full_path):
|
if not os.path.exists(full_path):
|
||||||
try:
|
try:
|
||||||
os.makedirs(full_path)
|
os.makedirs(full_path)
|
||||||
|
@ -116,11 +113,6 @@ class UpgradeAnalysis(models.Model):
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
if not self.upgrade_path:
|
|
||||||
return (
|
|
||||||
"ERROR: no upgrade_path set when writing analysis of %s\n" % module_name
|
|
||||||
)
|
|
||||||
|
|
||||||
connection = self.config_id.get_connection()
|
connection = self.config_id.get_connection()
|
||||||
RemoteRecord = self._get_remote_model(connection, "record")
|
RemoteRecord = self._get_remote_model(connection, "record")
|
||||||
LocalRecord = self.env["upgrade.record"]
|
LocalRecord = self.env["upgrade.record"]
|
||||||
|
@ -183,6 +175,17 @@ class UpgradeAnalysis(models.Model):
|
||||||
+ local_model_records
|
+ local_model_records
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
if "base" in affected_modules:
|
||||||
|
try:
|
||||||
|
from odoo.addons.openupgrade_scripts import apriori
|
||||||
|
except ImportError:
|
||||||
|
_logger.error(
|
||||||
|
"You are using upgrade_analysis on core modules without "
|
||||||
|
" having openupgrade_scripts module available."
|
||||||
|
" The analysis process will not work properly,"
|
||||||
|
" if you are generating analysis for the odoo modules"
|
||||||
|
" in an openupgrade context."
|
||||||
|
)
|
||||||
|
|
||||||
# reorder and output the result
|
# reorder and output the result
|
||||||
keys = ["general"] + affected_modules
|
keys = ["general"] + affected_modules
|
||||||
|
|
|
@ -38,7 +38,7 @@
|
||||||
/>
|
/>
|
||||||
<field
|
<field
|
||||||
name="upgrade_path"
|
name="upgrade_path"
|
||||||
attrs="{'readonly': [('state', '=', 'done')], 'invisible': [('write_files', '=', False)]}"
|
attrs="{'invisible': [('write_files', '=', False)]}"
|
||||||
/>
|
/>
|
||||||
<field
|
<field
|
||||||
name="analysis_date"
|
name="analysis_date"
|
||||||
|
|
Loading…
Reference in New Issue