|
| 1 | +import glob |
| 2 | +import os |
| 3 | +import subprocess |
| 4 | +import yaml |
| 5 | + |
| 6 | +prefix="src" |
| 7 | + |
| 8 | +def add_git_submodule(repo_name, repo_url, repo_version): |
| 9 | + subprocess.call(['git', 'submodule', 'add', '-b', repo_version, repo_url, repo_name]) |
| 10 | + |
| 11 | +def is_submodule(repo_name): |
| 12 | + try: |
| 13 | + subprocess.check_output(['git', 'submodule', 'status', repo_name], stderr=subprocess.DEVNULL) |
| 14 | + return True |
| 15 | + except subprocess.CalledProcessError: |
| 16 | + return False |
| 17 | + |
| 18 | +def parse_repos_file(file_path): |
| 19 | + with open(file_path, 'r') as file: |
| 20 | + repos_data = yaml.safe_load(file) |
| 21 | + repositories = repos_data['repositories'] |
| 22 | + |
| 23 | + for repo_name, repo_info in repositories.items(): |
| 24 | + if 'type' in repo_info and repo_info['type'] == 'git': |
| 25 | + repo_url = repo_info['url'] |
| 26 | + repo_version = repo_info['version'] |
| 27 | + submodule_name = os.path.join(prefix, repo_name) |
| 28 | + |
| 29 | + if not is_submodule(submodule_name): |
| 30 | + add_git_submodule(submodule_name, repo_url, repo_version) |
| 31 | + print(f"Added {repo_name} as a submodule.") |
| 32 | + |
| 33 | +# Find .repos files within the src directory |
| 34 | +repos_files = glob.glob('src/**/*.repos', recursive=True) |
| 35 | + |
| 36 | +# Process each .repos file |
| 37 | +for repos_file in repos_files: |
| 38 | + parse_repos_file(repos_file) |
0 commit comments