Commit 314c298e authored by Alexis PASQUIER's avatar Alexis PASQUIER
Browse files

🚨 Passage lint, black, isort 💚

Passage en version 1.2.1
parent 8f6359f0
Pipeline #74559 failed with stages
in 1 minute and 47 seconds
repos:
- repo: https://github.com/psf/black
rev: 22.1.0
hooks:
- id: black
- repo: https://github.com/PyCQA/isort
rev: 5.7.0
hooks:
- id: isort
# - repo: https://github.com/flakehell/flakehell
# rev: v.0.9.0
# hooks:
# - id: flakehell
- repo: local
hooks:
- id: autoflake
name: autoflake
entry: pautoflake -i
language: system
always_run: true
pass_filenames: true
- id: flakehell
name: flakehell
entry: flakehell lint
language: system
always_run: true
pass_filenames: false
# Requirements for
flakehell>=0.9.0
flake8-black>=0.3.2
flake8-isort>=4.1.1
flake8==3.9.0
black>=22.1.0
isort>=5.6.4
pre-commit>=2.17.0
pyproject-autoflake>=1.0.1
\ No newline at end of file
......@@ -5,9 +5,9 @@
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/odoo_launcher" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/tests" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build" />
<excludeFolder url="file://$MODULE_DIR$/dist" />
<excludeFolder url="file://$MODULE_DIR$/odoo_launcher.egg-info" />
<excludeFolder url="file://$MODULE_DIR$/build" />
</content>
<orderEntry type="jdk" jdkName="Python 3.8" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
......
......@@ -9,27 +9,31 @@ from . import api, config_section, mapper # noqa
from .odoo_config_maker import OdooConfig, OdooEnvConverter # noqa
_logger = logging.getLogger(__name__)
# _logger.setLevel(logging.DEBUG)
def main():
env_vars = dict(os.environ)
launcher = laucher.Launcher(
args=sys.argv[:1],
odoo_path=env_vars.get("ODOO_PATH"),
odoo_rc=env_vars.get("ODOO_RC"),
server_path=env_vars.get("ODOO_SERVER_PATH"),
)
_logger.info("create config")
if env_vars.get("UPDATE") or env_vars.get("INSTALL"):
return_code = launcher.launch_config_file(env_vars).wait()
if return_code:
sys.exit(return_code)
odoo_path = os.getenv("ODOO_PATH")
server_path = os.getenv("NDP_SERVER_PATH")
odoo_rc = os.getenv("ODOO_RC")
launcher = laucher.Launcher(sys.argv[1:], odoo_path=odoo_path, odoo_rc=odoo_rc, server_path=server_path)
launcher.init_addons(env_vars)
return_code = launcher.launch_config_file(env_vars).wait()
if return_code:
sys.exit(return_code)
if os.getenv("UPDATE") or os.getenv("INSTALL"):
_logger.info("Update or init detected")
with launcher.launch_maintenance_server() as maintenance_server_proc:
return_code = launcher.launch_update(env_vars).wait()
maintenance_server_proc.kill()
maintenance_server_proc = launcher.launch_maintenance_server()
return_code = launcher.launch_update(env_vars).wait()
maintenance_server_proc.kill()
if return_code:
sys.exit(return_code)
_logger.info("#############################################")
_logger.info("Run Odoo")
sys.exit(launcher.launch(env_vars).wait())
sys.exit(launcher.launch({}).wait())
if __name__ == "__main__":
main()
......@@ -50,7 +50,7 @@ class Dictable(ABC):
class ConfigConvert(ABC):
def is_true(self, any):
# type: (Union[str, bool, int, None]) -> bool
if not isinstance(any, (str, bool, int)):
if not any or not isinstance(any, (str, bool, int)):
return False
return bool(any) and (str(any).isdigit() and bool(int(any))) or (str(any).capitalize() == str(True)) or False
......
......@@ -185,9 +185,19 @@ class ServerWideModuleConfigSection(OdooConfigSection):
self.queue_job_module_name = "connector"
self.server_wide_modules.append(self.queue_job_module_name)
if env_vars.get("S3_FILESTORE_ENABLE"):
print(
"enable odoo_filestore_s3 ?",
self.is_true(env_vars.get("S3_FILESTORE_ENABLE")),
env_vars.get("S3_FILESTORE_ENABLE"),
)
print(
"enable odoo_session_redis ? ",
self.is_true(env_vars.get("REDIS_SESSION_ENABLE")),
env_vars.get("REDIS_SESSION_ENABLE"),
)
if self.is_true(env_vars.get("S3_FILESTORE_ENABLE")):
self.server_wide_modules.append("odoo_filestore_s3")
if env_vars.get("REDIS_SESSION_ENABLE"):
if self.is_true(env_vars.get("REDIS_SESSION_ENABLE")):
self.server_wide_modules.append("odoo_session_redis")
def remove_queue_job(self):
......@@ -205,7 +215,7 @@ class OtherSection(OdooConfigSection):
super(OtherSection, self).__init__(odoo_config_maker, env_vars)
self.unaccent = self.is_true(env_vars.get("UNACCENT", True))
self.test_enable = self.is_true(env_vars.get("TEST_ENABLE"))
self.without_demo = self.is_true(env_vars.get("WITHOUT_DEMO"))
self.without_demo = self.is_true(env_vars.get("WITHOUT_DEMO", "all"))
def to_dict(self):
if not self.enable:
......@@ -266,7 +276,7 @@ class UpdateInstallSection(OdooConfigSection):
return default_res
res = OrderedDict()
res["--update"] = ",".join(self.update)
res["--install"] = ",".join(self.install)
res["--init"] = ",".join(self.install)
res["--stop-after-init"] = self.stop_after_init
res["--save"] = self.save_config_file
res.update(default_res)
......
from __future__ import unicode_literals
import argparse
import configparser
import logging
import os
import subprocess
import sys
if sys.version_info >= (3,):
import configparser
else:
import ConfigParser as configparser
import uuid
from typing import Dict, List, Optional
from addons_installer import AddonsInstaller, AddonsRegistry
from .odoo_config_maker import OdooConfig
_logger = logging.getLogger("launch")
......@@ -25,12 +32,13 @@ class Launcher(object):
odoo_path = ns.odoo_path or odoo_path
assert odoo_path, "No Odoo path is provided"
self.odoo_path = os.path.abspath(os.path.expanduser(odoo_path))
self.other_args = other
odoo_rc = ns.odoo_rc or odoo_rc
assert "No Odoo config file path is provided"
self.odoo_rc = os.path.abspath(odoo_rc)
ndp_server_path = ns.server_path or server_path
assert "Server path is provided"
assert ndp_server_path, "Server path is provided"
self.ndp_server_path = os.path.abspath(os.path.expanduser(ndp_server_path))
def get_parser(self):
......@@ -41,10 +49,16 @@ class Launcher(object):
parser.add_argument("--ndp-server-path", dest="server_path", help="Server Path")
return parser
def init_addons(self, env_vars):
registry = AddonsRegistry()
addons = registry.parse_env(env_vars)
for addon in addons:
AddonsInstaller.install(addon)
def create_config_file_args(self, env_vars):
# type: (Dict[str, str]) -> OdooConfig
config = OdooConfig(env_vars, self.odoo_rc)
config.http_config.enable = False
# config.http_config.enable = False
config.update_install.enable = False
config.update_install.save_config_file = True
......@@ -122,21 +136,3 @@ class Launcher(object):
# type: (List[str]) -> subprocess.Popen
_logger.info("Run -> %s", " ".join([str(s) for s in cmd]))
return subprocess.Popen(cmd)
if __name__ == "__main__":
_logger.info("create config")
launcher = Launcher(sys.argv[1:])
if os.getenv("UPDATE") or os.getenv("INSTALL"):
return_code = launcher.create_config_file(update_mode=True).wait()
if return_code:
sys.exit(return_code)
_logger.info("Update or init detected")
with launcher.launch_maintenance_server() as maintenance_server_proc:
return_code = launcher.launch_update().wait()
maintenance_server_proc.kill()
if return_code:
sys.exit(return_code)
_logger.info("#############################################")
_logger.info("Run Odoo")
sys.exit(launcher.launch().wait())
from typing import Dict, Union
from .api import EnvMapper
......@@ -70,7 +72,7 @@ class OdooRedisSessionMapper(EnvMapper):
def map_vars(self, env_vars):
# type: (Dict[str, str]) -> Dict[str, str]
enable = self.is_true(env_vars.get("REDIS_SESSION_ENABLE"))
enable = self.is_true(env_vars.get("REDIS_SESSION_ENABLE", bool(env_vars.get("REDIS_HOST"))))
return {
"REDIS_SESSION_ENABLE": str(enable),
"REDIS_SESSION_URL": enable and env_vars.get("REDIS_SESSION_URL", env_vars.get("REDIS_URL")) or None,
......@@ -99,7 +101,7 @@ class CleverCloudCellarCompatibilityMapper(EnvMapper):
def map_vars(self, env_vars):
# type: (Dict[str, Union[str, bool, int, None]]) -> Dict[str, Union[str, bool, int, None]]
enable = self.is_true(env_vars.get("S3_FILESTORE_ENABLE", env_vars.get("CELLAR_ADDON_HOST") and "True"))
enable = self.is_true(env_vars.get("S3_FILESTORE_ENABLE", bool(env_vars.get("CELLAR_ADDON_HOST"))))
return {
"S3_FILESTORE_ENABLE": str(enable),
"S3_FILESTORE_HOST": enable
......
[build-system]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"
[tool.black]
line-length = 120
[tool.isort]
profile = "black"
skip_gitignore = true
skip = "__init__.py"
[tool.autoflake]
expand-star-imports = true # expand from module import *
ignore-init-module-imports = true # exclude __init__.py when removing unused imports
remove-duplicate-keys = true # remove all duplicate keys in objects
\ No newline at end of file
remove-duplicate-keys = true # remove all duplicate keys in objects
[tool.flakehell]
base = "https://gitlab.ndp-systemes.fr/odoo-addons/ci-files/-/raw/master/jobs/.pre/base_flake_hell.toml"
[metadata]
name = odoo_launcher
version = 1.2.0
version = 1.2.1
url = https://gitlab.ndp-systemes.fr/python-libs/odoo_launcher
license = GPLv3
author = Alexis Pasquier, NDP Systemes
......@@ -19,8 +19,8 @@ python_requires = >=2.7, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.*
include_package_data = True
packages = odoo_launcher
install_requires =
addons-installer==1.2.0
maintenance-server==1.2.0
addons-installer>=1.2.1
maintenance-server>=1.2.1
typing==3.10.0.0;python_version<='3'
enum34==1.1.10;python_version<='3'
......@@ -190,6 +190,7 @@ class TestCleverCloudMapperCellar(TestMapper):
)
self.assertEqual(5, len(result.keys()))
self.assertTrue(result["S3_FILESTORE_ENABLE"])
self.assertEqual(str(True), result["S3_FILESTORE_ENABLE"])
self.assertEqual(host, result["S3_FILESTORE_HOST"])
self.assertEqual(secret_key, result["S3_FILESTORE_SECRET_KEY"])
self.assertEqual(key_id, result["S3_FILESTORE_ACCESS_KEY"])
......
......@@ -61,7 +61,8 @@ class TestCleverCloudMapperPostgres(TestMapper):
Chez Clever cloud les connections sont géré via un proxy,
il reste possible via une option chez eux d'avoir un acces direct
Dans ce cas les variables <POSTGRESQL_ADDON_DIRECT_PORT> et <POSTGRESQL_ADDON_DIRECT_HOST> sont disponibles.
Les variables <POSTGRESQL_ADDON_DIRECT_DB>, <POSTGRESQL_ADDON_DIRECT_USER> et <POSTGRESQL_ADDON_DIRECT_PASSWORD> n'existe pas
Les variables <POSTGRESQL_ADDON_DIRECT_DB>, <POSTGRESQL_ADDON_DIRECT_USER> et
<POSTGRESQL_ADDON_DIRECT_PASSWORD> n'existe pas
"""
db_host = "my-host.com"
......@@ -91,7 +92,8 @@ class TestCleverCloudMapperPostgres(TestMapper):
Chez Clever cloud les connections sont géré via un proxy,
il reste possible via une option chez eux d'avoir un acces direct
Dans ce cas les variables <POSTGRESQL_ADDON_DIRECT_PORT> et <POSTGRESQL_ADDON_DIRECT_HOST> sont disponibles.
Dans ce cas elles doivent être prise en priorité par rapport à <POSTGRESQL_ADDON_PORT> et <POSTGRESQL_ADDON_HOST>
Dans ce cas elles doivent être prise en priorité par rapport
à <POSTGRESQL_ADDON_PORT> et <POSTGRESQL_ADDON_HOST>
"""
db_host = "my-host.com"
......
......@@ -12,7 +12,7 @@ class TestOdooConfig(unittest.TestCase):
{
"--config": None,
"--update": "",
"--install": "",
"--init": "",
"--stop-after-init": False,
"--save": False,
"--addons-path": [],
......
......@@ -121,7 +121,7 @@ class TestOdooLauncher(unittest.TestCase):
self.assertEqual("--load=base,web,odoo_filestore_s3,odoo_session_redis", result.pop())
self.assertEqual("--no-http", result.pop())
self.assertEqual("--stop-after-init", result.pop())
self.assertEqual("--install=my_erp", result.pop())
self.assertEqual("--init=my_erp", result.pop())
self.assertEqual("--update=base,my_erp", result.pop())
self.assertEqual("--config=/tmp/odoo_rc.conf", result.pop())
......
......@@ -25,7 +25,7 @@ class TestOdooQueueJobMapper(TestMapper):
value4 = "4"
value5 = "5"
to_map = {
"REDIS_SESSION_ENABLE": "True",
"REDIS_SESSION_ENABLE": str(True),
"REDIS_SESSION_URL": value1,
"REDIS_SESSION_HOST": value2,
"REDIS_SESSION_PORT": value3,
......@@ -91,3 +91,25 @@ class TestOdooQueueJobMapper(TestMapper):
self.assertEqual(value3, result["REDIS_SESSION_PORT"])
self.assertEqual(value4, result["REDIS_SESSION_DB_INDEX"])
self.assertEqual(value5, result["REDIS_SESSION_PASSWORD"])
def test_not_enable(self):
value1 = "1"
value2 = "2"
value3 = "3"
value4 = "4"
value5 = "5"
to_map = {
"REDIS_URL": value1,
"REDIS_SESSION_HOST": value2,
"REDIS_SESSION_PORT": value3,
"REDIS_SESSION_DB_INDEX": value4,
"REDIS_SESSION_PASSWORD": value5,
}
result = self.mapper.map_vars(to_map)
self.assertEqual(self.nb_element, len(result.keys()))
self.assertEqual("False", result["REDIS_SESSION_ENABLE"])
self.assertIsNone(result["REDIS_SESSION_URL"])
self.assertIsNone(result["REDIS_SESSION_HOST"])
self.assertIsNone(result["REDIS_SESSION_PORT"])
self.assertIsNone(result["REDIS_SESSION_DB_INDEX"])
self.assertIsNone(result["REDIS_SESSION_PASSWORD"])
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment