Last active
December 23, 2015 00:59
-
-
Save fridgei/6557817 to your computer and use it in GitHub Desktop.
This file contains 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
import operator | |
def version_compare(comparer): | |
def compare_from(v1): | |
def compare_to(v2): | |
return comparer(map(int, v1.split(".")), | |
map(int, v2.split("."))) and \ | |
not any(v2.endswith(e) for e in ["beta", "alpha"]) | |
return compare_to | |
return compare_from | |
# Used when no wild cards present | |
less_than = version_compare(operator.lt) | |
less_than_equal = version_compare(operator.le) | |
greater_than = version_compare(operator.gt) | |
greater_than_equal = version_compare(operator.ge) | |
equal = version_compare(operator.eq) | |
def wildcard_comparer(v1): | |
mapping = [] | |
for elem in v1.split("."): | |
if elem.isdigit(): | |
mapping.append(equal(elem)) | |
elif elem in ["X", "*"]: | |
mapping.append(lambda x: True) | |
def compare_to(v2): | |
return all(map(c(v2), mapping)) | |
return compare_to |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment