Skip to content

Instantly share code, notes, and snippets.

@liuliu

liuliu/pods.py

Created Aug 2, 2020
Embed
What would you like to do?
#!/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
You can’t perform that action at this time.