Compare commits

...

21 Commits

Author SHA1 Message Date
Sylvain LE GAL
7daa04688f fixup! fixup! fixup! fixup! fixup! fixup! fixup! [TRY] fix CI 2022-03-28 22:10:34 +02:00
Sylvain LE GAL
2668e54fb0 fixup! fixup! fixup! fixup! fixup! fixup! [TRY] fix CI 2022-03-28 21:43:20 +02:00
Sylvain LE GAL
930f9f8dd7 fixup! fixup! fixup! fixup! fixup! [TRY] fix CI 2022-03-28 21:35:19 +02:00
Sylvain LE GAL
e8a7e7fdc8 fixup! fixup! fixup! fixup! [TRY] fix CI 2022-03-28 21:27:19 +02:00
Sylvain LE GAL
c362390902 fixup! fixup! fixup! [TRY] fix CI 2022-03-28 21:23:04 +02:00
Sylvain LE GAL
906c0f3ea7 fixup! fixup! [TRY] fix CI 2022-03-28 21:18:35 +02:00
Sylvain LE GAL
dd08967f5e fixup! [TRY] fix CI 2022-03-28 21:12:54 +02:00
Sylvain LE GAL
6c3c555286 [TRY] fix CI 2022-03-28 21:08:39 +02:00
Sylvain LE GAL
7580a93023 fixup! [FIX] use virtualenv command instead of cli 2022-03-28 21:03:50 +02:00
Sylvain LE GAL
613eeb9d93 [FIX] use virtualenv command instead of cli 2022-03-28 20:55:01 +02:00
Sylvain LE GAL
c069757168 [ADD] virtualenv creation 2022-03-28 16:59:36 +02:00
Sylvain LE GAL
a27fcabbba [FIX] black 2022-03-28 15:30:19 +02:00
Sylvain LE GAL
e298b73efb [ADD] pyttest.ini file + test for cli_build 2022-03-28 15:08:58 +02:00
Sylvain LE GAL
4d144d557f [ADD] call to gitaggregate 2022-03-28 15:08:16 +02:00
Sylvain LE GAL
f78f0677ae fixup! [REF] add ensure_file_exists_from_template function 2022-03-28 13:45:47 +02:00
Sylvain LE GAL
5f14b50a31 [REF] add ensure_file_exists_from_template function 2022-03-28 13:23:08 +02:00
Sylvain LE GAL
1d52b51b54 fixup! [REF] add ensure_folder_exists system 2022-03-28 12:49:02 +02:00
Sylvain LE GAL
507d368b30 [REF] add ensure_folder_exists system 2022-03-28 12:46:07 +02:00
Sylvain LE GAL
5c98761086 WIP 2022-03-28 12:11:06 +02:00
Sylvain LE GAL
e81e22e91b Work in Progress 2022-03-28 10:21:01 +02:00
Sylvain LE GAL
d64140487f WIP 2022-03-25 18:27:18 +01:00
20 changed files with 2142 additions and 74 deletions

7
.gitignore vendored Normal file
View File

