89 lines
2.7 KiB
Python
Executable File
89 lines
2.7 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
import os
|
|
import subprocess
|
|
import configparser
|
|
|
|
def read_gitmodules(file_path):
|
|
config = configparser.ConfigParser(allow_no_value=True, delimiters=('=', ':'))
|
|
config.read(file_path)
|
|
modules = []
|
|
for section in config.sections():
|
|
path = config[section].get('path', 'Not found')
|
|
url = config[section].get('url', 'Not found')
|
|
submodule_info = {
|
|
'path': path,
|
|
'url': url
|
|
}
|
|
if path not in ["odoo", "enterprise", "themes"]:
|
|
modules.append(submodule_info)
|
|
return modules
|
|
|
|
# Settings
|
|
branches = ["15.0", "16.0"]
|
|
output_file = "modules.md"
|
|
|
|
# Define dictionary for module list
|
|
module_data = {}
|
|
|
|
# Iterate over each branch
|
|
for branch in branches:
|
|
|
|
# Switch to the branch
|
|
subprocess.run(["git", "switch", branch])
|
|
|
|
# Get all submodules
|
|
submodules = read_gitmodules(".gitmodules")
|
|
|
|
# Iterate over each submodule
|
|
for submodule in submodules:
|
|
|
|
if submodule["url"].startswith("git@"):
|
|
org = submodule["url"].split(":")[1].split("/")[0]
|
|
repo = submodule["url"].split(":")[1].split("/")[1].replace(".git", "")
|
|
elif submodule["url"].startswith("https://"):
|
|
org = submodule["url"].replace("https://github.com/", "").split("/")[0]
|
|
repo = submodule["url"].replace("https://github.com/", "").split("/")[1]
|
|
path = submodule["path"]
|
|
|
|
if not org:
|
|
raise ValueError(f"Org not found in {submodule['url']}")
|
|
|
|
# Get list of modules
|
|
result = subprocess.run(
|
|
["git", "-C", path, "ls-tree", "--name-only", "-d", branch],
|
|
capture_output=True,
|
|
text=True,
|
|
check=True
|
|
)
|
|
modules = result.stdout.split("\n")
|
|
|
|
# Cleanup list
|
|
modules = list(filter(None, modules))
|
|
modules = list(filter(lambda x: x not in ["setup", ".github"], modules))
|
|
|
|
# Add module data to the dictionary
|
|
for module in modules:
|
|
module_key = f"{org}|{repo}|{module}"
|
|
|
|
url = f"https://github.com/{org}/{repo}"
|
|
branch_link = f" [{branch}]({url}/tree/{branch})"
|
|
|
|
if module_key in module_data:
|
|
module_data[module_key] += branch_link
|
|
else:
|
|
module_data[module_key] = branch_link
|
|
|
|
|
|
# Sort mdoule data by key
|
|
module_data = dict(sorted(module_data.items()))
|
|
|
|
with open(output_file, "w") as f:
|
|
f.write("| org | repo | name | link |\n")
|
|
f.write("|---|---|---|---|\n")
|
|
|
|
for key, links in module_data.items():
|
|
org, repo, name = key.split('|')
|
|
f.write(f"| {org} | {repo} | {name} |{links} |\n")
|
|
|
|
print(f"Markdown table created in {output_file}") |