update
This commit is contained in:
parent
b249bc7149
commit
dbd5a8325c
64
cli.py
64
cli.py
@ -1,35 +1,73 @@
|
||||
import argparse
|
||||
|
||||
import tqdm
|
||||
from services.odoo.service import OdooServiceManager
|
||||
from services.odoo.module import OdooModuleManager
|
||||
|
||||
|
||||
def service(args):
|
||||
service = OdooServiceManager(config_path="utility/config/settings.yaml")
|
||||
match args.action:
|
||||
case "start":
|
||||
service.start_service(args.service)
|
||||
service.start_service(args.instance)
|
||||
case "stop":
|
||||
service.stop_service(args.service)
|
||||
service.stop_service(args.instance)
|
||||
case "restart":
|
||||
service.restart_service(args.service)
|
||||
service.restart_service(args.instance)
|
||||
case _:
|
||||
print("Invalid action")
|
||||
|
||||
|
||||
def module(args):
|
||||
module_manager = OdooModuleManager(config_path="utility/config/settings.yaml")
|
||||
|
||||
# If modules are provided in the command line
|
||||
if args.modules:
|
||||
print(f"Processing modules: {', '.join(args.modules)} for {args.instance}")
|
||||
else:
|
||||
# Fallback if no modules are provided (can use default from instance settings)
|
||||
print(f"No modules specified. Using default modules for {args.instance}")
|
||||
args.modules = module_manager.get_modules(args.instance)
|
||||
|
||||
# Create a progress bar using tqdm
|
||||
for module_name in tqdm.tqdm(
|
||||
args.modules, desc="Processing modules", unit="module"
|
||||
):
|
||||
match args.action:
|
||||
case "install":
|
||||
module_manager.install(args.instance, [module_name])
|
||||
case "uninstall":
|
||||
module_manager.uninstall(args.instance, [module_name])
|
||||
case "upgrade":
|
||||
module_manager.upgrade(args.instance, [module_name])
|
||||
case _:
|
||||
print("Invalid action")
|
||||
|
||||
|
||||
def setup_cli():
|
||||
parser = argparse.ArgumentParser(description="Service Manager CLI")
|
||||
parser.add_argument(
|
||||
"-v", "--verbose", action="store_true", help="Enable verbose mode"
|
||||
)
|
||||
|
||||
subparsers = parser.add_subparsers(
|
||||
dest="command", required=True, help="Available commands"
|
||||
)
|
||||
subparsers = parser.add_subparsers(dest="command", required=True)
|
||||
|
||||
service_parser = subparsers.add_parser("service", help="Manage instance service")
|
||||
service_parser.add_argument("action", type=str, help="start/stop/restart")
|
||||
service_parser.add_argument("service", type=str, help="Name of the service")
|
||||
service_parser.set_defaults(func=service)
|
||||
|
||||
service_parser.add_argument(
|
||||
"action", choices=["start", "stop", "restart"], help="Service action"
|
||||
)
|
||||
service_parser.add_argument("instance", type=str, help="Instance Name")
|
||||
service_parser.set_defaults(func=service) # Fixed: Correct function assignment
|
||||
|
||||
module_parser = subparsers.add_parser("module", help="Manage instance module")
|
||||
module_parser.add_argument(
|
||||
"action", choices=["install", "uninstall", "upgrade"], help="Module action"
|
||||
)
|
||||
module_parser.add_argument("instance", type=str, help="Instance Name")
|
||||
module_parser.add_argument(
|
||||
"--modules", "-m", nargs="+", help="List of modules to process"
|
||||
)
|
||||
module_parser.set_defaults(func=module) # Fixed: Correct function assignment
|
||||
|
||||
return parser
|
||||
|
||||
@ -37,7 +75,11 @@ def setup_cli():
|
||||
def main():
|
||||
parser = setup_cli()
|
||||
args = parser.parse_args()
|
||||
args.func(args)
|
||||
|
||||
if hasattr(args, "func"): # Ensuring `func` is set
|
||||
args.func(args)
|
||||
else:
|
||||
print("Invalid command. Use --help for more details.")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
@ -1,12 +1,27 @@
|
||||
odoo_instances:
|
||||
- name: "server"
|
||||
host: "10.1.1.34"
|
||||
- name: "ftacpa"
|
||||
host: "10.1.1.31"
|
||||
port: 8069
|
||||
database: "ftacpa"
|
||||
username: "nextzen"
|
||||
password: "smartyourlife"
|
||||
type: "systemctl"
|
||||
service_name: "odoo18"
|
||||
git:
|
||||
repo_url: "https://hoangvv:smartyourlife@git.nextzenos.com/NextERP/Odoo18-FTACPA.git"
|
||||
branch: "community/demo/ftacpa"
|
||||
local_path: "/opt/odoo18/addons"
|
||||
ssh:
|
||||
user: root
|
||||
password: Smartyourlife123@*
|
||||
key_path: "/root/.ssh/privatessh.key"
|
||||
odoo_instances:
|
||||
- name: "ftacpa"
|
||||
host: "10.1.1.31"
|
||||
port: 8069
|
||||
database: "server"
|
||||
username: "nextzen"
|
||||
password: "smartyourlife"
|
||||
module_names:
|
||||
- "base"
|
||||
type: "systemctl"
|
||||
service_name: "odoo18"
|
||||
git:
|
||||
|
@ -1,3 +1,4 @@
|
||||
odoorpc==0.9.0
|
||||
GitPython==3.1.43
|
||||
PyYAML==6.0.1
|
||||
PyYAML==6.0.1
|
||||
tqdm
|
@ -7,9 +7,11 @@ class OdooModuleManager:
|
||||
def __init__(self, config_path: str = "config/settings.yaml"):
|
||||
self.config = OdooConnection(config_path)
|
||||
|
||||
def _manage_module(self, action: str, instance_name: str = None) -> None:
|
||||
def _manage_module(
|
||||
self, action: str, instance_name: str = None, module_names: list = None
|
||||
) -> None:
|
||||
"""Generic method to install, uninstall, or upgrade modules."""
|
||||
if action not in ["install", "uninstall", "upgrade"]:
|
||||
if action not in {"install", "uninstall", "upgrade"}:
|
||||
raise ValueError(f"Invalid action: {action}")
|
||||
|
||||
self.config.connect(instance_name)
|
||||
@ -19,53 +21,49 @@ class OdooModuleManager:
|
||||
continue
|
||||
|
||||
print(f"Processing instance: {instance['name']}")
|
||||
module_names = instance.get("module_names", [])
|
||||
|
||||
if not module_names:
|
||||
print(
|
||||
f"No modules specified for {instance['name']}, skipping {action}."
|
||||
)
|
||||
continue
|
||||
|
||||
for module_name in module_names:
|
||||
print(
|
||||
f"{action.capitalize()}ing module: {module_name} in {instance['name']}"
|
||||
)
|
||||
try:
|
||||
print(
|
||||
f"{action.capitalize()}ing module: {module_name} in {instance['name']}"
|
||||
)
|
||||
|
||||
module_ids = self.config.execute(
|
||||
instance["name"],
|
||||
"ir.module.module",
|
||||
"search",
|
||||
[("name", "=", module_name), ("state", "=", "installed")],
|
||||
[("name", "=", module_name)],
|
||||
)
|
||||
if module_ids:
|
||||
button_action = f"button_immediate_{action}"
|
||||
self.config.execute(
|
||||
instance["name"],
|
||||
"ir.module.module",
|
||||
button_action,
|
||||
[module_ids],
|
||||
)
|
||||
|
||||
if not module_ids:
|
||||
print(
|
||||
f"Module {module_name} {action}ed successfully in {instance['name']}"
|
||||
)
|
||||
else:
|
||||
print(
|
||||
f"Module {module_name} not found or not installed in {instance['name']}"
|
||||
f"Module {module_name} not found in {instance['name']}, skipping."
|
||||
)
|
||||
continue
|
||||
|
||||
button_action = f"button_immediate_{action}"
|
||||
self.config.execute(
|
||||
instance["name"],
|
||||
"ir.module.module",
|
||||
button_action,
|
||||
module_ids, # Pass list directly instead of wrapping in another list
|
||||
)
|
||||
|
||||
print(
|
||||
f"Module {module_name} {action}ed successfully in {instance['name']}"
|
||||
)
|
||||
except Exception as e:
|
||||
print(
|
||||
f"Failed to {action} {module_name} in {instance['name']}: {e}"
|
||||
f"Error while {action}ing {module_name} in {instance['name']}: {e}"
|
||||
)
|
||||
|
||||
def install(self, instance_name: str = None) -> None:
|
||||
def install(self, instance_name: str = None,module_names: list = None) -> None:
|
||||
"""Install multiple modules for the specified instance(s)."""
|
||||
self._manage_module("install", instance_name)
|
||||
self._manage_module("install", instance_name,module_names)
|
||||
|
||||
def uninstall(self, instance_name: str = None) -> None:
|
||||
def uninstall(self, instance_name: str = None,module_names: list = None) -> None:
|
||||
"""Uninstall multiple modules for the specified instance(s)."""
|
||||
self._manage_module("uninstall", instance_name)
|
||||
self._manage_module("uninstall", instance_name,module_names)
|
||||
|
||||
def upgrade(self, instance_name: str = None) -> None:
|
||||
def upgrade(self, instance_name: str = None,module_names: list = None) -> None:
|
||||
"""Upgrade multiple modules for the specified instance(s)."""
|
||||
self._manage_module("upgrade", instance_name)
|
||||
self._manage_module("upgrade", instance_name,module_names)
|
||||
|
Loading…
Reference in New Issue
Block a user