def version_cmp(ver_a, ver_b):
    """
    Compares two version strings in the dotted-numeric-label format.

    Returns -1 if a < b, 0 if a == b, and +1 if a > b.

    Inputs may include a prefix string that matches '^\w+[_-]', but
    both strings must start with the same prefix.  If present, it
    is ignored for purposes of comparision.  If it does not match,
    straight lexicographical ordering is used for the entire string.

    If a is None, it is always considered less than b, even if b
    is also None.

    The function also accepts the case where both args are ints
    or can be converted to ints.
"""
    if ver_a is None and ver_b is None:
        return 0
    if ver_a is None:
        return -1
    elif ver_b is None:
        return 1
    try:
        a = int(ver_a)
        b = int(ver_b)
        if a < b: return -1
        elif a > b: return 1
        else: return 0
    except:
        pass
    m = re.match('^(\w+[_-])(\d.*)$', ver_a)
    if m:
        pref_a = m.group(1)
        a = m.group(2)
    else:
        pref_a = ''
        a = ver_a
    m = re.match('^(\w+[_-])(\d.*)$', ver_b)
    if m:
        pref_b = m.group(1)
        b = m.group(2)
    else:
        pref_b = ''
        b = ver_b
    if pref_a != pref_b:
        if ver_a < ver_b: return -1
        else: return 1
    a = a.split('.')
    b = b.split('.')

    restrip = re.compile(r'[^\d]+$')

    for i in range(0, max(len(a), len(b))):
        if i >= len(a): return -1
        if i >= len(b): return 1
        astr = restrip.sub('', a[i])
        if not astr: astr = '0'
        bstr = restrip.sub('', b[i])
        if not bstr: bstr = '0'
        try: aint = int(astr)
        except: return -1                                                                       # pragma: no cover
        try: bint = int(bstr)
        except: return -1                                                                       # pragma: no cover
        if aint < bint: return -1
        elif aint > bint: return 1
    return 0
Compares two version strings in the dotted-numeric-label format.

    Returns -1 if a < b, 0 if a == b, and +1 if a > b.

    Inputs may include a prefix string that matches '^\w+[_-]', but
    both strings must start with the same prefix.  If present, it
    is ignored for purposes of comparision.  If it does not match,
    straight lexicographical ordering is used for the entire string.

    If a is None, it is always considered less than b, even if b
    is also None.

    The function also accepts the case where both args are ints
    or can be converted to ints.