Skip to content

Commit

Permalink
version 0.1.3
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
legalsylvain committed Oct 11, 2019
1 parent 9d47b85 commit 180dfb8
Show file tree
Hide file tree
Showing 17 changed files with 209 additions and 135 deletions.
26 changes: 26 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
sudo: false
cache: pip

language: python

python:
- "3.6"

before_install:
# For tests running git command
- git config --global user.name "test"
- git config --global user.email "test.test@test.com"

# command to install dependencies
install:
- pip install -r requirements.txt
- pip install -r test_requirements.txt

# command to run tests
script:
- git --version
- flake8 . --exclude=__init__.py
- coverage run --source git_aggregator setup.py test

after_success:
- coveralls
7 changes: 7 additions & 0 deletions DEVELOP.rst
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,13 @@ How to improve the library
* Read (or complete !) the migration advices of the OCA.
https://github.com/OCA/maintainer-tools/wiki#migration

* Read the complementary pages
https://odoo-development.readthedocs.io/en/latest/migration/

* Discover what changed between two revisions, reading OpenUpgrade
documentation, specially the modules changes, for exemple:
https://github.com/OCA/OpenUpgrade/blob/12.0/odoo/openupgrade/doc/source/modules110-120.rst

* Create or complete the according migration file.

* Add tests.
Expand Down
16 changes: 16 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
:alt: License: AGPL-3
.. image:: https://img.shields.io/badge/python-3.6-blue.svg
:alt: Python support: 3.6
.. image:: https://travis-ci.org/grap/odoo-migrate.svg?branch=master
:target: https://travis-ci.org/grap/odoo-migrate
.. image:: https://coveralls.io/repos/grap/odoo-migrate/badge.png?branch=master
:target: https://coveralls.io/r/grap/odoo-migrate?branch=master

============
odoo-migrate
Expand Down Expand Up @@ -120,6 +124,9 @@ Available arguments
|``--log-level`` | ``-ll`` | Default: | Possible value: ``DEBUG``, ``INFO``, ``WARNING``, etc.|
| | | ``INFO`` | |
+--------------------------+----------+-----------------+-------------------------------------------------------+
|``--no-commit`` | ``-nc`` | Default: | If set the library will not git add and git commit |
| | | commit | changes. |
+--------------------------+----------+-----------------+-------------------------------------------------------+


Roadmap / Know issues
Expand All @@ -129,6 +136,14 @@ Roadmap / Know issues

* Add tests.

Changes
=======

0.1.2 (October 10, 2019)
------------------------

* First release

Credits
=======

Expand All @@ -141,3 +156,4 @@ Contributors
------------

* Sylvain LE GAL (https://www.twitter.com/legalsylvain)

73 changes: 11 additions & 62 deletions odoo_migrate/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,15 @@ def get_parser():
type=str,
)

main_parser.add_argument(
"-nc",
"--no-commit",
action='store_true',
default=False,
help="Enable this option, if you don't want that the library commits"
" the changes. (using git add and git commit command)"
)

return main_parser


Expand All @@ -111,73 +120,13 @@ def main():

migration = Migration(
args.directory, args.init_version_name, args.target_version_name,
module_names, args.format_patch, args.remote_name, args.force_black
module_names, args.format_patch, args.remote_name,
args.force_black, not args.no_commit,
)

# run Migration
migration.run()

# # Get Main path and test if exists
# root_path = Path(args.directory)
# if not root_path.exists():
# raise ValueError("'%s' is not a valid path." % (args.directory))

# # Recover modules list
# modules_path = []
# modules_list = args.modules\
# and [x for x in args.modules.split(",") if x] or []

# if not args.modules:
# # Recover all submodules, if no modules list is provided
# subfolders = [x for x in root_path.iterdir() if x.is_dir()]
# else:
# subfolders = [root_path / x for x in modules_list]

# # Recover code for former version, if asked
# if args.format_patch:
# if len(modules_list) != 1:
# raise ValueError(
# "If 'format-patch' option is enabled, you should provide"
# " a unique module name in the 'modules' argument.")
# migrate_tools._get_code_from_previous_branch(
# _logger, root_path, modules_list[0], args.init_version,
# args.target_version, args.remote_name)

# # check if each folder is a valid module or not
# for subfolder in subfolders:
# if (subfolder / "__openerp__.py").exists() or (
# subfolder / "__manifest__.py"
# ).exists():
# modules_path.append(subfolder)
# else:
# if modules_list:
# _logger.warning(
# "The module %s was not found in the directory %s"
# % (subfolder.name, args.directory)
# )

# if modules_path:
# _logger.debug(
# "The lib will process the following modules '%s'"
# % (", ".join([x.name for x in modules_path]))
# )
# else:
# _logger.error("No module found.")

# # Compute migration list
# migration_list = tools._get_migration_list(
# args.init_version, args.target_version
# )

# for module_path in modules_path:
# # Use black to clean the code
# if args.enable_black:
# pass

# # migrate modules
# migrate_tools._migrate_module(
# _logger, root_path, module_path, migration_list)

