This commit is contained in:
KaySar12 2025-04-12 15:55:53 +07:00
parent e541836cfc
commit 533f7982c8
3 changed files with 44 additions and 6 deletions

View File

@ -7,7 +7,7 @@ import lib.color_log as color_log
def setup_cli(subparsers):
module_parser = subparsers.add_parser("module", help="Manage instance module")
module_parser.add_argument(
"action", choices=["install", "uninstall", "upgrade"], help="Module action"
"action", choices=["install", "uninstall", "upgrade","update_list"], help="Module action"
)
module_parser.add_argument("instance", type=str, help="Instance Name")
module_parser.add_argument(
@ -36,6 +36,9 @@ def module(args):
for module_name in args.modules:
try:
match args.action:
case "update_list":
pbar.set_description(f"Installing {module_name}")
module_manager.update_list(args.instance)
case "install":
pbar.set_description(f"Installing {module_name}")
module_manager.install(args.instance, [module_name])

View File

@ -68,7 +68,7 @@ def update_instance(instance_name, action, force_pull=False):
color_log.Show("INFO", f"\n=== Starting update process for {instance_name} ===")
# 1. Pull latest code
color_log.Show("INFO", "Step 1/3: Pulling latest code...")
color_log.Show("INFO", "Step 1/4: Pulling latest code...")
pull_cmd = ["python", "utility/main.py", "git", "pull", instance_name]
if force_pull:
pull_cmd.append("--force")
@ -76,15 +76,22 @@ def update_instance(instance_name, action, force_pull=False):
color_log.Show("WARNING", f"Skipping module update for {instance_name} due to pull failure")
return False
# 2. Update modules
color_log.Show("INFO", "Step 2/3: Updating modules...")
# 2. Update module list
color_log.Show("INFO", "Step 2/4: Updating module list...")
module_list_cmd = ["python", "utility/main.py", "module", "update_list", instance_name]
if not run_command(module_list_cmd, f"Updating module list for {instance_name}"):
color_log.Show("WARNING", f"Module list update failed for {instance_name}")
return False
# 3. Update modules
color_log.Show("INFO", "Step 3/4: Updating modules...")
module_cmd = ["python", "utility/main.py", "module", action, instance_name]
if not run_command(module_cmd, f"Updating modules for {instance_name}"):
color_log.Show("WARNING", f"Module update failed for {instance_name}")
return False
# 3. Restart service
color_log.Show("INFO", "Step 3/3: Restarting service...")
# 4. Restart service
color_log.Show("INFO", "Step 4/4: Restarting service...")
restart_cmd = ["python", "utility/main.py", "service", "restart", instance_name]
if not run_command(restart_cmd, f"Restarting service for {instance_name}"):
color_log.Show("WARNING", f"Service restart failed for {instance_name}")

View File

@ -86,6 +86,34 @@ class OdooModuleManager:
"""Upgrade multiple modules for the specified instance(s)."""
self._manage_module("upgrade", instance_name, module_names)
def update_list(self, instance_name: str = None) -> dict:
"""Update the module list and return the number of updated and added modules.
Args:
instance_name (str): Name of the Odoo instance to update modules for
Returns:
dict: Dictionary containing the number of updated and added modules
"""
self.config.connect(instance_name)
try:
updated, added = self.config.execute(
instance_name,
"ir.module.module",
"update_list",
)
color_log.Show(
"OK",
f"Module list updated successfully in {instance_name}. Updated: {updated}, Added: {added}",
)
return {"updated": updated, "added": added}
except Exception as e:
color_log.Show(
"FAILED",
f"Error updating module list in {instance_name}: {e}",
)
return {"updated": 0, "added": 0}
def is_module_installed(self, instance_name: str, module_name: str) -> bool:
"""Check if a module is installed in the specified instance.