@ -0,0 +1,7 @@
env
__pycache__
.tox
.coverage
.pytest_cache
/tests/output/*
log/

69
.gitlab-ci.yml Normal file
View File

@ -0,0 +1,69 @@
---
image: python3.6
cache:
key: one-key-to-rule-them-all
paths:
- .venv
stages:
- prepare
- linting
- tests
install_tools:
stage: prepare
script:
- python -m venv .venv
- source .venv/bin/activate
- pip install poetry
- poetry --version
- poetry install -v
- echo $PATH
- echo $PYTHONPATH
black:
stage: linting
script:
# Intall pipx to install black
# otherwise, it fails.
# TODO, check with Coop It Easy
- pip install --user pipx
- python -m pipx ensurepath
- source ~/.profile
# Classic CI
- pipx install black
- black --version
- black --check .
pylint:
stage: linting
script:
- source .venv/bin/activate
- pylint --version
pytest:
stage: tests
image: python
cache: {}
script:
# Install python3.6, because it is required to
# run virtualenv of odoo 14.0
- apt-get install python3.6
# Classic CI
- pip install poetry
- poetry --version
- poetry install -v
- poetry run pytest --version
- poetry run pytest --cov odoo_openupgrade_wizard -v
tox:
stage: tests
image: themattrix/tox
cache: {}
script:
- pip install poetry tox
- tox --version
- poetry --version
- tox

36
.pre-commit-config.yaml Normal file
View File

@ -0,0 +1,36 @@
---
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.4.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: debug-statements
- id: mixed-line-ending
- id: name-tests-test
- id: check-yaml
- id: check-json
- id: check-toml
- id: check-added-large-files
args: ['--maxkb=2048']
- id: check-docstring-first
- id: check-merge-conflict
- id: check-symlinks
- repo: https://github.com/pre-commit/mirrors-isort
rev: v5.7.0
hooks:
- id: isort
- repo: https://github.com/psf/black
rev: 20.8b1
hooks:
- id: black
- repo: https://github.com/PyCQA/flake8
rev: "3.9.2"
hooks:
- id: flake8
# - repo: https://gitlab.com/smop/pre-commit-hooks
# rev: v1.0.0
# hooks:
# - id: check-gitlab-ci

40
DEVELOP.md Normal file
View File

@ -0,0 +1,40 @@
# Requirements
TODO (poetry, etc...)
# Installation
```
git clone https://gitlab.com/odoo-openupgrade-wizard/odoo-openupgrade-wizard/
cd odoo-openupgrade-wizard
virtualenv env --python=python3.X
. ./env/bin/activate
poetry install
```
Note : ``python3.X`` should be >= to ``python3.6``
``odoo-openupgrade-wizard`` commands are now available in your virutalenv.
# Run tests
## Via pytest
This will run tests only for the current ``python3.X`` version.
(in your virtualenv)
```
poetry run pytest --cov odoo_openupgrade_wizard -v
```
## Via Tox
This will run tests for all the python versions put in the ``tox.ini`` folder.
(in your virtualenv)
```
tox
```
Note : you should have all the python versions available in your local system.
# Structure of the project

138
README.md
View File

@ -1,92 +1,82 @@
# odoo-openupgrade-wizard
Odoo Openupgrade Wizard is a tool that helps developpers to make major
upgrade of Odoo Community Edition. (formely OpenERP).
It works with Openupgrade OCA tools. (https://github.com/oca/openupgrade)
this tool is useful for complex migrations:
- skip several versions
- complex custom code
## Getting started
It will create a migration environment (with all the code available)
and provides helpers to run (and replay) migrations until it works.
To make it easy for you to get started with GitLab, here's a list of recommended next steps.
## Commands
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
## Add your files
- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
### ``odoo-openupgrade-wizard init``
```
cd existing_repo
git remote add origin https://gitlab.com/odoo-openupgrade-wizard/odoo-openupgrade-wizard.git
git branch -M main
git push -uf origin main
odoo-openupgrade-wizard init\
--initial-version=10.0\
--final-version=12.0\
--extra-repository=OCA/web,OCA/server-tools
```
## Integrate with your tools
Initialize a folder to make a migration from a 10.0 and a 12.0 database.
This will generate the following structure :
- [ ] [Set up project integrations](https://gitlab.com/odoo-openupgrade-wizard/odoo-openupgrade-wizard/-/settings/integrations)
```
config.yml
log/
2022_03_25__23_12_41__init.log
...
repos/
10.0.yml
11.0.yml
12.0.yml
requirements/
10.0_requirements.txt
11.0_requirements.txt
12.0_requirements.txt
scripts/
step_1__update__10.0/
pre-migration.sql
post-migration.py
step_2__upgrade__11.0/
pre-migration.sql
post-migration.py
step_2__upgrade__12.0/
pre-migration.sql
post-migration.py
step_4__update__12.0/
pre-migration.sql
post-migration.py
src/
```
## Collaborate with your team
* ``log/`` will contains all the log of the ``odoo-openupgrade-wizard``
and the logs of the odoo instance that will be executed.
- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
- [ ] [Automatically merge when pipeline succeeds](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
## Test and Deploy
* ``repos/`` contains a file per version of odoo, that enumerates the
list of the repositories to use to run each odoo instance.
The syntax should respect the ``gitaggregate`` command.
(See : https://pypi.org/project/git-aggregator/)
Repo files are pre-generated. You can update them with your custom settings.
(custom branches, extra PRs, git shallow options, etc...)
Use the built-in continuous integration in GitLab.
* ``requirements/`` contains a file per version of odoo, that enumerates the
list of extra python librairies required to run each odoo instance.
The syntax should respect the ``pip install -r`` command.
(See : https://pip.pypa.io/en/stable/reference/requirements-file-format/)
- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html)
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing(SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
* ``scripts`` contains a folder per migration step. In each step folder:
- ``pre-migration.sql`` can contains extra SQL queries you want to execute
before beginning the step.
- ``post-migration.py`` can contains extra python command to execute
after the execution of the step. (the orm will be available)
***
# TODO
# Editing this README
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to [makeareadme.com](https://www.makeareadme.com/) for this template.
## Suggestions for a good README
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
## Name
Choose a self-explaining name for your project.
## Description
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
## Badges
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
## Visuals
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
## Installation
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
## Usage
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
## Support
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
## Roadmap
If you have ideas for releases in the future, it is a good idea to list them in the README.
## Contributing
State if you are open to contributions and what your requirements are for accepting them.
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
## Authors and acknowledgment
Show your appreciation to those who have contributed to the project.
## License
For open source projects, say how it is licensed.
## Project status
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
* with coop it easy :
- short_help of group decorator ? seems useless...

View File

@ -0,0 +1,5 @@
from pathlib import Path
from single_source import get_version
__version__ = get_version(__name__, Path(__file__).parent.parent)

View File

@ -0,0 +1,5 @@
"""Executed when module is run as a script."""
from odoo_openupgrade_wizard import cli
cli.main() # pylint: disable=no-value-for-parameter

View File

@ -0,0 +1,97 @@
import datetime
from pathlib import Path
import click
import yaml
from loguru import logger
import odoo_openupgrade_wizard
from odoo_openupgrade_wizard.cli_build import build
from odoo_openupgrade_wizard.cli_init import init
from odoo_openupgrade_wizard.tools_system import ensure_folder_exists
@click.group()
@click.version_option(version=odoo_openupgrade_wizard.__version__)
@click.option(
"-ef",
"--env-folder",
default="./",
type=click.Path(
exists=True,
dir_okay=True,
file_okay=False,
writable=True,
resolve_path=True,
),
help="Folder that will contains all the configuration of the wizard"
" and all the Odoo code required to make the migrations. Let empty to"
" use current folder (./).",
)
@click.option(
"-fs",
"--filestore-folder",
type=click.Path(dir_okay=True, file_okay=False, resolve_path=True),
help="Folder that contains the Odoo filestore of the database(s)"
" to migrate. Let empty to use the subfolder 'filestore' of the"
" environment folder.",
)
@click.pass_context
def main(ctx, env_folder, filestore_folder):
"""
Provides a command set to perform odoo Community Edition migrations.
"""
date_begin = datetime.datetime.now()
logger.debug("Beginning script '%s' ..." % (ctx.invoked_subcommand))
if not isinstance(ctx.obj, dict):
ctx.obj = {}
# Define all the folder required by the tools
env_folder_path = Path(env_folder)
src_folder_path = env_folder_path / Path("./src/")
repo_folder_path = env_folder_path / Path("./repos/")
requirement_folder_path = env_folder_path / Path("./requirements/")
script_folder_path = env_folder_path / Path("./scripts/")
config_file_path = env_folder_path / Path("config.yml")
log_folder_path = env_folder_path / Path("./log/")
if not filestore_folder:
filestore_folder_path = env_folder_path / Path("./filestore/")
else:
filestore_folder_path = Path(filestore_folder)
# ensure log folder exists
ensure_folder_exists(log_folder_path)
# Create log file
log_file_path = log_folder_path / Path(
"{}__{}.log".format(
date_begin.strftime("%Y_%m_%d__%H_%M_%S"), ctx.invoked_subcommand
)
)
logger.add(log_file_path)
# Add all global values in the context
ctx.obj["env_folder_path"] = env_folder_path
ctx.obj["src_folder_path"] = src_folder_path
ctx.obj["repo_folder_path"] = repo_folder_path
ctx.obj["script_folder_path"] = script_folder_path
ctx.obj["filestore_folder_path"] = filestore_folder_path
ctx.obj["config_file_path"] = config_file_path
ctx.obj["requirement_folder_path"] = requirement_folder_path
# Load the main configuration file
if config_file_path.exists():
with open(config_file_path) as file:
config = yaml.safe_load(file)
for step in config["migration_steps"]:
step["local_path"] = src_folder_path / Path(
"env_%s" % step["version"]
)
ctx.obj["config"] = config
elif ctx.invoked_subcommand != "init":
raise
main.add_command(init)
main.add_command(build)

View File

@ -0,0 +1,32 @@
import click
from odoo_openupgrade_wizard.configuration_version_dependant import (
_get_repo_file,
)
from odoo_openupgrade_wizard.tools_system import (
create_virtualenv,
ensure_folder_exists,
git_aggregate,
)
@click.command()
@click.pass_context
def build(ctx):
"""
Build OpenUpgrade Wizard Environment:
- gitaggregate all the repositories
- build virtualenv (TODO)
"""
# distinct_versions = list(set(x["version"] for x in series))
for step in ctx.obj["config"]["migration_steps"]:
# 1. Create main folder for the odoo version
ensure_folder_exists(step["local_path"], mode="777")
# 2. Create virtual environment
create_virtualenv(step["local_path"], step["python"])
# 3. gitaggregate source code
git_aggregate(step["local_path"], _get_repo_file(ctx, step))

View File

@ -0,0 +1,149 @@
from pathlib import Path
import click
from odoo_openupgrade_wizard.configuration_version_dependant import (
_get_odoo_version_str_list,
_get_odoo_versions,
)
from odoo_openupgrade_wizard.templates import (
_CONFIG_YML_TEMPLATE,
_POST_MIGRATION_PY_TEMPLATE,
_PRE_MIGRATION_SQL_TEMPLATE,
_REPO_YML_TEMPLATE,
_REQUIREMENTS_TXT_TEMPLATE,
)
from odoo_openupgrade_wizard.tools_system import (
ensure_file_exists_from_template,
ensure_folder_exists,
)
@click.command()
@click.option(
"-iv",
"--initial-version",
required=True,
prompt=True,
type=click.Choice(_get_odoo_version_str_list("initial")),
)
@click.option(
"-fv",
"--final-version",
required=True,
prompt=True,
type=click.Choice(_get_odoo_version_str_list("final")),
)
@click.option(
"-er",
"--extra-repository",
"extra_repository_list",
# TODO, add a callback to check the quality of the argument
help="Coma separated extra repositories to use in the odoo environment."
"Ex: 'OCA/web,OCA/server-tools,GRAP/grap-odoo-incubator'",
)
@click.pass_context
def init(ctx, initial_version, final_version, extra_repository_list):
"""
Initialize OpenUpgrade Wizard Environment based on the initial and
the final version of Odoo you want to migrate.
"""
if extra_repository_list:
extra_repositories = extra_repository_list.split(",")
else:
extra_repositories = []
# 1. create steps from series given as argument
series = _get_odoo_versions(float(initial_version), float(final_version))
distinct_versions = list(set(x["version"] for x in series))
# Create initial first step
steps = [series[0].copy()]
steps[0].update(
{
"name": "step_1",
"action": "update",
"complete_name": "step_1__update__%s" % (steps[0]["version"]),
}
)
# Add all upgrade steps
count = 1
for serie in series[1:]:
steps.append(serie.copy())
steps[count].update(
{
"name": "step_%d" % (count + 1),
"action": "upgrade",
"complete_name": "step_%d__upgrade__%s"
% (count + 1, serie["version"]),
}
)
count += 1
# add final update step
steps.append(series[-1].copy())
steps[-1].update(
{
"name": "step_%d" % (count + 1),
"action": "update",
"complete_name": "step_%d__update__%s"
% (count + 1, steps[-1]["version"]),
}
)
# 2. ensure src folder exists
ensure_folder_exists(ctx.obj["src_folder_path"], mode="777")
# 3. ensure filestore folder exists
ensure_folder_exists(ctx.obj["filestore_folder_path"], mode="777")
# 4. ensure main configuration file exists
ensure_file_exists_from_template(
ctx.obj["config_file_path"], _CONFIG_YML_TEMPLATE, steps=steps
)
# 4. Create Repo folder and files
ensure_folder_exists(ctx.obj["repo_folder_path"])
orgs = {x: [] for x in set([x.split("/")[0] for x in extra_repositories])}
for extra_repository in extra_repositories:
org, repo = extra_repository.split("/")
orgs[org].append(repo)
for version in distinct_versions:
ensure_file_exists_from_template(
ctx.obj["repo_folder_path"] / Path("%s.yml" % (version)),
_REPO_YML_TEMPLATE,
version=version,
orgs=orgs,
)
# 5. Create Requirements folder and files
ensure_folder_exists(ctx.obj["requirement_folder_path"])
for serie in series:
ensure_file_exists_from_template(
ctx.obj["requirement_folder_path"]
/ Path("%s_requirements.txt" % (serie["version"])),
_REQUIREMENTS_TXT_TEMPLATE,
python_libraries=serie["python_libraries"],
)
# 6. Create Scripts folder and files
ensure_folder_exists(ctx.obj["script_folder_path"])
for step in steps:
step_path = ctx.obj["script_folder_path"] / step["complete_name"]
ensure_folder_exists(step_path)
ensure_file_exists_from_template(
step_path / Path("pre-migration.sql"),
_PRE_MIGRATION_SQL_TEMPLATE,
)
ensure_file_exists_from_template(
step_path / Path("post-migration.py"),
_POST_MIGRATION_PY_TEMPLATE,
)

View File

@ -0,0 +1,83 @@
from pathlib import Path
# List of the series of odoo
# python version is defined, based on the OCA CI.
# https://github.com/OCA/oca-addons-repo-template/blob/master/src/.github/workflows/%7B%25%20if%20ci%20%3D%3D%20'GitHub'%20%25%7Dtest.yml%7B%25%20endif%20%25%7D.jinja
_ODOO_SERIES = [
{
"version": 6.0,
"python": "python2.7",
"python_libraries": ["openupgradelib"],
},
{
"version": 6.1,
"python": "python2.7",
"python_libraries": ["openupgradelib"],
},
{
"version": 7.0,
"python": "python2.7",
"python_libraries": ["openupgradelib"],
},
{
"version": 8.0,
"python": "python2.7",
"python_libraries": ["openupgradelib"],
},
{
"version": 9.0,
"python": "python2.7",
"python_libraries": ["openupgradelib"],
},
{
"version": 10.0,
"python": "python2.7",
"python_libraries": ["openupgradelib"],
},
{
"version": 11.0,
"python": "python3.5",
"python_libraries": ["openupgradelib"],
},
{
"version": 12.0,
"python": "python3.6",
"python_libraries": ["openupgradelib"],
},
{
"version": 13.0,
"python": "python3.6",
"python_libraries": ["openupgradelib"],
},
{
"version": 14.0,
"python": "python3.6",
"python_libraries": ["openupgradelib"],
},
{
"version": 15.0,
"python": "python3.8",
"python_libraries": ["openupgradelib"],
},
]
def _get_odoo_version_str_list(mode):
serie_list = [x["version"] for x in _ODOO_SERIES]
if mode == "initial":
serie_list = serie_list[:-1]
if mode == "final":
serie_list = serie_list[1:]
return [str(x) for x in serie_list]
def _get_odoo_versions(initial, final):
result = []
for serie in _ODOO_SERIES:
if serie["version"] >= initial and serie["version"] <= final:
result.append(serie)
return result
def _get_repo_file(ctx, step):
return ctx.obj["repo_folder_path"] / Path("%s.yml" % (step["version"]))

View File

@ -0,0 +1,67 @@
_CONFIG_YML_TEMPLATE = """migration_steps:
{% for step in steps %}
- name: {{ step['name'] }}
complete_name: {{ step['complete_name'] }}
version: {{ step['version'] }}
action: {{ step['action'] }}
python: {{ step['python'] }}
{% endfor %}
"""
_REPO_YML_TEMPLATE = """
##############################################################################
## Odoo Repository
##############################################################################
./src/odoo:
defaults:
depth: 1
remotes:
odoo: https://github.com/odoo/odoo
target: odoo {{ version }}-target
merges:
- odoo {{ version }}
##############################################################################
## OpenUpgrade Repository
##############################################################################
./src/openupgrade:
defaults:
depth: 1
remotes:
OCA: https://github.com/OCA/OpenUpgrade
target: OCA {{ version }}-target
merges:
- OCA {{ version }}
{% for org_name, repo_list in orgs.items() %}
##############################################################################
## {{ org_name }} Repositories
##############################################################################
{% for repo in repo_list %}
./src/{{ org_name }}/{{ repo }}:
defaults:
depth: 1
remotes:
{{ org_name }}: https://github.com/{{ org_name }}/{{ repo }}
target: {{ org_name }} {{ version }}-target
merges:
- {{ org_name }} {{ version }}
{% endfor %}
{% endfor %}
"""
_REQUIREMENTS_TXT_TEMPLATE = """
{%- for python_librairy in python_libraries -%}
{{ python_librairy }}
{% endfor %}
"""
_PRE_MIGRATION_SQL_TEMPLATE = ""
_POST_MIGRATION_PY_TEMPLATE = """
def main(self, step):
pass
"""

View File

@ -0,0 +1,81 @@
import argparse
import os
from git_aggregator import main as gitaggregate_cmd
from git_aggregator.utils import working_directory_keeper
from jinja2 import Template
from loguru import logger
from plumbum import local
from plumbum.cmd import mkdir
from virtualenv.run import cli_run as virtualenv_cmd
def ensure_folder_exists(folder_path, mode=False):
"""Create a local folder.
- directory is created if it doesn't exist.
- mode is applied if defined.
- a log is done at INFO level.
"""
if not folder_path.exists():
cmd = ["--parents", folder_path]
if mode:
cmd = ["--mode", "777"] + cmd
logger.info("Creating folder '%s' ..." % (folder_path))
mkdir(cmd)
def ensure_file_exists_from_template(file_path, template_name, **args):
template = Template(template_name)
output = template.render(args)
if file_path.exists():
# Check if content is different
with open(file_path, "r") as file:
data = file.read()
file.close()
if data == output:
return
log_text = "Updating file '%s' from template ..." % (file_path)
else:
log_text = "Creating file '%s' from template ..." % (file_path)
with open(file_path, "w") as f:
logger.info(log_text)
f.write(output)
f.close()
def git_aggregate(folder_path, config_path):
args = argparse.Namespace(
command="aggregate",
config=str(config_path),
jobs=1,
dirmatch=None,
do_push=False,
expand_env=False,
env_file=None,
force=False,
)
with working_directory_keeper:
os.chdir(folder_path)
logger.info(
"Gitaggregate source code for %s. This can take a while ..."
% config_path
)
gitaggregate_cmd.run(args)
def create_virtualenv(folder_path, python_version):
"""
Create a virtual env named ``env`` in the ``folder_path`` folder
with the given ``python_version``.
"""
with local.cwd(folder_path):
logger.info(
"Create Virtual Env in %s with version %s"
% (folder_path, python_version)
)
virtualenv_cmd(["env", "--python", python_version])

1229
poetry.lock generated Normal file

File diff suppressed because it is too large Load Diff

66
pyproject.toml Normal file
View File

@ -0,0 +1,66 @@
[tool.poetry]
name = "odoo-openupgrade-wizard"
version = "0.0.1"
description = "CLI tool to manage Odoo Major Upgrades"
authors = [
"GRAP, Groupement Régional Alimentaire de Proximité",
"Coop IT Easy SCRLfs",
]
maintainers = [
"Sylvain LE GAL",
]
license = "AGPLv3+"
readme = "README.md"
repository = "https://gitlab.com/odoo-openupgrade-wizard/odoo-openupgrade-wizard"
keywords = ["cli", "odoo", "openupgrade"]
classifiers = [
"Intended Audience :: Developers",
"Development Status :: 2 - Pre-Alpha",
"Operating System :: Unix",
"Programming Language :: Python :: 3",
"Framework :: Odoo",
]
[tool.poetry.scripts]
odoo-openupgrade-wizard = "odoo_openupgrade_wizard.cli:main"
[tool.poetry.dependencies]
python = "^3.6"
click = "^7.0"
loguru = "^0.6"
plumbum = "^1.7"
single-source = "^0.3"
virtualenv = "^20.14"
git-aggregator = "^2.1"
pyyaml = "5.4.1"
[tool.poetry.dev-dependencies]
pytest = [
{version = "<=6.1.2", python = "<3.10"},
{version = ">=6.2.5", python = ">=3.10"}
]
pytest-cov = "*"
safety = "*"
pylint = "*"
tox = "*"
towncrier = "*"
[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
[tool.towncrier]
package = "ociedoo"
package_dir = "ociedoo"
filename = "CHANGES.rst"
directory = "newsfragments"
title_format = "{version} ({project_date})"
wrap = 72
[tool.black]
line-length = 79
[tool.isort]
profile = "black"
line_length = 79

2
pytest.ini Normal file
View File

@ -0,0 +1,2 @@
[pytest]
norecursedirs = output/*

39
tests/cli_build_test.py Normal file
View File

@ -0,0 +1,39 @@
from pathlib import Path
from click.testing import CliRunner
from plumbum.cmd import mkdir
from odoo_openupgrade_wizard.cli import main
def test_cli_build():
output_folder_path = Path("./tests/output")
mkdir([output_folder_path, "--parents"])
# We initialize an env with only one version to avoid to git clone
# large data
CliRunner().invoke(
main,
[
"--env-folder=%s" % output_folder_path,
"init",
"--initial-version=14.0",
"--final-version=14.0",
"--extra-repository=OCA/web",
],
)
result = CliRunner().invoke(
main,
[
"--env-folder=%s" % output_folder_path,
"build",
],
)
assert result.exit_code == 0
openupgrade_path = Path("./tests/output/src/env_14.0/src/openupgrade")
assert openupgrade_path.exists()
assert (openupgrade_path / Path("openupgrade_framework")).exists()

30
tests/cli_init_test.py Normal file
View File

@ -0,0 +1,30 @@
import filecmp
from pathlib import Path
from click.testing import CliRunner
from plumbum.cmd import mkdir
from odoo_openupgrade_wizard.cli import main
def test_cli_init():
output_folder_path = Path("./tests/output")
expected_folder_path = Path("./tests/output_expected")
mkdir([output_folder_path, "--parents"])
result = CliRunner().invoke(
main,
[
"--env-folder=%s" % output_folder_path,
"init",
"--initial-version=9.0",
"--final-version=12.0",
"--extra-repository="
"OCA/web,OCA/server-tools,GRAP/grap-odoo-incubator",
],
)
assert result.exit_code == 0
assert filecmp.cmp(
output_folder_path / Path("config.yml"),
expected_folder_path / Path("config.yml"),
)

View File

@ -0,0 +1,31 @@
migration_steps:
- name: step_1
complete_name: step_1__update__9.0
version: 9.0
action: update
python: python2.7
- name: step_2
complete_name: step_2__upgrade__10.0
version: 10.0
action: upgrade
python: python2.7
- name: step_3
complete_name: step_3__upgrade__11.0
version: 11.0
action: upgrade
python: python3.5
- name: step_4
complete_name: step_4__upgrade__12.0
version: 12.0
action: upgrade
python: python3.6
- name: step_5
complete_name: step_5__update__12.0
version: 12.0
action: update
python: python3.6

10
tox.ini Normal file
View File

@ -0,0 +1,10 @@
[tox]
isolated_build = true
skipsdist = True
envlist = py36, py37, py38
[testenv]
whitelist_externals = poetry
commands =
poetry install -v
poetry run pytest -vv