except KeyboardInterrupt:
pass

Expand Down
2 changes: 2 additions & 0 deletions odoo_migrate/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,5 @@
_ALLOWED_EXTENSIONS = [".py", ".xml", ".js"]

_BLACK_LINE_LENGTH = 79

_MANIFEST_NAMES = ["__openerp__.py", "__manifest__.py"]
15 changes: 8 additions & 7 deletions odoo_migrate/migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import pathlib
import pkgutil

from .config import _AVAILABLE_MIGRATION_STEPS
from .config import _AVAILABLE_MIGRATION_STEPS, _MANIFEST_NAMES
from .exception import ConfigException
from .log import logger
from .tools import _execute_shell, _get_latest_version_code
Expand All @@ -21,16 +21,18 @@ class Migration():
_use_black = False
_migration_scripts = []
_module_migrations = []
_commit_enabled = True

def __init__(
self, relative_directory_path, init_version_name, target_version_name,
module_names=[], format_patch=False, remote_name='origin',
force_black=False
force_black=False, commit_enabled=True,
):
pass
self._use_black = force_black
self._commit_enabled = commit_enabled

# Get migration steps that will be runned
found = False
self._use_black = force_black
for item in _AVAILABLE_MIGRATION_STEPS:
if not found and item["init_version_name"] != init_version_name:
continue
Expand Down Expand Up @@ -94,8 +96,7 @@ def __init__(
self._get_migration_scripts()

def _is_module_path(self, module_path):
return (module_path / "__openerp__.py").exists() or\
(module_path / "__manifest__.py").exists()
return any([(module_path / x).exists() for x in _MANIFEST_NAMES])

def _get_code_from_previous_branch(self, module_name, remote_name):
init_version = self._migration_steps[0]["init_version_name"]
Expand Down Expand Up @@ -170,7 +171,7 @@ def _get_migration_scripts(self):
[x.__file__.split('/')[-1] for x in self._migration_scripts]))

def run(self):
logger.info(
logger.debug(
"Running migration from: %s to: %s in '%s'" % (
self._migration_steps[0]["init_version_name"],
self._migration_steps[-1]["target_version_name"],
Expand Down
4 changes: 4 additions & 0 deletions odoo_migrate/migration_scripts/migrate_080_090.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 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",
Expand Down
4 changes: 4 additions & 0 deletions odoo_migrate/migration_scripts/migrate_080_allways.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 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).

_FILE_RENAMES = {"__openerp__.py": "__manifest__.py"}

_TEXT_REPLACES = {
Expand Down
9 changes: 7 additions & 2 deletions odoo_migrate/migration_scripts/migrate_100_110.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
_TEXT_WARNING = {"*": {"ir.values": "'ir.values' found."
" This model has been removed in V11."}}
# 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_WARNING = {"*": {
"ir.values": "[V11] Reference to 'ir.values'."
" This model has been removed."}}
4 changes: 4 additions & 0 deletions odoo_migrate/migration_scripts/migrate_100_allways.py
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
# 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 = {".py": {r"#.+coding:\Wutf-8.+\n": ""}}
4 changes: 4 additions & 0 deletions odoo_migrate/migration_scripts/migrate_110_120.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 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 = {
".py": {
"from odoo.addons.base.res": "from odoo.addons.base.models",
Expand Down
7 changes: 7 additions & 0 deletions odoo_migrate/migration_scripts/migrate_120_130.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# 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_WARNING = {"*": {
"web_settings_dashboard": "[V13] Reference to 'web_settings_dashboard'"
". This module has been removed."}}
33 changes: 30 additions & 3 deletions odoo_migrate/migration_scripts/migrate_allways.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,34 @@
# Bump Module version
# Switch the installable key to True
# 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).

import os
import subprocess


def bump_revision(**kwargs):
tools = kwargs['tools']
manifest_path = kwargs['manifest_path']
target_version_name = kwargs['migration_steps'][-1]["target_version_name"]

new_version = "%s.1.0.0" % target_version_name

old_term = r"('|\")version('|\").*('|\").*('|\")"
new_term = r'\1version\2: "{0}"'.format(new_version)
tools._replace_in_file(
manifest_path, {old_term: new_term},
"Bump version to %s" % new_version)


def set_module_installable(**kwargs):
tools = kwargs['tools']
manifest_path = kwargs['manifest_path']
old_term = r"('|\")installable('|\").*(False)"
new_term = r"\1installable\2: True"
tools._replace_in_file(
manifest_path, {old_term: new_term}, "Set module installable")


def remove_migration_folder(**kwargs):
logger = kwargs['logger']
module_path = kwargs['module_path']
Expand All @@ -14,4 +39,6 @@ def remove_migration_folder(**kwargs):
module_name))
subprocess.check_output("rm -r %s" % migration_path_folder, shell=True)

_GLOBAL_FUNCTIONS = [remove_migration_folder]

_GLOBAL_FUNCTIONS = [
remove_migration_folder, set_module_installable, bump_revision]
Loading

0 comments on commit 180dfb8

Please sign in to comment.