Skip to content

Instantly share code, notes, and snippets.

Last active Nov 24, 2016
What would you like to do?
Diff Podfile.lock
#!/usr/bin/env python
#-*- coding: utf-8 -*-
import re
from distutils.version import LooseVersion
_POD_RE = re.compile(r'\s{1,1}- (.*) \((.*)\)')
def parse_lock_file(lock):
pods = {}
with open(lock) as f:
for line in f:
if line.isspace():
match =
if match:
pods[] =
return pods
green = lambda x: '\033[0m\033[32;49m{}\033[0m'.format(x)
red = lambda x: '\033[0m\033[31;49m{}\033[0m'.format(x)
yellow = lambda x: '\033[0m\033[33;49m{}\033[0m'.format(x)
cyan = lambda x: '\033[0m\033[36;49m{}\033[0m'.format(x)
magenta = lambda x: '\033[0m\033[35;49m{}\033[0m'.format(x)
def compare(v1, v2):
str_v1 = str(v1)
str_v2 = str(v2)
if not str_v1 or str_v1.isspace():
return cyan("+")
v1 = LooseVersion(str_v1)
if not str_v2 or str_v2.isspace():
return magenta("-")
v2 = LooseVersion(str_v2)
if v1 < v2:
return red("↑")
elif v1 > v2:
return green("↓")
return yellow("=")
def diff(a, b):
pod_a = parse_lock_file(a)
pod_b = parse_lock_file(b)
keys = lambda x: list(x.keys())
all_pods = sorted(set(keys(pod_a)+keys(pod_b)))
for pod in all_pods:
v1 = pod_a.get(pod, "")
v2 = pod_b.get(pod, "")
print('{} {}\n ({}) {}\n ({}) {}\n'
.format(compare(v1, v2), pod, v1, a, v2, b))
if __name__ == '__main__':
import sys
diff(sys.argv[1], sys.argv[2])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment