update init script for odoo modules install

benjamin
Florian Roger 11 months ago
parent 4084da5ee3
commit 4c12530963

@ -10,6 +10,7 @@ Ce script python va permettre d'automatiser l'installation des modules de base
import subprocess
import os
import shutil
import time
# Configuration
ODOO_URL = 'http://localhost:10014'
@ -58,10 +59,40 @@ Ce script python va permettre d'automatiser l'installation des modules de base
{'name': 'om_recurring_payments'},
{'name': 'om_account_daily_reports'},
{'name': 'om_account_followup'},
{'name': 'om_account_accountant', 'dir': 'om_account_accountant'}
{'name': 'om_account_accountant', 'dir': 'om_account_accountant'},
{'name': 'om_hr_payroll'},
{'name': 'om_hr_payroll_account'}
]},
{'url': 'https://github.com/CybroOdoo/CybroAddons',
'apps': [
{'name': 'activity_reminder'},
]},
{'url': 'https://github.com/OCA/web',
'apps': [
{'name': 'web_responsive'}
]}
]
def configure_folders():
#os.makedirs('addons', exist_ok=True)
subprocess.run(["setfacl", "-m", "u:101:rwx", './addons'], check=True)
subprocess.run(["setfacl", "-d", "-m", "u:101:rwx", './addons'], check=True)
subprocess.run(["setfacl", "-m", "u:101:rwx", './etc'], check=True)
subprocess.run(["setfacl", "-d", "-m", "u:101:rwx", './etc'], check=True)
def merge_directories(src, dst):
for item in os.listdir(src):
if item != '.git':
s = os.path.join(src, item)
d = os.path.join(dst, item)
if os.path.isdir(s):
if not os.path.exists(d):
shutil.copytree(s, d)
else:
merge_directories(s, d)
else:
shutil.copy2(s, d)
def connect_odoo():
# Connect to the Odoo server
odoo = odoorpc.ODOO('localhost', port=10014)
@ -76,6 +107,7 @@ Ce script python va permettre d'automatiser l'installation des modules de base
if module_id:
module = odoo.env['ir.module.module'].browse(module_id)[0]
if module.state not in ['installed', 'to upgrade']:
time.sleep(1)
module.button_immediate_install()
print(f"Module {odoo_app} has been installed.")
else:
@ -86,51 +118,72 @@ Ce script python va permettre d'automatiser l'installation des modules de base
def install_apps(odoo):
for odoo_app in APPS_TO_INSTALL:
install_app(odoo, odoo_app)
time.sleep(1)
def dl_modules(group):
repo_url = group['url'].rstrip('/')
addons_path = "addons"
os.makedirs(addons_path, exist_ok=True)
git_dir_path = os.path.join(addons_path, '.git')
#git_dir_path = os.path.join(addons_path, '.git')
#subprocess.run(["mkdir", "-p", git_dir_path])
sparse_checkout_lines = []
search_git = True
#search_git = True
for app in group['apps']:
app_dir = app['dir'] if 'dir' in app else app['name']
app_path = os.path.join(addons_path, app_dir)
backup_git_path = os.path.join(app_path, ".git_backup")
#app_path = os.path.join(addons_path, app_dir)
#backup_git_path = os.path.join(app_path, ".git_backup")
sparse_checkout_lines.append(f"{app_dir}\n")
subprocess.run(["mkdir", "-p", app_path])
if search_git and os.path.isdir(backup_git_path):
subprocess.run(["mkdir", "-p", git_dir_path])
shutil.copytree(backup_git_path, git_dir_path, dirs_exist_ok=True)
search_git = False
#subprocess.run(["mkdir", "-p", app_path])
#if search_git and os.path.isdir(backup_git_path):
# #shutil.copytree(backup_git_path, git_dir_path, dirs_exist_ok=True)
# search_git = False
'''
for app in group['apps']:
app_dir = app['dir'] if 'dir' in app else app['name']
app_path = os.path.join(addons_path, app_dir)
backup_git_path = os.path.join(app_path, ".git_backup")
#backup_git_path = os.path.join(app_path, ".git_backup")
if os.path.isdir(backup_git_path):
shutil.rmtree(backup_git_path)
subprocess.run(["mkdir", "-p", backup_git_path])
shutil.copytree(git_dir_path, backup_git_path, dirs_exist_ok=True)
#shutil.copytree(git_dir_path, backup_git_path, dirs_exist_ok=True)
print(f"backup for app {app['name']}")
'''
clone_path = 'tmp'
clone_full_path = os.path.join(addons_path, clone_path)
git_dir_path = os.path.join(clone_full_path, '.git')
sparse_checkout_file_path = os.path.join(git_dir_path, 'info', 'sparse-checkout')
branch_name = "16.0"
if not os.path.isdir(git_dir_path):
subprocess.run(["git", "init"], cwd=addons_path)
subprocess.run(["git", "remote", "add", "origin", repo_url], cwd=addons_path)
subprocess.run(["git", "config", "core.sparseCheckout", "true"], cwd=addons_path, check=True)
print("starting git clone")
subprocess.run(["git", "clone", "--filter=blob:none", "--sparse", "--branch", branch_name, "--depth", "1", repo_url, clone_path], cwd=addons_path, check=True)
if not os.path.isdir(sparse_checkout_file_path):
#subprocess.run(["git", "init"], cwd=addons_path)
#subprocess.run(["git", "remote", "add", "origin", repo_url], cwd=addons_path)
subprocess.run(["git", "config", "core.sparseCheckout", "true"], cwd=clone_full_path, check=True)
with open(sparse_checkout_file_path, "w") as sparse_checkout_file:
sparse_checkout_file.writelines(sparse_checkout_lines)
subprocess.run(["git", "pull", "origin", branch_name], cwd=addons_path, check=True)
shutil.rmtree(git_dir_path)
#subprocess.run(["git", "fetch", "--filter=blob:none", "--sparse", "--depth", "1", "origin", branch_name], cwd=addons_path, check=True)
#subprocess.run(["git", "clone", "--filter=blob:none", "--sparse", "--depth", "1"], cwd=addons_path, check=True)
print("starting git checkout")
subprocess.run(["git", "checkout", branch_name], cwd=clone_full_path, check=True)
#subprocess.run(["git", "pull", "--depth=1", "origin", branch_name], cwd=addons_path, check=True)
#shutil.rmtree(git_dir_path)
for folder in os.listdir(clone_full_path):
if folder != '.git':
folder_path = os.path.join(clone_full_path, folder)
merge_directories(clone_full_path, addons_path)
shutil.rmtree(clone_full_path)
print(f"Modules {', '.join(app['name'] for app in group['apps'])} has been downloaded")
def update_module_list(odoo):
@ -142,18 +195,21 @@ Ce script python va permettre d'automatiser l'installation des modules de base
added_modules = module_update.added
print(f"Updated modules: {updated_modules}, Added modules: {added_modules}")
def install_modules(odoo):
for group in MODULES_TO_INSTALL:
dl_modules(group)
time.sleep(1)
update_module_list(odoo)
time.sleep(1)
for group in MODULES_TO_INSTALL:
for app in group['apps']:
install_app(odoo, app['name'])
def main():
configure_folders()
odoo = connect_odoo()
install_apps(odoo)
#time.sleep(5)
install_modules(odoo)
print("Script execution finished!")

Loading…
Cancel
Save