[IMP] script repo change addons list from backup file

- check module to identify addons path
This commit is contained in:
Mathieu Benoit 2026-02-13 01:29:48 -05:00
parent 54f8ba0feb
commit c580493099
3 changed files with 155 additions and 2 deletions

View file

@ -0,0 +1,101 @@
#!/usr/bin/env python3
# © 2021-2025 TechnoLibre (http://www.technolibre.ca)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
import argparse
import json
import logging
import os
import sys
import zipfile
new_path = os.path.normpath(
os.path.join(os.path.dirname(__file__), "..", "..")
)
sys.path.append(new_path)
from script.execute import execute
logging.basicConfig(level=os.environ.get("LOGLEVEL", "INFO"))
_logger = logging.getLogger(__name__)
def get_config():
"""Parse command line arguments, extracting the config file name,
returning the union of config file and command line arguments
:return: dict of config file settings and command line arguments
"""
parser = argparse.ArgumentParser(
formatter_class=argparse.RawDescriptionHelpFormatter,
description="""\
Extract all repo path from installed module into backup.
Use --backup_path or --backup_name
""",
epilog="""\
""",
)
parser.add_argument("--backup_path", help="Backup file path")
parser.add_argument("--backup_name", help="Backup file name")
parser.add_argument(
"--debug",
action="store_true",
help="Will show all debug and execution information",
)
args = parser.parse_args()
die(
not (bool(args.backup_path) or bool(args.backup_name)),
"Take --backup_path or --backup_name",
)
return args
def main():
config = get_config()
if config.backup_path:
file_path = config.backup_path
elif not config.backup_name.endswith(".zip"):
file_path = os.path.join("image_db", f"{config.backup_name}.zip")
else:
file_path = os.path.join("image_db", config.backup_name)
with zipfile.ZipFile(file_path, "r") as zip_ref:
manifest_file = zip_ref.open("manifest.json")
json_manifest_file = json.load(manifest_file)
lst_module = set(json_manifest_file.get("modules").keys())
cmd = "parallel ::: " + " ".join(
[
f"'./script/addons/check_addons_exist.py --output_path -m \"{a}\"'"
for a in lst_module
]
)
execute_cmd = execute.Execute()
status, output = execute_cmd.exec_command_live(
cmd,
quiet=not config.debug,
source_erplibre=False,
single_source_erplibre=True,
return_status_and_output=True,
)
set_path_repo = set()
for line_module_path in output:
line_repo = os.path.dirname(line_module_path)
set_path_repo.add(line_repo)
for path_repo in set_path_repo:
print(path_repo)
def die(cond, message, code=1):
if cond:
print(message, file=sys.stderr)
sys.exit(code)
if __name__ == "__main__":
main()

View file

@ -15,6 +15,7 @@ new_path = os.path.normpath(
)
sys.path.append(new_path)
from script.execute import execute
from script.git.git_tool import GitTool
_logger = logging.getLogger(__name__)
@ -52,6 +53,18 @@ def get_config():
action="store_true",
help="Will remove odoo path, need this feature for OpenUpgrade when Odoo <= 13",
)
parser.add_argument(
"--from_backup_path",
help="Will read backup path and whitelist the repo",
)
parser.add_argument(
"--from_backup_name",
help="Will read backup name and whitelist the repo",
)
parser.add_argument(
"--add_repo",
help="Add repo, separate by ; for list",
)
args = parser.parse_args()
return args
@ -62,10 +75,38 @@ def main():
filter_group = config.group if config.group else None
lst_whitelist = []
if config.from_backup_path or config.from_backup_name:
execute_cmd = execute.Execute()
# script/database/get_repo_from_backup.py
# --backup_name bpir_prod_5_dec_2025_2026-02-04_14h27m54s.zip
if config.from_backup_path:
cmd = f"./script/database/get_repo_from_backup.py --backup_path {config.from_backup_path}"
else:
cmd = f"./script/database/get_repo_from_backup.py --backup_name {config.from_backup_name}"
status, output = execute_cmd.exec_command_live(
cmd,
quiet=True,
source_erplibre=False,
single_source_erplibre=True,
return_status_and_output=True,
)
index_to_remove = len(os.getcwd()) + 1
for line in output:
repo_name = line[index_to_remove:].strip()
lst_whitelist.append(repo_name)
if config.add_repo:
lst_add_repo = [a.strip() for a in config.add_repo.split(";")]
else:
lst_add_repo = []
git_tool.generate_generate_config(
filter_group=filter_group,
extra_path=config.extra_addons_path,
ignore_odoo_path=config.ignore_odoo_path,
lst_add_repo=lst_add_repo,
lst_whitelist=lst_whitelist,
)

View file

@ -426,14 +426,25 @@ class GitTool:
filter_group=None,
extra_path=None,
ignore_odoo_path=None,
lst_whitelist=None
lst_add_repo=None,
lst_whitelist=None,
):
filename_locally = os.path.join(repo_path, "script/generate_config.sh")
if not filter_group:
filter_group = self.odoo_version_long
lst_repo = self.get_repo_info(
lst_repo_origin = self.get_repo_info(
repo_path=repo_path, filter_group=filter_group
)
if lst_whitelist:
lst_repo = []
for repo in lst_repo_origin:
if (
repo.get("path") in lst_whitelist
or repo.get("path") in lst_add_repo
):
lst_repo.append(repo)
else:
lst_repo = lst_repo_origin
lst_result = []
if not lst_repo:
print(