diff --git a/.gitignore b/.gitignore index 894a44c..ad61f44 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ +# odoo-module-migrator + +data_tmp/ + # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] diff --git a/.travis.yml b/.travis.yml index f178af8..c7ce33f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,7 +20,7 @@ install: script: - git --version - flake8 . --exclude=__init__.py - - coverage run --source git_aggregator setup.py test + - coverage run --source odoo_migrate setup.py test after_success: - coveralls diff --git a/DEVELOP.rst b/DEVELOP.rst index f6309f0..8892c17 100644 --- a/DEVELOP.rst +++ b/DEVELOP.rst @@ -93,17 +93,37 @@ The list of the operations are written in the subfolder } } -* Display warnings if files contains a given partern. For exemple, for +* Display errors if files contains a given partern. For exemple, for migration from version 10.0 to version 11.0: .. code-block:: python - _TEXT_WARNING = { + _TEXT_ERRORS = { "*": { "ir.values": "ir.values table does not exist anymore" } } +* Dependencies to obsoletes modules. There is four possibility: + * the module has been fully removed. + * the module has been renamed. + * the module features has been merged into another module. + * the module has been moved under OCA umbrella. (w/o another name) + +.. code-block:: python + + _DEPRECATED_MODULES = [ + + ("account_anglo_saxon", "removed"), + + ("account_check_writing", "renamed", "account_check_printing"), + + ("account_chart", "merged", "account"), + + ("account_analytic_analysis", "oca_moved", "contract", "Moved to OCA/contract"), + + ] + How to improve the library ========================== diff --git a/README.rst b/README.rst index db6a836..146eeb7 100644 --- a/README.rst +++ b/README.rst @@ -28,14 +28,38 @@ This library will so: * apply automatically changes. (renaming, replacing, etc.) * (depending of the config and the version) black your code. * commit your changes. -* Display warnings if your code belong obsolete code patterns. For exemple, - for a migration to V11+ +* Display warnings or errors in log if your code belong obsolete code patterns. +**INFO log** + +It mentions that the lib automatically changed something. +*A priori* you have nothing to do. For example, for a migration from 8.0 to +a more recent version: .. code-block:: shell + 12:38:54 INFO Renaming file: '/my_module/__openerp__.py' by '/my_module/__manifest__.py' + +**WARNING log** + +It mentions that you should check something. There is *maybe* something to do +to make the module working. For exemple: + +.. code-block:: shell + + 19:37:55 WARNING Replaced dependency of 'account_analytic_analysis' by 'contract' (Moved to OCA/contract) + - 15:59:04 WARNING 'ir.values' found. This model has been removed in V11. +**ERROR log** +It mentions that you should change something in your code. It not, the module +will not work *for sure*. (not installable, or generating error during the +execution) + +For example, if you have a 8.0 module that depends on 'account_chart', that +disappeared in more recent version, the following log will be displayed + +.. code-block:: shell + 12:38:54 ERROR Depends on removed module 'account_anglo_saxon' Development and improvment ========================== @@ -132,13 +156,50 @@ Available arguments Roadmap / Know issues ===================== -* Complete migration scripts. - -* Add tests. +* replacement of tag by will fail in the case + where there are many occurency. + We could fix that, using ``lxml`` lib instead of regular expression. Changes ======= +0.1.4 (October 12, 2019) +------------------------ +* test +[ADD] test + +* framework +[ADD] ``--file-path`` option. +[ADD] ``_DEPRECATED_MODULES`` syntax. + +* migration script +[FIX] Incorrect syntax of regular expression, to remove python 2 header +[IMP] first release of all the steps from 8.0 to 13.0 + + +0.1.3 (October 11, 2019) +------------------------ + +* framework + +[ADD] ``--no-commit`` option that disable git add and git commit calls +[FIX] do not commit many times if migration has many steps. +[REF] remove useless commented code +[REF] create _commit_changes() and _replace_in_file() functions + +* Meta + +[FIX] github url of the project in setup.py +[ADD] Travis file + links to coveralls +[ADD] test_requirements.txt + +* migration script + +[ADD] 12.0 to 13.0 and add a warning if reference to web_settings_dashboard are found. cortesy @yelizariev +[ADD] bump version in manifest file +[ADD] set installable to True + + 0.1.2 (October 10, 2019) ------------------------ diff --git a/odoo_migrate/__main__.py b/odoo_migrate/__main__.py index 40f1ef9..0350a1c 100644 --- a/odoo_migrate/__main__.py +++ b/odoo_migrate/__main__.py @@ -4,8 +4,8 @@ import argparse import argcomplete -# from pathlib import Path -# from . import migrate_tools +import sys + from . import tools from .log import setup_logger from .migration import Migration @@ -92,6 +92,14 @@ def get_parser(): type=str, ) + main_parser.add_argument( + "-lp", + "--log-path", + dest="log_path", + default=False, + type=str, + ) + main_parser.add_argument( "-nc", "--no-commit", @@ -104,14 +112,14 @@ def get_parser(): return main_parser -def main(): +def main(args): # Parse Arguments parser = get_parser() argcomplete.autocomplete(parser, always_complete_options=False) - args = parser.parse_args() + args = parser.parse_args(args) # Set log level - setup_logger(args.log_level) + setup_logger(args.log_level, args.log_path) try: # Create a new Migration Object @@ -132,4 +140,4 @@ def main(): if __name__ == "__main__": - main() + main(sys.argv[1:]) diff --git a/odoo_migrate/log.py b/odoo_migrate/log.py index b4af80b..6ce26d6 100644 --- a/odoo_migrate/log.py +++ b/odoo_migrate/log.py @@ -22,15 +22,19 @@ } -def setup_logger(level): - handler = logging.StreamHandler() - handler.setFormatter(OdooMigrateFormatter()) +def setup_logger(level, file_path=False): + if not file_path: + handler = logging.StreamHandler() + handler.setFormatter(OdooMigrateFormatter()) + else: + handler = logging.FileHandler(file_path) + handler.setFormatter(logging.Formatter( + "%(asctime)s,%(msecs)d %(name)s %(levelname)s %(message)s")) logger.addHandler(handler) logger.setLevel(getattr(logging, str(level))) class OdooMigrateFormatter(logging.Formatter): - """custom Log Formatter""" def format(self, record): """Overwrite format() function to use custom formatter""" @@ -50,7 +54,6 @@ def default_prefix_template(self, record): from inside the :py:meth:`logging.Formatter.format` record. """ - reset = [Style.RESET_ALL] levelname = [ LEVEL_COLORS.get(record.levelname), Style.BRIGHT, diff --git a/odoo_migrate/migration.py b/odoo_migrate/migration.py index c07b220..51199de 100644 --- a/odoo_migrate/migration.py +++ b/odoo_migrate/migration.py @@ -130,6 +130,10 @@ def _get_code_from_previous_branch(self, module_name, remote_name): def _get_migration_scripts(self): + # Add the script that will be allways executed + self._migration_scripts.append(importlib.import_module( + "odoo_migrate.migration_scripts.migrate_allways")) + all_packages = importlib.import_module( "odoo_migrate.migration_scripts") @@ -161,10 +165,6 @@ def _get_migration_scripts(self): self._migration_scripts.append(importlib.import_module(full_name)) - # Finally, add the script that will be allways executed - self._migration_scripts.append(importlib.import_module( - "odoo_migrate.migration_scripts.migrate_allways")) - logger.debug( "The following migration script will be" " executed:\n- %s" % '\n- '.join( diff --git a/odoo_migrate/migration_scripts/__init__.py b/odoo_migrate/migration_scripts/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/odoo_migrate/migration_scripts/migrate_080_090.py b/odoo_migrate/migration_scripts/migrate_080_090.py index 3777b6e..84be2d2 100644 --- a/odoo_migrate/migration_scripts/migrate_080_090.py +++ b/odoo_migrate/migration_scripts/migrate_080_090.py @@ -3,12 +3,61 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). _TEXT_REPLACES = { - "*": { - "base.group_configuration": "base.group_system", - "base.group_sale_salesman": "sales_team.group_sale_salesman", - "base.group_sale_salesman_all_leads": - "sales_team.group_sale_salesman_all_leads", - "base.group_sale_manager": "sales_team.group_sale_manager", - }, ".py": {"select=True": "index=True"}, } + +_DEPRECATED_MODULES = [ + ("account_analytic_analysis", "oca_moved", "contract", + "Moved to OCA/contract"), + ("account_analytic_plans", "oca_moved", "account_analytic_distribution", + "Moved to OCA/account_analytic"), + ("account_anglo_saxon", "removed"), + ("account_bank_statement_extensions", "removed"), + ("account_chart", "merged", "account"), + ("account_check_writing", "renamed", "account_check_printing"), + ("account_followup", "removed"), + ("account_payment", "oca_moved", "account_payment_order", + "Moved to OCA/bank-payment"), + ("account_sequence", "removed"), + ("analytic_contract_hr_expense", "removed"), + ("analytic_user_function", "removed"), + ("anglo_saxon_dropshipping", "removed"), + ("auth_openid", "removed"), + ("base_report_designer", "removed"), + ("contacts", "merged", "mail"), + ("crm_helpdesk", "removed"), + ("crm_mass_mailing", "removed"), + ("crm_profiling", "removed"), + ("edi", "removed"), + ("email_template", "merged", "mail_template"), + ("hr_applicant_document", "removed"), + ("hr_timesheet_invoice", "removed"), + ("im_chat", "merged", "mail"), + ("knowledge", "oca_moved", "knowledge", "Moved to OCA/knowledge"), + ("l10n_be_coda", "removed"), + ("l10n_fr_rib", "removed"), + ("marketing_crm", "merged", "crm"), + ("multi_company", "removed"), + ("portal_claim", "renamed", "website_crm_claim"), + ("portal_project", "merged", "project"), + ("portal_project_issue", "merged", "project_issue"), + ("procurement_jit_stock", "merged", "procurement_jit"), + ("purchase_analytic_plans", "oca_moved", "purchase_analytic_distribution", + "Moved to OCA/account-analytic"), + ("purchase_double_validation", "removed"), + ("sale_analytic_plans", "oca_moved", "sale_analytic_distribution", + "Moved to OCA/account-analytic"), + ("sale_journal", "removed"), + ("share", "removed"), + ("stock_invoice_directly", "removed"), + ("web_api", "removed"), + ("web_gantt", "merged", "web"), + ("web_graph", "merged", "web"), + ("web_kanban_sparkline", "merged", "web"), + ("web_tests", "merged", "web"), + ("web_tests_demo", "removed"), + ("website_certification", "removed"), + ("website_instantclick", "removed"), + ("website_mail_group", "renamed", "website_mail_channel"), + ("website_report", "merged", "report"), +] diff --git a/odoo_migrate/migration_scripts/migrate_080_allways.py b/odoo_migrate/migration_scripts/migrate_080_allways.py index 55d83c4..85b315b 100644 --- a/odoo_migrate/migration_scripts/migrate_080_allways.py +++ b/odoo_migrate/migration_scripts/migrate_080_allways.py @@ -6,4 +6,8 @@ _TEXT_REPLACES = { ".py": {"from openerp": "from odoo", "import openerp": "import odoo"}, + ".xml": { + r"( |\t)*(\n| |\t)*": "", + r"( |\t)*<\/data>(\n| |\t)*<\/openerp>": "", + } } diff --git a/odoo_migrate/migration_scripts/migrate_090_100.py b/odoo_migrate/migration_scripts/migrate_090_100.py new file mode 100644 index 0000000..ea0b3a3 --- /dev/null +++ b/odoo_migrate/migration_scripts/migrate_090_100.py @@ -0,0 +1,38 @@ +# Copyright (C) 2019 - Today: GRAP (http://www.grap.coop) +# @author: Sylvain LE GAL (https://twitter.com/legalsylvain) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +_TEXT_REPLACES = { + "*": { + "base.group_configuration": "base.group_system", + "base.group_sale_salesman": "sales_team.group_sale_salesman", + "base.group_sale_salesman_all_leads": + "sales_team.group_sale_salesman_all_leads", + "base.group_sale_manager": "sales_team.group_sale_manager", + }, +} + +_DEPRECATED_MODULES = [ + ("account_extra_reports", "removed"), + ("account_full_reconcile", "removed"), + ("account_tax_adjustments", "removed"), + ("account_tax_exigible", "removed"), + ("claim_from_delivery", "removed"), + ("crm_claim", "removed"), + ("crm_partner_assign", "removed"), + ("im_odoo_support", "merged", "im_livechat"), + ("mail_tip", "merged", "mail"), + ("marketing", "merged", "marketing_campaign"), + ("mrp_operations", "merged", "mrp"), + ("product_uos", "removed"), + ("product_visible_discount", "removed"), + ("project_timesheet", "merged", "hr_timesheet"), + ("report_webkit", "removed"), + ("sale_layout", "merged", "sale"), + ("sale_service", "merged", "sale_timesheet"), + ("warning", "removed"), + ("web_analytics", "removed"), + ("web_tip", "removed"), + ("web_view_editor", "removed"), + ("website_crm_claim", "removed"), +] diff --git a/odoo_migrate/migration_scripts/migrate_100_110.py b/odoo_migrate/migration_scripts/migrate_100_110.py index aaa1602..c5fe6b6 100644 --- a/odoo_migrate/migration_scripts/migrate_100_110.py +++ b/odoo_migrate/migration_scripts/migrate_100_110.py @@ -2,6 +2,82 @@ # @author: Sylvain LE GAL (https://twitter.com/legalsylvain) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -_TEXT_WARNING = {"*": { - "ir.values": "[V11] Reference to 'ir.values'." - " This model has been removed."}} +# TODO: Call 2to3 + +_TEXT_REPLACES = { + "*": { + r"ir.actions.report.xml": "ir.actions.report", + r"report.external_layout": "web.external_layout", + r"report.html_container": "web.html_container", + r"report.layout": "web.report_layout", + r"report.minimal_layout": "web.minimal_layout", + }, + ".xml": { + r"kanban_state_selection": "state_selection", + } +} + +_TEXT_ERRORS = { + "*": { + "('|\")ir.values('|\")": + "[V11] Reference to 'ir.values'." + " This model has been removed.", + "('|\")workflow('|\")": + "[V11] Reference to 'workflow'." + " This model has been removed.", + "('|\")workflow.activity('|\")": + "[V11] Reference to 'workflow.activity'." + " This model has been removed.", + "('|\")workflow.instance('|\")": + "[V11] Reference to'workflow.instance'." + " This model has been removed.", + "('|\")workflow.transition('|\")": + "[V11] Reference to 'workflow.transition'." + " This model has been removed.", + "('|\")workflow.triggers('|\")": + "[V11] Reference to 'workflow.triggers'." + " This model has been removed.", + "('|\")workflow.workitem('|\")": + "[V11] Reference to 'workflow.workitem'." + " This model has been removed.", + "report.external_layout_header": + "report.external_layout_header is obsolete.", + "report.external_layout_footer": + "report.external_layout_footer is obsolete.", + }, + ".xml": { + "]*": + "color attribute is deprecated in tree view. Use decoration- instead.", + } +} + +_DEPRECATED_MODULES = [ + ("account_accountant", "removed"), + ("account_tax_cash_basis", "removed"), + ("base_action_rule", "renamed", "base_automation"), + ("crm_project_issue", "renamed", "crm_project_issue"), + ("hr_timesheet_sheet", "oca_moved", "hr_timesheet_sheet", + "Moved to OCA/hr-timesheet"), + ("marketing_campaign", "removed"), + ("marketing_campaign_crm_demo", "removed"), + ("portal_gamification", "merged", "gamification"), + ("portal_sale", "merged", "sale"), + ("portal_stock", "merged", "portal"), + ("procurement", "merged", "stock"), + ("project_issue", "merged", "project"), + ("project_issue_sheet", "merged", "hr_timesheet"), + ("rating_project_issue", "removed"), + ("report", "merged", "base"), + ("stock_calendar", "removed"), + ("stock_picking_wave", "renamed", "stock_picking_batch"), + ("subscription", "removed"), + ("web_calendar", "merged", "web"), + ("web_kanban", "merged", "web"), + ("website_issue", "renamed", "website_form_project"), + ("website_portal", "merged", "website"), + ("website_project", "merged", "project"), + ("website_project_issue", "merged", "project"), + ("website_project_timesheet", "merged", "hr_timesheet"), + ("website_rating_project_issue", "renamed", "website_rating_project"), + +] diff --git a/odoo_migrate/migration_scripts/migrate_100_allways.py b/odoo_migrate/migration_scripts/migrate_100_allways.py index 7de2a2c..99adf15 100644 --- a/odoo_migrate/migration_scripts/migrate_100_allways.py +++ b/odoo_migrate/migration_scripts/migrate_100_allways.py @@ -2,4 +2,4 @@ # @author: Sylvain LE GAL (https://twitter.com/legalsylvain) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -_TEXT_REPLACES = {".py": {r"#.+coding:\Wutf-8.+\n": ""}} +_TEXT_REPLACES = {".py": {r"# (-\*- )?coding: utf-8( -\*-)?\n": ""}} diff --git a/odoo_migrate/migration_scripts/migrate_110_120.py b/odoo_migrate/migration_scripts/migrate_110_120.py index 37e30f8..5e856fb 100644 --- a/odoo_migrate/migration_scripts/migrate_110_120.py +++ b/odoo_migrate/migration_scripts/migrate_110_120.py @@ -2,9 +2,42 @@ # @author: Sylvain LE GAL (https://twitter.com/legalsylvain) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +# TODO +# All