Skip to content

Commit

Permalink
[IMP] upgrade_coverage : generate coverage module file
Browse files Browse the repository at this point in the history
  • Loading branch information
legalsylvain committed Nov 12, 2021
1 parent d4e9f7c commit 4b87950
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 2 deletions.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# generated from manifests external_dependencies
dataclasses
mako
odoorpc
openupgradelib
2 changes: 1 addition & 1 deletion upgrade_analysis/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"installable": True,
"depends": ["base"],
"external_dependencies": {
"python": ["dataclasses", "odoorpc", "openupgradelib"],
"python": ["mako", "dataclasses", "odoorpc", "openupgradelib"],
},
"license": "AGPL-3",
}
71 changes: 70 additions & 1 deletion upgrade_analysis/models/upgrade_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
from copy import deepcopy

from lxml import etree
from mako.template import Template

from odoo import fields, models
from odoo import fields, models, release
from odoo.exceptions import ValidationError
from odoo.modules import get_module_path
from odoo.tools import config
Expand Down Expand Up @@ -265,6 +266,12 @@ def analyze(self):
_logger.exception("Error generating noupdate changes: %s" % e)
general_log += "ERROR: error when generating noupdate changes: %s\n" % e

try:
self.generate_module_coverage_file()
except Exception as e:
_logger.exception("Error generating module coverage file: %s" % e)
general_log += "ERROR: error when generating module coverage file: %s\n" % e

self.write(
{
"state": "done",
Expand Down Expand Up @@ -494,3 +501,65 @@ def generate_noupdate_changes(self):
filename="noupdate_changes.xml",
)
return True

def generate_module_coverage_file(self):
self.ensure_one()

module_coverage_file_folder = config.get("module_coverage_file_folder", False)

if not module_coverage_file_folder:
return

file_template = Template(
filename=os.path.join(
get_module_path("upgrade_analysis"),
"static",
"src",
"module_coverage_template.rst.mako",
)
)

module_domain = [
("state", "=", "installed"),
("name", "not in", ["upgrade_analysis", "openupgrade_records"]),
]

connection = self.config_id.get_connection()
all_local_modules = (
self.env["ir.module.module"].search(module_domain).mapped("name")
)
all_remote_modules = (
connection.env["ir.module.module"]
.browse(connection.env["ir.module.module"].search(module_domain))
.mapped("name")
)

start_version = "14.0" # connection.version
end_version = release.major_version

all_modules = sorted(list(set(all_remote_modules + all_local_modules)))
module_descriptions = []
for module in all_modules:
if module in all_local_modules and module in all_remote_modules:
module_description = " %s" % module
elif module in all_local_modules:
module_description = " |add| %s" % module
else:
module_description = " |del| %s" % module
module_descriptions.append(module_description.ljust(49, " "))

rendered_text = file_template.render(
start_version=start_version,
end_version=end_version,
module_descriptions=module_descriptions,
)

file_name = "modules{}-{}.rst".format(
start_version.replace(".", ""),
end_version.replace(".", ""),
)

file_path = os.path.join(module_coverage_file_folder, file_name)
f = open(file_path, "w+")
f.write(rendered_text)
f.close()
12 changes: 12 additions & 0 deletions upgrade_analysis/static/src/module_coverage_template.rst.mako
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Module coverage ${start_version} -> ${end_version}
============================

.. include:: coverage_legend.rst

+-------------------------------------------------+-------------------------------------------------+
|Module |Status |
+=================================================+=================================================+
% for module_description in module_descriptions:
|${module_description}| |
+-------------------------------------------------+-------------------------------------------------+
% endfor

0 comments on commit 4b87950

Please sign in to comment.