Skip to content

Commit 533705a

Browse files
committed
[ADD] xodoo: init
``xodoo`` is collection of various scripts intended to be used for odoo. It is based on ``click-odoo`` to connect and manage odoo. Scripts ~~~~~~~ xodoo-migrate ------------- Migration tool intended to run various migration scripts for Odoo. It should be used when migration scripts directly on modules do not make sense (e.g. need to generate some customer specific data that is not directly related with any module).
1 parent 82d85e5 commit 533705a

22 files changed

+858
-5
lines changed

.github/workflows/ci.yml

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
---
2+
name: CI
3+
4+
on: # yamllint disable-line rule:truthy
5+
pull_request:
6+
push:
7+
branches:
8+
- "master"
9+
tags:
10+
- "[0-9]+.[0-9]+.[0-9]+"
11+
12+
jobs:
13+
tests:
14+
runs-on: ubuntu-latest
15+
strategy:
16+
fail-fast: false
17+
matrix:
18+
include:
19+
- python-version: "3.9"
20+
toxenv: "py39-15.0"
21+
machine: ubuntu-22.04
22+
- python-version: "3.10"
23+
toxenv: "py310-16.0"
24+
machine: ubuntu-22.04
25+
- python-version: "3.11"
26+
toxenv: "py311-16.0"
27+
machine: ubuntu-22.04
28+
- python-version: "3.10"
29+
toxenv: "twine_check"
30+
machine: ubuntu-22.04
31+
services:
32+
postgres:
33+
image: postgres:15
34+
env:
35+
POSTGRES_USER: odoo
36+
POSTGRES_PASSWORD: odoo
37+
ports:
38+
- 5432:5432
39+
# needed because the postgres container does not provide a healthcheck
40+
options:
41+
--health-cmd pg_isready --health-interval 10s --health-timeout 5s
42+
--health-retries 5
43+
env:
44+
PGHOST: localhost
45+
PGPORT: 5432
46+
PGUSER: odoo
47+
PGPASSWORD: odoo
48+
steps:
49+
- uses: actions/checkout@v4
50+
- uses: actions/setup-python@v4
51+
with:
52+
python-version: "${{ matrix.python-version }}"
53+
- uses: actions/cache@v3
54+
with:
55+
path: ~/.cache/pip
56+
key: ${{ runner.os }}-pip-${{ matrix.toxenv }}
57+
- name: Install system dependencies
58+
run: |
59+
sudo apt-get update -qq
60+
sudo apt-get install -qq --no-install-recommends \
61+
libxml2-dev libxslt1-dev \
62+
libldap2-dev libsasl2-dev \
63+
gettext
64+
pip install tox virtualenv
65+
- name: Run tox
66+
run: tox -e ${{ matrix.toxenv }}
67+
deploy:
68+
runs-on: ubuntu-latest
69+
needs:
70+
- tests
71+
if: startsWith(github.ref, 'refs/tags')
72+
steps:
73+
- uses: actions/checkout@v4
74+
- uses: actions/setup-python@v4
75+
- name: Build a binary wheel and a source tarball
76+
run: pipx run build
77+
- name: Publish distribution 📦 to PyPI
78+
uses: pypa/gh-action-pypi-publish@release/v1
79+
with:
80+
user: __token__
81+
password: ${{ secrets.PYPI_API_TOKEN }}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
/.vscode
66
pyrightconfig.json
77
.venv
8+
src/odoo
9+
.tox_env
810

911
# Byte-compiled / optimized / DLL files
1012
__pycache__/

.isort.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[settings]
2+
profile = black

.pre-commit-config.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
exclude: "^tests/data/.*$"
3+
repos:
4+
- repo: https://github.com/pre-commit/pre-commit-hooks
5+
rev: v4.4.0
6+
hooks:
7+
- id: trailing-whitespace
8+
- id: end-of-file-fixer
9+
- id: check-yaml
10+
- id: debug-statements
11+
- id: fix-encoding-pragma
12+
args:
13+
- --remove
14+
- repo: https://github.com/pycqa/flake8
15+
rev: 6.1.0
16+
hooks:
17+
- id: flake8
18+
additional_dependencies: ["flake8-bugbear==20.1.4"]
19+
- repo: https://github.com/asottile/pyupgrade
20+
rev: v3.10.1
21+
hooks:
22+
- id: pyupgrade
23+
- repo: https://github.com/pycqa/isort
24+
rev: 5.12.0
25+
hooks:
26+
- id: isort
27+
- repo: https://github.com/psf/black
28+
rev: 23.7.0
29+
hooks:
30+
- id: black

README.rst

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,58 @@
1-
click-odoo-migrate
2-
==================
1+
xodoo
2+
=====
33

44
.. image:: https://img.shields.io/badge/license-LGPL--3-blue.svg
55
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
66
:alt: License: LGPL-3
77

8-
``click-odoo-migrate`` is migration tool intended to run various migrations
9-
scripts for Odoo. It should be used when migration scripts on modules directly
10-
do not make sense (e.g. need to generate some customer specific data that is not directly related with any module).
8+
``xodoo`` is collection of various scripts intended to be used for odoo.
9+
It is based on ``click-odoo`` to connect and manage odoo.
10+
11+
Scripts
12+
~~~~~~~
13+
14+
xodoo-migrate
15+
-------------
16+
17+
Migration tool intended to run various migration scripts for Odoo. It should
18+
be used when migration scripts directly on modules do not make sense (e.g. need
19+
to generate some customer specific data that is not directly related with any
20+
module).
21+
22+
.. code::
23+
24+
Usage: xodoo-migrate [OPTIONS] PATH
25+
26+
PATH: migration file or directory of migration files.
27+
28+
Migration file must end with .py extension and must have 'migrate' function
29+
that expects 'env' argument.
30+
31+
Options:
32+
-c, --config FILE Specify the Odoo configuration file. Other ways
33+
to provide it are with the ODOO_RC or
34+
OPENERP_SERVER environment variables, or
35+
~/.odoorc (Odoo >= 10) or ~/.openerp_serverrc.
36+
-d, --database TEXT Specify the database name. If present, this
37+
parameter takes precedence over the database
38+
provided in the Odoo configuration file.
39+
--log-level TEXT Specify the logging level. Accepted values depend
40+
on the Odoo version, and include debug, info,
41+
warn, error. [default: warn]
42+
--logfile FILE Specify the log file.
43+
--rollback Rollback the transaction even if the script does
44+
not raise an exception. Note that if the script
45+
itself commits, this option has no effect. This
46+
is why it is not named dry run. This option is
47+
implied when an interactive console is started.
48+
-f, --force TEXT Specify migration file names (without extension)
49+
to force migrate. It will migrate even if it was
50+
already migrated. Must be subset of migration
51+
files provided in a path.
52+
-s, --sort-algorithm TEXT Sort algorithm to sort migration files before
53+
migration. Possible choices: sorted, natsorted
54+
--help Show this message and exit.
55+
56+
If you use ``--rollback`` option, make sure you do not run ``cr.commit()`` in
57+
your scripts, otherwise it will have no effect (script changes are automatically
58+
committed if they do not fail at the end of transaction).

natsort-8.4.0-py3-none-any.whl

37.4 KB
Binary file not shown.

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[build-system]
2+
requires = ["setuptools>=42", "wheel", "setuptools_scm[toml]>=3.4"]
3+
build-backend = "setuptools.build_meta"

setup.cfg

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[flake8]
2+
max-line-length = 88
3+
max-complexity = 16
4+
# B = bugbear
5+
# B9 = bugbear opinionated (incl line length)
6+
select = C,E,F,W,B,B9
7+
# E203: whitespace before ':' (black behaviour)
8+
# E501: flake8 line length (covered by bugbear B950)
9+
# W503: line break before binary operator (black behaviour)
10+
ignore = E203,E501,W503
11+
exclude =
12+
./.git
13+
./src
14+
./venv*
15+
./.venv*
16+
.eggs/

