Merge branch 'test' into 'main'
PR#1 See merge request odoo-openupgrade-wizard/odoo-openupgrade-wizard!1
This commit is contained in:
commit
74df2437eb
8
.gitignore
vendored
Normal file
8
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
env
|
||||
__pycache__
|
||||
.tox
|
||||
.coverage
|
||||
.pytest_cache
|
||||
/tests/output_01/*
|
||||
/tests/output_02/*
|
||||
log/
|
||||
67
.gitlab-ci.yml
Normal file
67
.gitlab-ci.yml
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
---
|
||||
image: python
|
||||
|
||||
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
|
||||
- pipx install black
|
||||
# Classic CI
|
||||
- black --version
|
||||
- black --check .
|
||||
|
||||
pylint:
|
||||
stage: linting
|
||||
script:
|
||||
- source .venv/bin/activate
|
||||
- pylint --version
|
||||
# - pylint --disable fixme ociedoo
|
||||
# - pylint --disable fixme tests
|
||||
|
||||
pytest:
|
||||
stage: tests
|
||||
image: python
|
||||
cache: {}
|
||||
script:
|
||||
- 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
36
.pre-commit-config.yaml
Normal 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
40
DEVELOP.md
Normal 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
138
README.md
|
|
@ -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...
|
||||
|
|
|
|||
5
odoo_openupgrade_wizard/__init__.py
Normal file
5
odoo_openupgrade_wizard/__init__.py
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
from pathlib import Path
|
||||
|
||||
from single_source import get_version
|
||||
|
||||
__version__ = get_version(__name__, Path(__file__).parent.parent)
|
||||
5
odoo_openupgrade_wizard/__main__.py
Normal file
5
odoo_openupgrade_wizard/__main__.py
Normal 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
|
||||
95
odoo_openupgrade_wizard/cli.py
Normal file
95
odoo_openupgrade_wizard/cli.py
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
import datetime
|
||||
from pathlib import Path
|
||||
|
||||
import click
|
||||
import yaml
|
||||
from loguru import logger
|
||||
|
||||
import odoo_openupgrade_wizard
|
||||
from odoo_openupgrade_wizard.cli_get_code import get_code
|
||||
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/")
|
||||
script_folder_path = env_folder_path / Path("./scripts/")
|
||||
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)
|
||||
|
||||
config_file_path = env_folder_path / Path("config.yml")
|
||||
|
||||
# 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["script_folder_path"] = script_folder_path
|
||||
ctx.obj["log_folder_path"] = log_folder_path
|
||||
ctx.obj["filestore_folder_path"] = filestore_folder_path
|
||||
|
||||
ctx.obj["config_file_path"] = config_file_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(get_code)
|
||||
22
odoo_openupgrade_wizard/cli_get_code.py
Normal file
22
odoo_openupgrade_wizard/cli_get_code.py
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
import click
|
||||
|
||||
from odoo_openupgrade_wizard.configuration_version_dependant import (
|
||||
get_odoo_env_path,
|
||||
)
|
||||
from odoo_openupgrade_wizard.tools_system import git_aggregate
|
||||
|
||||
|
||||
@click.command()
|
||||
@click.pass_context
|
||||
def get_code(ctx):
|
||||
"""
|
||||
Build OpenUpgrade Wizard Environment:
|
||||
- gitaggregate all the repositories
|
||||
"""
|
||||
|
||||
# TODO, make it modular.
|
||||
# For exemple, possibility to aggregate only 9.0 and 11.0 releaase
|
||||
for odoo_version in ctx.obj["config"]["odoo_versions"]:
|
||||
folder_path = get_odoo_env_path(ctx, odoo_version)
|
||||
repo_file_path = folder_path / "repos.yml"
|
||||
git_aggregate(folder_path, repo_file_path)
|
||||
168
odoo_openupgrade_wizard/cli_init.py
Normal file
168
odoo_openupgrade_wizard/cli_init.py
Normal file
|
|
@ -0,0 +1,168 @@
|
|||
from pathlib import Path
|
||||
|
||||
import click
|
||||
|
||||
from odoo_openupgrade_wizard import templates
|
||||
from odoo_openupgrade_wizard.configuration_version_dependant import (
|
||||
get_odoo_env_path,
|
||||
get_odoo_versions,
|
||||
get_release_options,
|
||||
)
|
||||
from odoo_openupgrade_wizard.tools_system import (
|
||||
ensure_file_exists_from_template,
|
||||
ensure_folder_exists,
|
||||
)
|
||||
|
||||
|
||||
@click.command()
|
||||
@click.option(
|
||||
"--initial-release",
|
||||
required=True,
|
||||
prompt=True,
|
||||
type=click.Choice(get_release_options("initial")),
|
||||
)
|
||||
@click.option(
|
||||
"--final-release",
|
||||
required=True,
|
||||
prompt=True,
|
||||
type=click.Choice(get_release_options("final")),
|
||||
)
|
||||
@click.option(
|
||||
"--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_release, final_release, extra_repository_list):
|
||||
"""
|
||||
Initialize OpenUpgrade Wizard Environment based on the initial and
|
||||
the final release of Odoo you want to migrate.
|
||||
"""
|
||||
|
||||
# Handle arguments
|
||||
if extra_repository_list:
|
||||
extra_repositories = extra_repository_list.split(",")
|
||||
else:
|
||||
extra_repositories = []
|
||||
|
||||
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)
|
||||
|
||||
# 1. Compute Odoo versions
|
||||
odoo_versions = get_odoo_versions(
|
||||
float(initial_release), float(final_release)
|
||||
)
|
||||
|
||||
# 2. Compute Migration Steps
|
||||
|
||||
# Create initial first step
|
||||
steps = [
|
||||
{
|
||||
"name": 1,
|
||||
"action": "update",
|
||||
"release": odoo_versions[0]["release"],
|
||||
"complete_name": "step_01__update__%s"
|
||||
% (odoo_versions[0]["release"]),
|
||||
}
|
||||
]
|
||||
|
||||
# Add all upgrade steps
|
||||
count = 2
|
||||
for odoo_version in odoo_versions[1:]:
|
||||
steps.append(
|
||||
{
|
||||
"name": count,
|
||||
"action": "upgrade",
|
||||
"release": odoo_version["release"],
|
||||
"complete_name": "step_%s__upgrade__%s"
|
||||
% (str(count).rjust(2, "0"), odoo_version["release"]),
|
||||
}
|
||||
)
|
||||
count += 1
|
||||
|
||||
# add final update step
|
||||
count += 1
|
||||
steps.append(
|
||||
{
|
||||
"name": count,
|
||||
"action": "update",
|
||||
"release": odoo_versions[-1]["release"],
|
||||
"complete_name": "step_%s__update__%s"
|
||||
% (str(count).rjust(2, "0"), odoo_versions[-1]["release"]),
|
||||
}
|
||||
)
|
||||
|
||||
# 3. ensure src folder exists
|
||||
ensure_folder_exists(ctx.obj["src_folder_path"])
|
||||
|
||||
# 4. ensure filestore folder exists
|
||||
ensure_folder_exists(ctx.obj["filestore_folder_path"])
|
||||
|
||||
# 5. ensure main configuration file exists
|
||||
ensure_file_exists_from_template(
|
||||
ctx.obj["config_file_path"],
|
||||
templates.CONFIG_YML_TEMPLATE,
|
||||
steps=steps,
|
||||
odoo_versions=odoo_versions,
|
||||
)
|
||||
|
||||
# 6. Create one folder per version and add files
|
||||
for odoo_version in odoo_versions:
|
||||
# Create main path for each version
|
||||
path_version = get_odoo_env_path(ctx, odoo_version)
|
||||
ensure_folder_exists(path_version)
|
||||
|
||||
# Create python requirements file
|
||||
ensure_file_exists_from_template(
|
||||
path_version / Path("python_requirements.txt"),
|
||||
templates.PYTHON_REQUIREMENTS_TXT_TEMPLATE,
|
||||
python_libraries=odoo_version["python_libraries"],
|
||||
)
|
||||
|
||||
# Create debian requirements file
|
||||
ensure_file_exists_from_template(
|
||||
path_version / Path("debian_requirements.txt"),
|
||||
templates.DEBIAN_REQUIREMENTS_TXT_TEMPLATE,
|
||||
)
|
||||
|
||||
# Create odoo config file
|
||||
ensure_file_exists_from_template(
|
||||
path_version / Path("odoo.cfg"),
|
||||
templates.ODOO_CONFIG_TEMPLATE,
|
||||
)
|
||||
|
||||
# Create repos.yml file for gitaggregate tools
|
||||
ensure_file_exists_from_template(
|
||||
path_version / Path("repos.yml"),
|
||||
templates.REPO_YML_TEMPLATE,
|
||||
odoo_version=odoo_version,
|
||||
orgs=orgs,
|
||||
)
|
||||
|
||||
# Create Dockerfile file
|
||||
ensure_file_exists_from_template(
|
||||
path_version / Path("Dockerfile"),
|
||||
templates.DOCKERFILE_TEMPLATE,
|
||||
odoo_version=odoo_version,
|
||||
)
|
||||
|
||||
# 6. Create one folder per step and add 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"),
|
||||
templates.PRE_MIGRATION_SQL_TEMPLATE,
|
||||
)
|
||||
|
||||
ensure_file_exists_from_template(
|
||||
step_path / Path("post-migration.py"),
|
||||
templates.POST_MIGRATION_PY_TEMPLATE,
|
||||
)
|
||||
87
odoo_openupgrade_wizard/configuration_version_dependant.py
Normal file
87
odoo_openupgrade_wizard/configuration_version_dependant.py
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
# 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_VERSION_TEMPLATES = [
|
||||
{
|
||||
"release": 8.0,
|
||||
"python_major_version": "python2",
|
||||
"python_libraries": ["openupgradelib"],
|
||||
},
|
||||
{
|
||||
"release": 9.0,
|
||||
"python_major_version": "python2",
|
||||
"python_libraries": ["openupgradelib"],
|
||||
},
|
||||
{
|
||||
"release": 10.0,
|
||||
"python_major_version": "python2",
|
||||
"python_libraries": ["openupgradelib"],
|
||||
},
|
||||
{
|
||||
"release": 11.0,
|
||||
"python_major_version": "python3",
|
||||
"python_libraries": ["openupgradelib"],
|
||||
},
|
||||
{
|
||||
"release": 12.0,
|
||||
"python_major_version": "python3",
|
||||
"python_libraries": ["openupgradelib"],
|
||||
},
|
||||
{
|
||||
"release": 13.0,
|
||||
"python_major_version": "python3",
|
||||
"python_libraries": ["openupgradelib"],
|
||||
},
|
||||
{
|
||||
"release": 14.0,
|
||||
"python_major_version": "python3",
|
||||
"python_libraries": ["openupgradelib"],
|
||||
},
|
||||
{
|
||||
"release": 15.0,
|
||||
"python_major_version": "python3",
|
||||
"python_libraries": ["openupgradelib"],
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
def get_release_options(mode: str) -> list:
|
||||
"""Get options available for release click argument.
|
||||
Arguments:
|
||||
mode: Possible value 'initial', 'final'
|
||||
Return:
|
||||
list of string.
|
||||
Exemple:
|
||||
['9.0', '10.0', '11.0']
|
||||
"""
|
||||
releases_list = [str(x["release"]) for x in _ODOO_VERSION_TEMPLATES]
|
||||
if mode == "initial":
|
||||
releases_list = releases_list[:-1]
|
||||
if mode == "final":
|
||||
releases_list = releases_list[1:]
|
||||
return releases_list
|
||||
|
||||
|
||||
def get_odoo_versions(initial_release: float, final_release: float) -> list:
|
||||
"""Return a list of odoo versions from the initial release to the final
|
||||
release
|
||||
"""
|
||||
result = []
|
||||
for version_template in _ODOO_VERSION_TEMPLATES:
|
||||
if (
|
||||
version_template["release"] >= initial_release
|
||||
and version_template["release"] <= final_release
|
||||
):
|
||||
result.append(version_template)
|
||||
return result
|
||||
|
||||
|
||||
# def _get_repo_file(ctx, step):
|
||||
# return ctx.obj["repo_folder_path"] / Path("%s.yml" % (step["version"]))
|
||||
|
||||
|
||||
def get_odoo_env_path(ctx, odoo_version):
|
||||
folder_name = "env_%s" % str(odoo_version["release"]).rjust(4, "0")
|
||||
return ctx.obj["src_folder_path"] / folder_name
|
||||
100
odoo_openupgrade_wizard/templates.py
Normal file
100
odoo_openupgrade_wizard/templates.py
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
CONFIG_YML_TEMPLATE = """odoo_versions:
|
||||
{% for odoo_version in odoo_versions %}
|
||||
- release: {{ odoo_version['release'] }}
|
||||
{% endfor %}
|
||||
|
||||
migration_steps:
|
||||
{% for step in steps %}
|
||||
- name: {{ step['name'] }}
|
||||
release: {{ step['release'] }}
|
||||
action: {{ step['action'] }}
|
||||
complete_name: {{ step['complete_name'] }}
|
||||
{% endfor %}
|
||||
"""
|
||||
|
||||
REPO_YML_TEMPLATE = """
|
||||
##############################################################################
|
||||
## Odoo Repository
|
||||
##############################################################################
|
||||
|
||||
./src/odoo:
|
||||
defaults:
|
||||
depth: 1
|
||||
remotes:
|
||||
odoo: https://github.com/odoo/odoo
|
||||
target: odoo {{ odoo_version['release'] }}-target
|
||||
merges:
|
||||
- odoo {{ odoo_version['release'] }}
|
||||
|
||||
##############################################################################
|
||||
## OpenUpgrade Repository
|
||||
##############################################################################
|
||||
|
||||
./src/openupgrade:
|
||||
defaults:
|
||||
depth: 1
|
||||
remotes:
|
||||
OCA: https://github.com/OCA/OpenUpgrade
|
||||
target: OCA {{ odoo_version['release'] }}-target
|
||||
merges:
|
||||
- OCA {{ odoo_version['release'] }}
|
||||
|
||||
{% 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 }} {{ odoo_version['release'] }}-target
|
||||
merges:
|
||||
- {{ org_name }} {{ odoo_version['release'] }}
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
|
||||
"""
|
||||
|
||||
PYTHON_REQUIREMENTS_TXT_TEMPLATE = """
|
||||
{%- for python_librairy in python_libraries -%}
|
||||
{{ python_librairy }}
|
||||
{% endfor %}
|
||||
"""
|
||||
|
||||
DEBIAN_REQUIREMENTS_TXT_TEMPLATE = ""
|
||||
|
||||
ODOO_CONFIG_TEMPLATE = ""
|
||||
|
||||
DOCKERFILE_TEMPLATE = """
|
||||
FROM odoo:{{ odoo_version['release'] }}
|
||||
MAINTAINER GRAP, Coop It Easy
|
||||
|
||||
# Set User root for installations
|
||||
USER root
|
||||
|
||||
# 1. Make available files in the containers
|
||||
|
||||
COPY debian_requirements.txt /debian_requirements.txt
|
||||
|
||||
COPY python_requirements.txt /python_requirements.txt
|
||||
|
||||
# 2. Install extra debian packages
|
||||
RUN apt-get update &&\
|
||||
xargs apt-get install -y --no-install-recommends <debian_requirements.txt
|
||||
|
||||
# 3. Install extra Python librairies
|
||||
RUN {{ odoo_version["python_major_version"] }}\
|
||||
-m pip install -e python_requirements.txt
|
||||
|
||||
# Reset to odoo user to run the container
|
||||
USER odoo
|
||||
"""
|
||||
|
||||
PRE_MIGRATION_SQL_TEMPLATE = ""
|
||||
|
||||
POST_MIGRATION_PY_TEMPLATE = """
|
||||
def main(self, step):
|
||||
pass
|
||||
"""
|
||||
69
odoo_openupgrade_wizard/tools_system.py
Normal file
69
odoo_openupgrade_wizard/tools_system.py
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
import argparse
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
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.cmd import mkdir
|
||||
|
||||
|
||||
def ensure_folder_exists(folder_path: Path, mode: str = 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", "755"] + cmd
|
||||
logger.info("Creating folder '%s' ..." % (folder_path))
|
||||
mkdir(cmd)
|
||||
|
||||
|
||||
def ensure_file_exists_from_template(
|
||||
file_path: Path, template_name: str, **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: Path, config_path: 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)
|
||||
1229
poetry.lock
generated
Normal file
1229
poetry.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
56
pyproject.toml
Normal file
56
pyproject.toml
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
[tool.poetry]
|
||||
name = "odoo-openupgrade-wizard"
|
||||
version = "0.0.2"
|
||||
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"
|
||||
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.black]
|
||||
line-length = 79
|
||||
|
||||
[tool.isort]
|
||||
profile = "black"
|
||||
line_length = 79
|
||||
2
pytest.ini
Normal file
2
pytest.ini
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
[pytest]
|
||||
norecursedirs = tests/output_*
|
||||
30
tests/cli_01_init_test.py
Normal file
30
tests/cli_01_init_test.py
Normal 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_01")
|
||||
expected_folder_path = Path("./tests/output_01_expected")
|
||||
mkdir([output_folder_path, "--parents"])
|
||||
result = CliRunner().invoke(
|
||||
main,
|
||||
[
|
||||
"--env-folder=%s" % output_folder_path,
|
||||
"init",
|
||||
"--initial-release=9.0",
|
||||
"--final-release=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"),
|
||||
)
|
||||
41
tests/cli_02_get_code_test.py
Normal file
41
tests/cli_02_get_code_test.py
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
from pathlib import Path
|
||||
|
||||
from click.testing import CliRunner
|
||||
from plumbum.cmd import mkdir
|
||||
|
||||
from odoo_openupgrade_wizard.cli import main
|
||||
|
||||
|
||||
def test_cli_get_code():
|
||||
output_folder_path = Path("./tests/output_02")
|
||||
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-release=14.0",
|
||||
"--final-release=14.0",
|
||||
"--extra-repository=OCA/web",
|
||||
],
|
||||
)
|
||||
|
||||
result = CliRunner().invoke(
|
||||
main,
|
||||
[
|
||||
"--env-folder=%s" % output_folder_path,
|
||||
"get-code",
|
||||
],
|
||||
)
|
||||
assert result.exit_code == 0
|
||||
|
||||
openupgrade_path = output_folder_path / Path(
|
||||
"./src/env_14.0/src/openupgrade"
|
||||
)
|
||||
|
||||
assert openupgrade_path.exists()
|
||||
|
||||
assert (openupgrade_path / Path("openupgrade_framework")).exists()
|
||||
37
tests/output_01_expected/config.yml
Normal file
37
tests/output_01_expected/config.yml
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
odoo_versions:
|
||||
|
||||
- release: 9.0
|
||||
|
||||
- release: 10.0
|
||||
|
||||
- release: 11.0
|
||||
|
||||
- release: 12.0
|
||||
|
||||
|
||||
migration_steps:
|
||||
|
||||
- name: 1
|
||||
release: 9.0
|
||||
action: update
|
||||
complete_name: step_01__update__9.0
|
||||
|
||||
- name: 2
|
||||
release: 10.0
|
||||
action: upgrade
|
||||
complete_name: step_02__upgrade__10.0
|
||||
|
||||
- name: 3
|
||||
release: 11.0
|
||||
action: upgrade
|
||||
complete_name: step_03__upgrade__11.0
|
||||
|
||||
- name: 4
|
||||
release: 12.0
|
||||
action: upgrade
|
||||
complete_name: step_04__upgrade__12.0
|
||||
|
||||
- name: 6
|
||||
release: 12.0
|
||||
action: update
|
||||
complete_name: step_06__update__12.0
|
||||
Loading…
Reference in New Issue
Block a user