erplibre/script/repo_remove_auto_install.py
Mathieu Benoit 492fc4c5b0 [ADD] script to remove auto_install in manifest of all repo
- Script to show difference between actual code and manifest revision
This will help to don't forget divergence between missing push code
- Fix default_remote, using dict of all values instead of string
2020-09-30 20:52:13 -04:00

117 lines
3.7 KiB
Python
Executable file

#!./.venv/bin/python
import os
import sys
import argparse
import logging
from pathlib import Path
from git import Repo # pip install gitpython
from git.exc import GitCommandError
new_path = os.path.normpath(os.path.join(os.path.dirname(__file__), '..'))
sys.path.append(new_path)
from script.git_tool import GitTool
_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
"""
# TODO update description
parser = argparse.ArgumentParser(
formatter_class=argparse.RawDescriptionHelpFormatter,
description='''\
''',
epilog='''\
'''
)
parser.add_argument('-d', '--dir', dest="dir", default="./",
help="Path of repo to change remote, including submodule.")
args = parser.parse_args()
return args
def main():
config = get_config()
git_tool = GitTool()
lst_repo = git_tool.get_source_repo_addons(repo_path=config.dir,
add_repo_root=False)
lst_repo_organization = [git_tool.get_transformed_repo_info_from_url(
a.get("url"), repo_path=config.dir, get_obj=True,
is_submodule=a.get("is_submodule"), sub_path=a.get("sub_path"),
revision=a.get("revision"), clone_depth=a.get("clone_depth"))
for a in lst_repo]
lst_ignore_repo = ["odoo"]
i = 0
total = len(lst_repo)
branch_name = "12.0_dev"
for repo in lst_repo_organization:
i += 1
print(f"\nNb element {i}/{total} - {repo.path}")
is_checkout_branch = False
if repo.repo_name in lst_ignore_repo:
print(f"Ignore {repo.repo_name}.")
continue
git_repo = Repo(repo.relative_path)
# Force checkout branch if exist
try:
git_repo.git.checkout(branch_name)
is_checkout_branch = True
except GitCommandError:
try:
git_repo.git.checkout("-t", f"{repo.organization}/{branch_name}")
is_checkout_branch = True
except GitCommandError:
pass
has_change = get_manifest_external_dependencies(repo)
if has_change:
if not is_checkout_branch:
git_repo.git.checkout("-b", branch_name)
# change branch, commit and push
git_repo.git.add(".")
git_repo.git.commit("-m", "Set all module auto_install at False")
git_repo.git.push("-u", repo.organization, branch_name)
def get_lst_manifest_py(relative_path):
return list(Path(relative_path).rglob("__manifest__.py"))
def get_manifest_external_dependencies(repo):
has_change = False
lst_manifest_file = get_lst_manifest_py(repo.relative_path)
for manifest_file in lst_manifest_file:
has_change_manifest = False
with open(manifest_file, 'r') as f:
lst_content = f.readlines()
i = 0
for content in lst_content:
if "auto_install" in content and "True" in content:
has_change_manifest = True
has_change = True
first_char_index = content.find("auto_install")
index = content.find("True", first_char_index)
lst_content[i] = content[:index] + "False" + content[index + 4:]
i += 1
if has_change_manifest:
print(f"Update file {manifest_file}")
with open(manifest_file, 'w') as f:
f.writelines(lst_content)
return has_change
if __name__ == '__main__':
main()