-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrepos2gitmodules.py
executable file
·53 lines (37 loc) · 1.25 KB
/
repos2gitmodules.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env python3
import argparse
import sys
from pathlib import Path
import configparser
import yaml
def repos2gitmodules(repos_file: Path, output_file: Path):
with open(repos_file, "r") as f:
repos = yaml.load(f, Loader=yaml.SafeLoader)
gitmodules = configparser.ConfigParser()
for k, v in repos["repositories"].items():
path = f"src/{k}"
url = v["url"]
key = f'submodule "{path}"'
gitmodules[key] = {
"path": path,
"url": url,
}
with open(output_file, "w") as f:
gitmodules.write(f)
def main(args):
parser = argparse.ArgumentParser()
parser.add_argument("repos_file", type=Path)
parser.add_argument("-o", "--output", dest="output_file", type=Path, default=None)
ns = parser.parse_args(args)
if not ns.output_file:
parent_dir = ns.repos_file.absolute().parent
ns.output_file = parent_dir / ".gitmodules"
repos2gitmodules(ns.repos_file, ns.output_file)
if __name__ == "__main__":
main(sys.argv[1:])
# [submodule "autoware.universe"]
# path = autoware.universe
# url = https://github.com/autowarefoundation/autoware.universe
# [submodule "tmp"]
# path = tmp
# url = https://github.com/autowarefoundation/autoware.universe