| |
@@ -0,0 +1,71 @@
|
| |
+ #!/usr/bin/env python3
|
| |
+ """Calls `./po-to-src.sh` for all source repos"""
|
| |
+
|
| |
+ import argparse
|
| |
+ import os
|
| |
+ import urllib.request
|
| |
+ import subprocess
|
| |
+ import shlex
|
| |
+ import yaml
|
| |
+
|
| |
+
|
| |
+ def main():
|
| |
+ """Handle params"""
|
| |
+ parser = argparse.ArgumentParser(
|
| |
+ description="Calls `./po-to-src.sh` for all source repos")
|
| |
+ parser.add_argument("output_dir", help="Output directory")
|
| |
+ args = parser.parse_args()
|
| |
+
|
| |
+ output_dir = args.output_dir
|
| |
+
|
| |
+ os.makedirs(output_dir, exist_ok=True)
|
| |
+
|
| |
+ output_dir = os.path.abspath(output_dir)
|
| |
+ parse_yml(output_dir)
|
| |
+
|
| |
+ def call_podman_and_src_to_po(output_dir, doc):
|
| |
+ command = "podman run --rm -it -v {o}:/output:z ".format(o=output_dir)
|
| |
+ command += "-v {c}/src-to-pot.sh:/scripts/src-to-pot.sh:z ".format(c=os.getcwd())
|
| |
+ command += "asamalik/fedora-docs-translations /scripts/src-to-pot.sh {d}".format(d=doc)
|
| |
+ print(command)
|
| |
+ args = shlex.split(command)
|
| |
+ subprocess.run(args, check=True)
|
| |
+
|
| |
+
|
| |
+ def parse_yml(output_dir):
|
| |
+ """List repositories to convert to pot from antora yaml file"""
|
| |
+
|
| |
+ # download site.yml
|
| |
+ urllib.request.urlretrieve(
|
| |
+ "https://pagure.io/fedora-docs/docs-fp-o/raw/master/f/site.yml", "site.yml"
|
| |
+ )
|
| |
+
|
| |
+ # Read site.yml
|
| |
+ with open("site.yml", 'r') as stream:
|
| |
+ data_loaded = yaml.load(stream, Loader=yaml.SafeLoader)
|
| |
+
|
| |
+ # Parse site.yml
|
| |
+ for source in data_loaded['content']['sources']:
|
| |
+ url = source['url']
|
| |
+
|
| |
+ if 'start_path' in source:
|
| |
+ src_basedir = source['start_path']
|
| |
+ doc = "--clone-target-repo --src-basedir \"{bd}\" {url} /output".format(
|
| |
+ bd=src_basedir, url=url)
|
| |
+
|
| |
+ elif 'branches' in source:
|
| |
+ for branch in source['branches']:
|
| |
+ src_branch = branch
|
| |
+ doc = "--clone-target-repo --src-branch \"{br}\" {url} /output".format(
|
| |
+ br=src_branch, url=url)
|
| |
+ else:
|
| |
+ doc = "--clone-target-repo {url} /output".format(url=url)
|
| |
+
|
| |
+ call_podman_and_src_to_po(output_dir, doc)
|
| |
+
|
| |
+ # Remove site.yml
|
| |
+ os.remove("site.yml")
|
| |
+
|
| |
+
|
| |
+ if __name__ == '__main__':
|
| |
+ main()
|
| |