2025-01-14 18:08:41 +07:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
import argparse
|
|
|
|
import configparser
|
|
|
|
import shutil
|
|
|
|
import os
|
|
|
|
from dotenv import set_key
|
|
|
|
from pathlib import Path
|
|
|
|
import socket
|
|
|
|
import secrets
|
|
|
|
import string
|
|
|
|
import color_log
|
|
|
|
def find_available_port(start_port=80):
|
|
|
|
"""Finds an available port starting from the given port."""
|
|
|
|
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
|
|
|
|
while True:
|
|
|
|
try:
|
2025-01-15 14:28:10 +07:00
|
|
|
sock.bind(('0.0.0.0', start_port))
|
2025-01-14 18:08:41 +07:00
|
|
|
color_log.Show(3,f" {start_port} is Open")
|
|
|
|
return start_port
|
|
|
|
except OSError as e:
|
|
|
|
if e.errno == 98: # Address already in use
|
|
|
|
print(f"{start_port} already in use , Try other port ...")
|
|
|
|
start_port += 1
|
|
|
|
else:
|
|
|
|
raise
|
|
|
|
def main():
|
|
|
|
"""
|
|
|
|
Generates a random password and finds an available port.
|
|
|
|
Updates the Odoo configuration file and .env file with these values.
|
|
|
|
"""
|
|
|
|
parser = argparse.ArgumentParser(description="Generate Odoo configuration")
|
|
|
|
parser.add_argument('--db_user', type=str, help='')
|
|
|
|
parser.add_argument('--db_pass', type=str, help='')
|
|
|
|
parser.add_argument('--deploy_path', type=str, help='')
|
|
|
|
parser.add_argument('--addons_path', type=str, help='')
|
2025-01-16 09:38:47 +07:00
|
|
|
# parser.add_argument('--db_filter', type=str, help='')
|
2025-01-14 18:08:41 +07:00
|
|
|
parser.add_argument('--db_port', type=int, help='')
|
2025-01-15 11:43:11 +07:00
|
|
|
parser.add_argument('--db_server', type=str, help='')
|
2025-01-14 18:08:41 +07:00
|
|
|
args = parser.parse_args()
|
|
|
|
db_port = args.db_port
|
|
|
|
db_user = args.db_user
|
|
|
|
db_pass = args.db_pass
|
2025-01-15 11:28:13 +07:00
|
|
|
db_server = args.db_server
|
2025-01-14 18:08:41 +07:00
|
|
|
app_port = find_available_port(8069)
|
|
|
|
addons_path = args.addons_path
|
|
|
|
base_dir= args.deploy_path
|
2025-01-16 09:38:47 +07:00
|
|
|
# db_filter= args.db_filter
|
2025-01-14 18:08:41 +07:00
|
|
|
# Copy template files
|
|
|
|
os.makedirs(f"{base_dir}/etc", exist_ok=True)
|
|
|
|
color_log.Show(3,f"Copy {base_dir}/odoo.conf.template to {base_dir}/etc/odoo.conf")
|
|
|
|
shutil.copyfile(f'{base_dir}/odoo.conf.template', f'{base_dir}/odoo.conf')
|
|
|
|
|
|
|
|
# Update Odoo configuration file
|
|
|
|
config = configparser.ConfigParser()
|
|
|
|
config.read(f'{base_dir}/odoo.conf')
|
2025-01-15 11:40:55 +07:00
|
|
|
config['options']['db_host'] = str(db_server)
|
2025-01-14 18:08:41 +07:00
|
|
|
config['options']['db_user'] = db_user
|
|
|
|
config['options']['db_password'] = db_pass
|
|
|
|
config['options']['db_port'] = str(db_port)
|
|
|
|
config['options']['addons_path'] = addons_path
|
|
|
|
config['options']['xmlrpc_port'] = str(app_port)
|
2025-01-16 09:38:47 +07:00
|
|
|
config['options']['dbfilter'] = ".*"
|
2025-01-14 18:08:41 +07:00
|
|
|
config['options']['proxy_mode'] = "True"
|
|
|
|
with open(f'{base_dir}/odoo.conf', 'w') as configfile:
|
|
|
|
config.write(configfile)
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|