update utility
This commit is contained in:
parent
57286a15e3
commit
6caea7e002
98
cli.py
98
cli.py
@ -1,98 +0,0 @@
|
||||
import argparse
|
||||
|
||||
import tqdm
|
||||
from services.odoo.service import OdooServiceManager
|
||||
from services.odoo.module import OdooModuleManager
|
||||
import lib.color_log as color_log
|
||||
|
||||
|
||||
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 _:
|
||||
color_log.Show(
|
||||
"FAILED",
|
||||
f"Invalid action '{args.action}' for service management.",
|
||||
)
|
||||
|
||||
|
||||
def module(args):
|
||||
module_manager = OdooModuleManager(config_path="utility/config/settings.yaml")
|
||||
|
||||
# If modules are provided in the command line
|
||||
if args.modules:
|
||||
color_log.Show(
|
||||
"INFO",
|
||||
f"Processing modules: {', '.join(args.modules)} for {args.instance}",
|
||||
)
|
||||
else:
|
||||
# Fallback if no modules are provided (can use default from instance settings)
|
||||
color_log.Show(
|
||||
"INFO",
|
||||
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 _:
|
||||
color_log.Show(
|
||||
"FAILED",
|
||||
f"Invalid action '{args.action}' for module management.",
|
||||
)
|
||||
|
||||
|
||||
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()
|
0
cli/__init__.py
Normal file
0
cli/__init__.py
Normal file
47
cli/module.py
Normal file
47
cli/module.py
Normal file
@ -0,0 +1,47 @@
|
||||
# cli/module.py
|
||||
import tqdm
|
||||
from services.odoo.module import OdooModuleManager
|
||||
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"
|
||||
)
|
||||
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)
|
||||
return module_parser
|
||||
|
||||
|
||||
def module(args):
|
||||
module_manager = OdooModuleManager(config_path="utility/config/settings.yaml")
|
||||
if args.modules:
|
||||
color_log.Show(
|
||||
"INFO",
|
||||
f"Processing modules: {', '.join(args.modules)} for {args.instance}",
|
||||
)
|
||||
else:
|
||||
color_log.Show(
|
||||
"INFO",
|
||||
f"No modules specified. Using default modules for {args.instance}",
|
||||
)
|
||||
args.modules = module_manager.get_modules(args.instance)
|
||||
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 _:
|
||||
color_log.Show(
|
||||
"FAILED",
|
||||
f"Invalid action '{args.action}' for module management.",
|
||||
)
|
29
cli/service.py
Normal file
29
cli/service.py
Normal file
@ -0,0 +1,29 @@
|
||||
# cli/service.py
|
||||
from services.odoo.service import OdooServiceManager
|
||||
import lib.color_log as color_log
|
||||
|
||||
|
||||
def setup_cli(subparsers):
|
||||
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)
|
||||
return service_parser
|
||||
|
||||
|
||||
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 _:
|
||||
color_log.Show(
|
||||
"FAILED",
|
||||
f"Invalid action '{args.action}' for service management.",
|
||||
)
|
@ -13,24 +13,6 @@ odoo_instances:
|
||||
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"
|
||||
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/ftacpa/addons"
|
||||
ssh:
|
||||
user: root
|
||||
password: Smartyourlife123@*
|
||||
key_path: "/root/.ssh/privatessh.key"
|
||||
# - name: "server1_test"
|
||||
# host: "server1.example.com"
|
||||
|
@ -1,41 +1,33 @@
|
||||
odoo_instances:
|
||||
- name: "server"
|
||||
host: "10.1.1.34"
|
||||
port: 8069
|
||||
database: "server"
|
||||
modules:
|
||||
- "hr_holidays"
|
||||
- "timesheet"
|
||||
- "hr"
|
||||
common: &common
|
||||
username: "nextzen"
|
||||
password: "smartyourlife"
|
||||
type: "systemctl"
|
||||
service_name: "odoo18"
|
||||
git:
|
||||
git: &git_config
|
||||
repo_url: "https://hoangvv:smartyourlife@git.nextzenos.com/NextERP/Odoo18-FTACPA.git"
|
||||
branch: "community/demo/ftacpa"
|
||||
local_path: "/opt/ftacpa/addons"
|
||||
ssh:
|
||||
ssh: &ssh_config
|
||||
user: root
|
||||
password: Smartyourlife123@*
|
||||
key_path: "/root/.ssh/privatessh.key"
|
||||
# - name: "server1_test"
|
||||
# host: "server1.example.com"
|
||||
# port: 8069
|
||||
# database: "test_db1"
|
||||
# username: "admin"
|
||||
# password: "test_password"
|
||||
# module_names:
|
||||
# - "your_module"
|
||||
# type: "docker"
|
||||
# - name: "server2_prod"
|
||||
# host: "server2.example.com"
|
||||
# port: 8070
|
||||
# database: "prod_db2"
|
||||
# username: "admin"
|
||||
# password: "admin_password"
|
||||
# module_names:
|
||||
# - "your_module"
|
||||
# - "custom_module"
|
||||
# - "third_module"
|
||||
# type: "systemctl"
|
||||
modules: &module_list
|
||||
- "hr_holidays"
|
||||
- "timesheet"
|
||||
- "hr"
|
||||
|
||||
odoo_instances:
|
||||
- name: "server"
|
||||
host: "10.1.1.34"
|
||||
port: 8069
|
||||
database: "server"
|
||||
action: "update"
|
||||
modules: *module_list
|
||||
<<: *common # Inherit common settings
|
||||
|
||||
- name: "server2"
|
||||
host: "10.1.1.34"
|
||||
port: 8069
|
||||
database: "server2"
|
||||
action: "install"
|
||||
modules: *module_list
|
||||
<<: *common # Inherit common settings
|
29
main.py
29
main.py
@ -1,4 +1,29 @@
|
||||
import cli
|
||||
# main.py
|
||||
import argparse
|
||||
from cli.service import setup_cli as setup_service_cli
|
||||
from cli.module import setup_cli as setup_module_cli
|
||||
|
||||
|
||||
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)
|
||||
setup_service_cli(subparsers)
|
||||
setup_module_cli(subparsers)
|
||||
return parser
|
||||
|
||||
|
||||
def main():
|
||||
parser = setup_cli()
|
||||
args = parser.parse_args()
|
||||
|
||||
if hasattr(args, "func"):
|
||||
args.func(args)
|
||||
else:
|
||||
print("Invalid command. Use --help for more details.")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
cli.main()
|
||||
main()
|
||||
|
Loading…
Reference in New Issue
Block a user