-
Notifications
You must be signed in to change notification settings - Fork 0
/
repos2workspace.py
executable file
·41 lines (28 loc) · 1.01 KB
/
repos2workspace.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
#!/usr/bin/env python3
import argparse
import json
import sys
from pathlib import Path
import yaml
def repos2workspace(repos_file: Path, output_file: Path):
with open(repos_file, "r") as f:
repos = yaml.load(f, Loader=yaml.SafeLoader)
paths = [f"src/{path}" for path in repos["repositories"]]
folders = [{"path": path} for path in paths]
folders += [{"path": "."}]
workspace = {
"folders": folders,
}
with open(output_file, "w") as f:
json.dump(workspace, f, indent=2, sort_keys=False)
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 / f"{parent_dir.name}.code-workspace"
repos2workspace(ns.repos_file, ns.output_file)
if __name__ == "__main__":
main(sys.argv[1:])