87 lines
2.9 KiB
Python
87 lines
2.9 KiB
Python
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.instance)
|
|
case "stop":
|
|
service.stop_service(args.instance)
|
|
case "restart":
|
|
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)
|
|
|
|
service_parser = subparsers.add_parser("service", help="Manage instance 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
|
|
|
|
|
|
def main():
|
|
parser = setup_cli()
|
|
args = parser.parse_args()
|
|
|
|
if hasattr(args, "func"): # Ensuring `func` is set
|
|
args.func(args)
|
|
else:
|
|
print("Invalid command. Use --help for more details.")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|