#4 steps 1 to 4
Merged 5 years ago by asamalik. Opened 5 years ago by jibecfed.

file added
+2
@@ -0,0 +1,2 @@ 

+ l10n/

+ sources/ 

\ No newline at end of file

file modified
+112 -3
@@ -17,20 +17,129 @@ 

      args = parser.parse_args()

  

      output_dir = args.output_dir

+     source_dir = os.path.dirname(os.path.abspath(__file__)) + "/sources/"

  

      os.makedirs(output_dir, exist_ok=True)

+     os.makedirs(source_dir, exist_ok=True)

  

      output_dir = os.path.abspath(output_dir)

      parse_yml(output_dir)

+     make_component_lists()

  

  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)

+     # print(command)

+     # args = shlex.split(command)

+     # subprocess.run(args, check=True)

+ 

+ def clone_source(url, branch = "master"):

+     repo_name = url.rsplit('/', 1)[-1].replace('.git', '')

+     dir = os.path.dirname(os.path.abspath(__file__)) + "/sources/" + repo_name

+ 

+     if os.path.exists(dir):

+         subprocess.run(['git', 'fetch'], check=True, cwd = dir)

+         subprocess.run(['git', 'checkout', branch], check=True, cwd = dir)

+         subprocess.run(['git', 'pull'], check=True, cwd = dir)

+     else:

+         command = "git clone -b {b} {u} {d}".format(b = branch, u=url, d=dir)

+         print(command)

+         args = shlex.split(command)

+         subprocess.run(args, check=True)

+ 

+ def clone_l10n(url):

+     repo_name = url.rsplit('/', 1)[-1].replace('.git', '')

+     dir = os.path.dirname(os.path.abspath(__file__)) + "/l10n/" + repo_name

+ 

+     if os.path.exists(dir):

+         subprocess.run(['git', 'pull'], check=True, cwd = dir)

+     else:

+         command = "git clone {u} {d}".format(u=url, d=dir)

+         print(command)

+         args = shlex.split(command)

+         subprocess.run(args, check=True)

+ 

+ def clone_sources():

+     """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:

+             clone_source(url)

+ 

+         elif 'branches' in source:

+             for branch in source['branches']:

+                 clone_source(url, branch)

+         else:

+             clone_source(url)

+ 

+ 

+     # Remove site.yml

+     os.remove("site.yml")

+ 

+ def get_component(dir, branch = 'master'):

+     subprocess.run(['git', 'fetch'], check=True, cwd = dir)

+     subprocess.run(['git', 'checkout', branch], check=True, cwd = dir)

+ 

+     with open(dir + "/antora.yml", 'r') as stream:

+         data_loaded = yaml.load(stream, Loader=yaml.SafeLoader)

  

+     component = data_loaded['name']

+     version = data_loaded['version']

+ 

+     f = []

+     for (dirpath, dirnames, filenames) in os.walk(dir + "/modules"):

+         f.extend(dirnames)

+         break

+ 

+     for module in f:

+         if module == "ROOT":

+             target_repo_name = component

+         else:

+             target_repo_name = component + "-" + module

+         clone_l10n("https://pagure.io/fedora-l10n/"+target_repo_name)

+ 

+ def make_component_lists():

+     """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']

+         repo_name = url.rsplit('/', 1)[-1].replace('.git', '')

+         dir = os.path.dirname(os.path.abspath(__file__)) + "/sources/" + repo_name

+ 

+         if 'start_path' in source:

+             get_component(dir+"/"+source['start_path'])

+ 

+         elif 'branches' in source:

+             for branch in source['branches']:

+                 get_component(dir, branch)

+         else:

+             get_component(dir)

+ 

+     # Remove site.yml

+     os.remove("site.yml")

  

  def parse_yml(output_dir):

      """List repositories to convert to pot from antora yaml file"""

1) parse the site.yml to get a list of repos
2) clone all source repositories locally
3) get a list of repos, components, and modules from it
4) clone all the l10n repos using component+module info

Pull-Request has been merged by asamalik

5 years ago
Metadata