From c25f0d8678938ef85550c0949f966463ebce3502 Mon Sep 17 00:00:00 2001 From: Jibec Date: Apr 12 2019 09:32:00 +0000 Subject: add all-src-to-pot.py --- diff --git a/all-src-to-pot.py b/all-src-to-pot.py new file mode 100755 index 0000000..aabcaab --- /dev/null +++ b/all-src-to-pot.py @@ -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()