Commit 83def4da authored by Alexis PASQUIER's avatar Alexis PASQUIER
Browse files

🔖 1.3.2

Ajout interface ABC pour simplifier une abstraction du fichier de config
Correction assert
parent 80ecebe8
Pipeline #77002 failed with stages
in 2 minutes and 32 seconds
......@@ -16,7 +16,7 @@ from typing import Dict, List, Optional
from addons_installer import AddonsInstaller, AddonsRegistry
from .odoo_config_maker import OdooConfig
from .odoo_config_maker import OdooConfig, OdooConfigFileRef, ToOdooArgs
_logger = logging.getLogger("launch")
_logger.setLevel(logging.DEBUG)
......@@ -35,8 +35,8 @@ class Launcher(object):
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)
assert odoo_rc, "No Odoo config file path is provided"
self.odoo_rc = os.path.abspath(os.path.expanduser(odoo_rc))
ndp_server_path = ns.server_path or server_path
assert ndp_server_path, "Server path is provided"
self.ndp_server_path = os.path.abspath(os.path.expanduser(ndp_server_path))
......@@ -99,7 +99,13 @@ class Launcher(object):
def launch(self, env_vars):
# type: (Dict[str, str]) -> subprocess.Popen
return self._launch_odoo("ndpserver", None)
return self._launch_odoo(
"ndpserver",
OdooConfigFileRef(
self.odoo_rc,
),
)
def config_launch_update(self, env_vars):
# type: (Dict[str, str]) -> OdooConfig
......@@ -121,7 +127,7 @@ class Launcher(object):
return self._execute_popen([sys.executable, "-m", "maintenance_server"])
def normalize_args(self, srv, config):
# type: (str, Optional[OdooConfig]) -> List[str]
# type: (str, Optional[ToOdooArgs]) -> List[str]
cmd_args = [sys.executable, os.path.join(self.odoo_path, "odoo-bin")]
if srv:
cmd_args.append("--addons-path=%s" % self.ndp_server_path)
......@@ -129,7 +135,7 @@ class Launcher(object):
return cmd_args + (config and config.to_odoo_args() or [])
def _launch_odoo(self, srv, config):
# type: (str, Optional[OdooConfig]) -> subprocess.Popen
# type: (str, Optional[ToOdooArgs]) -> subprocess.Popen
return self._execute_popen(self.normalize_args(srv, config))
def _execute_popen(self, cmd):
......
......@@ -6,7 +6,7 @@ import pprint
from collections import OrderedDict
from typing import Dict, List, Optional
from .api import ConfigConvert, Dictable, EnvMapper, OdooConfigABC
from .api import ABC, ConfigConvert, Dictable, EnvMapper, OdooConfigABC
from .config_section import (
AddonsPathConfigSection,
DatabaseOdooConfigSection,
......@@ -39,7 +39,21 @@ def is_main_instance(env_vars):
return env_vars.get("INSTANCE_NUMBER", 0) == 0
class OdooConfig(OdooConfigABC, Dictable):
class ToOdooArgs(ABC):
def to_odoo_args(self):
# type: () -> List[str]
...
class OdooConfigFileRef(ToOdooArgs):
def __init__(self, odoo_rc=None):
self.odoo_rc = odoo_rc
def to_odoo_args(self):
return [f"--config={self.odoo_rc}"]
class OdooConfig(OdooConfigABC, Dictable, ToOdooArgs):
def __init__(self, env_vars, odoo_rc=None, main_instance=None):
super(OdooConfig, self).__init__(main_instance is None and is_main_instance(env_vars))
self._odoo_version = self.to_int(env_vars.get("ODOO_VERSION"))
......
[metadata]
name = odoo_launcher
version = 1.3.1
version = 1.3.2
url = https://gitlab.ndp-systemes.fr/python-libs/odoo_launcher
license = GPLv3
author = Alexis Pasquier, NDP Systemes
......
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