From a04353b683d427370c9aa0cf985f53a7fe5ed12c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Taymans?= Date: Thu, 16 Mar 2023 23:24:28 +0100 Subject: [PATCH 1/3] [ADD] estimate-workload: ignored module list --- odoo_openupgrade_wizard/templates/config.yml.j2 | 3 +++ odoo_openupgrade_wizard/tools/tools_odoo_module.py | 14 +++++++++++--- tests/data/output_expected/config.yml | 3 +++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/odoo_openupgrade_wizard/templates/config.yml.j2 b/odoo_openupgrade_wizard/templates/config.yml.j2 index 2795c4f..dcda4a7 100644 --- a/odoo_openupgrade_wizard/templates/config.yml.j2 +++ b/odoo_openupgrade_wizard/templates/config.yml.j2 @@ -35,6 +35,9 @@ migration_steps: workload_settings: + # Ignored module list + ignored_module_list: [] + # porting a module requires 45 minutes minimaly port_minimal_time: 45 diff --git a/odoo_openupgrade_wizard/tools/tools_odoo_module.py b/odoo_openupgrade_wizard/tools/tools_odoo_module.py index a07580a..1194ae0 100644 --- a/odoo_openupgrade_wizard/tools/tools_odoo_module.py +++ b/odoo_openupgrade_wizard/tools/tools_odoo_module.py @@ -318,6 +318,7 @@ class OdooModule(object): self.name = module_name self.repository = repository_name self.unique_name = "%s.%s" % (repository_name, module_name) + self.ignored = self.is_ignored(ctx, module_name) self.module_versions = {} if not repository_name: self.module_type = "not_found" @@ -335,6 +336,11 @@ class OdooModule(object): for _, module_version in self.module_versions.items() ) + def is_ignored(self, ctx, module_name): + """Return true if module should be ignored""" + settings = ctx.obj["config"]["workload_settings"] + return module_name in settings["ignored_module_list"] + def get_module_version(self, current_version): res = self.module_versions.get(current_version, False) return res @@ -494,7 +500,7 @@ class OdooModuleVersion(object): self.version = version self.odoo_module = odoo_module self.addon_path = addon_path - self.state = state + self.state = "ignored" if odoo_module.ignored else state self.target_module = target_module self.openupgrade_state = "" self.python_code = 0 @@ -535,7 +541,7 @@ class OdooModuleVersion(object): openupgrade_field_line_time = settings["openupgrade_field_line_time"] openupgrade_xml_line_time = settings["openupgrade_xml_line_time"] - if self.state in ["merged", "renamed", "normal_loss"]: + if self.state in ["merged", "renamed", "normal_loss", "ignored"]: # The module has been moved, nothing to do return @@ -734,7 +740,7 @@ class OdooModuleVersion(object): return "lightgreen" else: # The module doesn't exist in the current version - if self.state in ["merged", "renamed", "normal_loss"]: + if self.state in ["merged", "renamed", "normal_loss", "ignored"]: # Normal case, the previous version has been renamed # or merged return "lightgray" @@ -765,6 +771,8 @@ class OdooModuleVersion(object): return "Merged into %s" % self.target_module elif self.state == "renamed": return "Renamed into %s" % self.target_module + elif self.state == "ignored": + return "Ignored" elif self.state == "normal_loss": return "" diff --git a/tests/data/output_expected/config.yml b/tests/data/output_expected/config.yml index 6170674..dcf6ba0 100644 --- a/tests/data/output_expected/config.yml +++ b/tests/data/output_expected/config.yml @@ -42,6 +42,9 @@ migration_steps: workload_settings: + # Ignored module list + ignored_module_list: [] + # porting a module requires 45 minutes minimaly port_minimal_time: 45 From 15088c9d0f0c7d51da06f34db9a757e4e27d13ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Taymans?= Date: Thu, 16 Mar 2023 23:27:39 +0100 Subject: [PATCH 2/3] [FIX] config: indentation --- .../templates/config.yml.j2 | 40 +++++++++---------- tests/data/output_expected/config.yml | 40 +++++++++---------- 2 files changed, 40 insertions(+), 40 deletions(-) diff --git a/odoo_openupgrade_wizard/templates/config.yml.j2 b/odoo_openupgrade_wizard/templates/config.yml.j2 index dcda4a7..d435171 100644 --- a/odoo_openupgrade_wizard/templates/config.yml.j2 +++ b/odoo_openupgrade_wizard/templates/config.yml.j2 @@ -35,32 +35,32 @@ migration_steps: workload_settings: - # Ignored module list - ignored_module_list: [] + # Ignored module list + ignored_module_list: [] - # porting a module requires 45 minutes minimaly - port_minimal_time: 45 + # porting a module requires 45 minutes minimaly + port_minimal_time: 45 - # a migration cost more for each version - port_per_version: 15 + # a migration cost more for each version + port_per_version: 15 - # Porting 120 lines of Python code costs 1 hour - port_per_python_line_time: 0.5 + # Porting 120 lines of Python code costs 1 hour + port_per_python_line_time: 0.5 - # Porting 120 lines of Javascript code costs 1 hour - port_per_javascript_line_time: 0.5 + # Porting 120 lines of Javascript code costs 1 hour + port_per_javascript_line_time: 0.5 - # Porting 10 lines of XML costs 1 minute - port_per_xml_line_time: 0.10 + # Porting 10 lines of XML costs 1 minute + port_per_xml_line_time: 0.10 - # Minimal time for Openupgrade PR - open_upgrade_minimal_time: 10 + # Minimal time for Openupgrade PR + open_upgrade_minimal_time: 10 - # time for a line of model in the openupgrade_analysis.txt - openupgrade_model_line_time: 10 + # time for a line of model in the openupgrade_analysis.txt + openupgrade_model_line_time: 10 - # Time for a line of field in the openupgrade_analysis.txt - openupgrade_field_line_time: 5 + # Time for a line of field in the openupgrade_analysis.txt + openupgrade_field_line_time: 5 - # Time for a line of XML in the openupgrade_analysis.txt - openupgrade_xml_line_time: 0.1 + # Time for a line of XML in the openupgrade_analysis.txt + openupgrade_xml_line_time: 0.1 diff --git a/tests/data/output_expected/config.yml b/tests/data/output_expected/config.yml index dcf6ba0..c9784ed 100644 --- a/tests/data/output_expected/config.yml +++ b/tests/data/output_expected/config.yml @@ -42,32 +42,32 @@ migration_steps: workload_settings: - # Ignored module list - ignored_module_list: [] + # Ignored module list + ignored_module_list: [] - # porting a module requires 45 minutes minimaly - port_minimal_time: 45 + # porting a module requires 45 minutes minimaly + port_minimal_time: 45 - # a migration cost more for each version - port_per_version: 15 + # a migration cost more for each version + port_per_version: 15 - # Porting 120 lines of Python code costs 1 hour - port_per_python_line_time: 0.5 + # Porting 120 lines of Python code costs 1 hour + port_per_python_line_time: 0.5 - # Porting 120 lines of Javascript code costs 1 hour - port_per_javascript_line_time: 0.5 + # Porting 120 lines of Javascript code costs 1 hour + port_per_javascript_line_time: 0.5 - # Porting 10 lines of XML costs 1 minute - port_per_xml_line_time: 0.10 + # Porting 10 lines of XML costs 1 minute + port_per_xml_line_time: 0.10 - # Minimal time for Openupgrade PR - open_upgrade_minimal_time: 10 + # Minimal time for Openupgrade PR + open_upgrade_minimal_time: 10 - # time for a line of model in the openupgrade_analysis.txt - openupgrade_model_line_time: 10 + # time for a line of model in the openupgrade_analysis.txt + openupgrade_model_line_time: 10 - # Time for a line of field in the openupgrade_analysis.txt - openupgrade_field_line_time: 5 + # Time for a line of field in the openupgrade_analysis.txt + openupgrade_field_line_time: 5 - # Time for a line of XML in the openupgrade_analysis.txt - openupgrade_xml_line_time: 0.1 \ No newline at end of file + # Time for a line of XML in the openupgrade_analysis.txt + openupgrade_xml_line_time: 0.1 From 40c54d22609ee457844928540bde8b49210ebbb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Taymans?= Date: Fri, 17 Mar 2023 00:16:08 +0100 Subject: [PATCH 3/3] [FIX] missing newline in generated files In a proper file each line end with a newline character, even the last one. Wrong file: Using `write()` function does not add a newline character at the end of the write. So writing a string in a file with `write()` leads to a file like this: ``` line1\n line2\n lastline ``` Good file: Using the `print()` command automatically ends the string with a newline character. So that we ends with a proper file: ``` line1\n line2\n lastline\n ``` Also the with statement automatically closes the file at the end of the block. --- odoo_openupgrade_wizard/tools/tools_system.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/odoo_openupgrade_wizard/tools/tools_system.py b/odoo_openupgrade_wizard/tools/tools_system.py index 3409856..3e5e437 100644 --- a/odoo_openupgrade_wizard/tools/tools_system.py +++ b/odoo_openupgrade_wizard/tools/tools_system.py @@ -78,8 +78,7 @@ def ensure_file_exists_from_template( with open(file_path, "w") as f: logger.info(log_text) - f.write(output) - f.close() + print(output, file=f) def git_aggregate(folder_path: Path, config_path: Path, jobs: int):