Last active
November 24, 2016 05:26
-
-
Save zqqf16/b8d1edf4c7842b8fbfa895bb77ac9f01 to your computer and use it in GitHub Desktop.
Diff Podfile.lock
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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(): | |
break | |
match = _POD_RE.search(line) | |
if match: | |
pods[match.group(1)] = match.group(2) | |
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("+") | |
else: | |
v1 = LooseVersion(str_v1) | |
if not str_v2 or str_v2.isspace(): | |
return magenta("-") | |
else: | |
v2 = LooseVersion(str_v2) | |
if v1 < v2: | |
return red("↑") | |
elif v1 > v2: | |
return green("↓") | |
else: | |
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