update init script

This commit is contained in:
Florian du Garage Num 2023-11-02 09:57:08 +01:00
parent 4c12530963
commit 01787a81ad

View File

@ -70,6 +70,10 @@ Ce script python va permettre d'automatiser l'installation des modules de base
{'url': 'https://github.com/OCA/web', {'url': 'https://github.com/OCA/web',
'apps': [ 'apps': [
{'name': 'web_responsive'} {'name': 'web_responsive'}
]},
{'url': 'https://gitlab.com/garagenum/odoo/gn_discount',
'apps': [
{'name': None}
]} ]}
] ]
@ -124,35 +128,13 @@ Ce script python va permettre d'automatiser l'installation des modules de base
repo_url = group['url'].rstrip('/') repo_url = group['url'].rstrip('/')
addons_path = "addons" addons_path = "addons"
#git_dir_path = os.path.join(addons_path, '.git')
#subprocess.run(["mkdir", "-p", git_dir_path])
sparse_checkout_lines = [] sparse_checkout_lines = []
#search_git = True
for app in group['apps']: for app in group['apps']:
app_dir = app['dir'] if 'dir' in app else app['name'] if app['name'] != None:
#app_path = os.path.join(addons_path, app_dir) app_dir = app['dir'] if 'dir' in app else app['name']
#backup_git_path = os.path.join(app_path, ".git_backup") sparse_checkout_lines.append(f"{app_dir}\n")
sparse_checkout_lines.append(f"{app_dir}\n") clone_path = 'tmp' if group['apps'][0]['name'] != None else os.path.join('tmp', group['url'].split('/')[-1])
#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")
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)
print(f"backup for app {app['name']}")
'''
clone_path = 'tmp'
clone_full_path = os.path.join(addons_path, clone_path) clone_full_path = os.path.join(addons_path, clone_path)
git_dir_path = os.path.join(clone_full_path, '.git') git_dir_path = os.path.join(clone_full_path, '.git')
sparse_checkout_file_path = os.path.join(git_dir_path, 'info', 'sparse-checkout') sparse_checkout_file_path = os.path.join(git_dir_path, 'info', 'sparse-checkout')
@ -162,29 +144,19 @@ Ce script python va permettre d'automatiser l'installation des modules de base
subprocess.run(["git", "clone", "--filter=blob:none", "--sparse", "--branch", branch_name, "--depth", "1", repo_url, clone_path], cwd=addons_path, check=True) 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): 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) subprocess.run(["git", "config", "core.sparseCheckout", "true"], cwd=clone_full_path, check=True)
with open(sparse_checkout_file_path, "w") as sparse_checkout_file: with open(sparse_checkout_file_path, "w") as sparse_checkout_file:
sparse_checkout_file.writelines(sparse_checkout_lines) sparse_checkout_file.writelines(sparse_checkout_lines)
#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") print("starting git checkout")
subprocess.run(["git", "checkout", branch_name], cwd=clone_full_path, check=True) 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): src_path = os.path.join(addons_path, 'tmp')
if folder != '.git': merge_directories(src_path, addons_path)
folder_path = os.path.join(clone_full_path, folder) shutil.rmtree(src_path)
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") print(f"Modules {', '.join(app['name'] if app['name'] else group['url'] for app in group['apps'])} has been downloaded")
def update_module_list(odoo): def update_module_list(odoo):
ModuleUpdate = odoo.env['base.module.update'] ModuleUpdate = odoo.env['base.module.update']
@ -203,7 +175,8 @@ Ce script python va permettre d'automatiser l'installation des modules de base
time.sleep(1) time.sleep(1)
for group in MODULES_TO_INSTALL: for group in MODULES_TO_INSTALL:
for app in group['apps']: for app in group['apps']:
install_app(odoo, app['name']) app_name = app['name'] if app['name'] != None else group['url'].split('/')[-1]
install_app(odoo, app_name)
def main(): def main():
configure_folders() configure_folders()