Skip to content

Instantly share code, notes, and snippets.

@liuliu
Created August 2, 2020 22:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save liuliu/0bba51a54ef8b1308cf74ef0769f4f82 to your computer and use it in GitHub Desktop.
Save liuliu/0bba51a54ef8b1308cf74ef0769f4f82 to your computer and use it in GitHub Desktop.
#!/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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment