Skip to content

Instantly share code, notes, and snippets.

@yangchenghu
Forked from liuliu/pods.py
Created April 3, 2023 06:26
Show Gist options
  • Save yangchenghu/9760d3fb0483d0b7aadf2ac0762662cf to your computer and use it in GitHub Desktop.
Save yangchenghu/9760d3fb0483d0b7aadf2ac0762662cf to your computer and use it in GitHub Desktop.

Revisions

  1. @liuliu liuliu created this gist Aug 2, 2020.
    53 changes: 53 additions & 0 deletions pods.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,53 @@
    #!/usr/bin/env python

    import argparse
    import subprocess
    import os
    import re
    import json

    def read_version(version):
    ver = re.compile('Using\s([\w\_\-]+)\s\(([\d\.]+)\)')
    versions = {}
    for line in version.readlines():
    s = ver.search(line)
    if s is not None:
    versions[s.group(1)] = s.group(2)
    return versions

    def gather_jsons(versions, spec, specs_path):
    spe = re.compile('Specs\/\w\/\w\/\w\/[\w\_\-]+\/([\d\.]+)\/[\w\_\-]+\.podspec\.json')
    mapping = {}
    for line in spec.readlines():
    s = spe.search(line)
    if s is not None:
    data = json.load(open(specs_path + '/' + s.group(0)))
    if s.group(1) == versions[data['name']]:
    mapping[data['name']] = data
    return mapping


    def main():
    parser = argparse.ArgumentParser(description="Pods Spec to Pods.WORKSPACE")
    parser.add_argument('--specs', nargs=1)
    parser.add_argument('--versions', nargs=1)
    parser.add_argument('--specs-path', nargs=1)
    args = parser.parse_args()
    args.specs = args.specs[0]
    args.specs_path = args.specs_path[0]
    args.versions = args.versions[0]
    with open(args.versions) as version:
    versions = read_version(version)
    with open(args.specs) as spec:
    mapping = gather_jsons(versions, spec, args.specs_path)
    for name, data in mapping.items():
    source = data['source']
    if 'git' in source:
    http = source['git'][:-4] + '/archive/' + source['tag'] + '.zip'
    else:
    http = source['http']
    print("new_pod_repository(\n name = \"{}\",\n url = \"{}\"\n)\n".format(name, http))


    if __name__ == "__main__":
    main()