Skip to content

Commit

Permalink
[WIP] Add test (#3)
Browse files Browse the repository at this point in the history
* Framework
[ADD] ``--file-path`` option.
[ADD] ``_DEPRECATED_MODULES`` syntax.

* Meta
[ADD] test files.

* 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
  • Loading branch information
legalsylvain committed Oct 13, 2019
1 parent 180dfb8 commit 6dc83a3
Show file tree
Hide file tree
Showing 35 changed files with 663 additions and 76 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# odoo-module-migrator

data_tmp/

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
24 changes: 22 additions & 2 deletions DEVELOP.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
==========================

Expand Down
73 changes: 67 additions & 6 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
==========================
Expand Down Expand Up @@ -132,13 +156,50 @@ Available arguments
Roadmap / Know issues
=====================

* Complete migration scripts.

* Add tests.
* replacement of tag <openerp><data> by <odoo> will fail in the case
where there are many <data> 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)
------------------------

Expand Down
20 changes: 14 additions & 6 deletions odoo_migrate/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand All @@ -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
Expand All @@ -132,4 +140,4 @@ def main():


if __name__ == "__main__":
main()
main(sys.argv[1:])
13 changes: 8 additions & 5 deletions odoo_migrate/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand All @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions odoo_migrate/migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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(
Expand Down
Empty file.
63 changes: 56 additions & 7 deletions odoo_migrate/migration_scripts/migrate_080_090.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
]
4 changes: 4 additions & 0 deletions odoo_migrate/migration_scripts/migrate_080_allways.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@

_TEXT_REPLACES = {
".py": {"from openerp": "from odoo", "import openerp": "import odoo"},
".xml": {
r"( |\t)*<openerp>(\n| |\t)*<data>": "<odoo>",
r"( |\t)*<\/data>(\n| |\t)*<\/openerp>": "</odoo>",
}
}
38 changes: 38 additions & 0 deletions odoo_migrate/migration_scripts/migrate_090_100.py
Original file line number Diff line number Diff line change
@@ -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"),
]
Loading

0 comments on commit 6dc83a3

Please sign in to comment.