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"
|
local_path: "/opt/odoo18/addons"
|
||||||
ssh:
|
ssh:
|
||||||
user: root
|
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"
|
key_path: "/root/.ssh/privatessh.key"
|
||||||
# - name: "server1_test"
|
# - name: "server1_test"
|
||||||
# host: "server1.example.com"
|
# host: "server1.example.com"
|
||||||
|
@ -1,41 +1,33 @@
|
|||||||
odoo_instances:
|
common: &common
|
||||||
- name: "server"
|
|
||||||
host: "10.1.1.34"
|
|
||||||
port: 8069
|
|
||||||
database: "server"
|
|
||||||
modules:
|
|
||||||
- "hr_holidays"
|
|
||||||
- "timesheet"
|
|
||||||
- "hr"
|
|
||||||
username: "nextzen"
|
username: "nextzen"
|
||||||
password: "smartyourlife"
|
password: "smartyourlife"
|
||||||
type: "systemctl"
|
type: "systemctl"
|
||||||
service_name: "odoo18"
|
service_name: "odoo18"
|
||||||
git:
|
git: &git_config
|
||||||
repo_url: "https://hoangvv:smartyourlife@git.nextzenos.com/NextERP/Odoo18-FTACPA.git"
|
repo_url: "https://hoangvv:smartyourlife@git.nextzenos.com/NextERP/Odoo18-FTACPA.git"
|
||||||
branch: "community/demo/ftacpa"
|
branch: "community/demo/ftacpa"
|
||||||
local_path: "/opt/ftacpa/addons"
|
local_path: "/opt/ftacpa/addons"
|
||||||
ssh:
|
ssh: &ssh_config
|
||||||
user: root
|
user: root
|
||||||
password: Smartyourlife123@*
|
|
||||||
key_path: "/root/.ssh/privatessh.key"
|
key_path: "/root/.ssh/privatessh.key"
|
||||||
# - name: "server1_test"
|
modules: &module_list
|
||||||
# host: "server1.example.com"
|
- "hr_holidays"
|
||||||
# port: 8069
|
- "timesheet"
|
||||||
# database: "test_db1"
|
- "hr"
|
||||||
# username: "admin"
|
|
||||||
# password: "test_password"
|
odoo_instances:
|
||||||
# module_names:
|
- name: "server"
|
||||||
# - "your_module"
|
host: "10.1.1.34"
|
||||||
# type: "docker"
|
port: 8069
|
||||||
# - name: "server2_prod"
|
database: "server"
|
||||||
# host: "server2.example.com"
|
action: "update"
|
||||||
# port: 8070
|
modules: *module_list
|
||||||
# database: "prod_db2"
|
<<: *common # Inherit common settings
|
||||||
# username: "admin"
|
|
||||||
# password: "admin_password"
|
- name: "server2"
|
||||||
# module_names:
|
host: "10.1.1.34"
|
||||||
# - "your_module"
|
port: 8069
|
||||||
# - "custom_module"
|
database: "server2"
|
||||||
# - "third_module"
|
action: "install"
|
||||||
# type: "systemctl"
|
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__":
|
if __name__ == "__main__":
|
||||||
cli.main()
|
main()
|
||||||
|
Loading…
Reference in New Issue
Block a user