setup.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Copyright 2023 Timefordev (<https://timefordev.com>)
2+
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
3+
import os
4+
5+
from setuptools import find_packages, setup
6+
7+
here = os.path.abspath(os.path.dirname(__file__))
8+
9+
setup(
10+
name="xodoo",
11+
description="Odoo CLI Tools",
12+
long_description="\n".join((open(os.path.join(here, "README.rst")).read(),)),
13+
use_scm_version=True,
14+
packages=find_packages(),
15+
include_package_data=True,
16+
setup_requires=["setuptools-scm"],
17+
install_requires=["click-odoo>=1.3.0", "natsort>=8.4.0"],
18+
python_requires=">=3.9",
19+
license="LGPLv3+",
20+
author="Andrius Laukavičius",
21+
author_email="info@timefordev.com",
22+
url="http://github.com/oerp-odoo/xodoo",
23+
classifiers=[
24+
"Intended Audience :: Developers",
25+
"License :: OSI Approved :: "
26+
+ "GNU Lesser General Public License v3 or later (LGPLv3+)",
27+
"Programming Language :: Python :: 3.9",
28+
"Programming Language :: Python :: 3.10",
29+
"Programming Language :: Python :: 3.11",
30+
"Framework :: Odoo",
31+
],
32+
entry_points="""
33+
[console_scripts]
34+
xodoo-migrate=xodoo.migration:main
35+
""",
36+
)

tests/conftest.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import os
2+
import pathlib
3+
import subprocess
4+
import textwrap
5+
6+
import pytest
7+
from click_odoo import odoo, odoo_bin
8+
9+
PATH_MIG_ROOT = pathlib.Path(__file__).parent / "data"
10+
PATH_MIG_1 = PATH_MIG_ROOT / "mig1"
11+
12+
# This hack is necessary because the way CliRunner patches
13+
# stdout is not compatible with the Odoo logging initialization
14+
# mechanism. Logging is therefore tested with subprocesses.
15+
odoo.netsvc._logger_init = True
16+
17+
18+
def _init_odoo_db(dbname, test_addons_dir=None):
19+
subprocess.check_call(["createdb", dbname])
20+
cmd = [odoo_bin, "-d", dbname, "-i", "base", "--stop-after-init"]
21+
if test_addons_dir:
22+
addons_path = [
23+
os.path.join(odoo.__path__[0], "addons"),
24+
os.path.join(odoo.__path__[0], "..", "addons"),
25+
test_addons_dir,
26+
]
27+
cmd.append("--addons-path")
28+
cmd.append(",".join(addons_path))
29+
subprocess.check_call(cmd)
30+
31+
32+
def _drop_db(dbname):
33+
subprocess.check_call(["dropdb", dbname])
34+
35+
36+
@pytest.fixture(scope="module")
37+
def odoodb(request):
38+
dbname = "xodoo-test-{}".format(odoo.release.version_info[0])
39+
test_addons_dir = getattr(request.module, "test_addons_dir", "")
40+
_init_odoo_db(dbname, test_addons_dir)
41+
try:
42+
yield dbname
43+
finally:
44+
_drop_db(dbname)
45+
46+
47+
@pytest.fixture(scope="function")
48+
def odoocfg(request, tmpdir):
49+
addons_path = [
50+
os.path.join(odoo.__path__[0], "addons"),
51+
os.path.join(odoo.__path__[0], "..", "addons"),
52+
]
53+
test_addons_dir = getattr(request.module, "test_addons_dir", "")
54+
if test_addons_dir:
55+
addons_path.append(test_addons_dir)
56+
odoo_cfg = tmpdir / "odoo.cfg"
57+
odoo_cfg.write(
58+
textwrap.dedent(
59+
"""\
60+
[options]
61+
addons_path = {}
62+
""".format(
63+
",".join(addons_path)
64+
)
65+
)
66+
)
67+
yield odoo_cfg
68+
69+
70+
@pytest.fixture
71+
def path_test_data(scope="package"):
72+
return pathlib.Path(__file__).parent / "data"

0 commit comments

Comments
 (0)