<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _cmp_by_origin(path1, path2):
 """Select the best path based on origin attribute. IGP is preferred over EGP; EGP is preferred over Incomplete. If both paths have same origin, we return None. """

    def get_origin_pref(origin):
        if origin.value == BGP_ATTR_ORIGIN_IGP:
            return 3
        elif origin.value == BGP_ATTR_ORIGIN_EGP:
            return 2
        elif origin.value == BGP_ATTR_ORIGIN_INCOMPLETE:
            return 1
        else:
            LOG.error('Invalid origin value encountered %s.', origin)
            return 0

    origin1 = path1.get_pattr(BGP_ATTR_TYPE_ORIGIN)
    origin2 = path2.get_pattr(BGP_ATTR_TYPE_ORIGIN)
    assert origin1 is not None and origin2 is not None

    # If both paths have same origins
    if origin1.value == origin2.value:
        return None

    # Translate origin values to preference.
    origin1 = get_origin_pref(origin1)
    origin2 = get_origin_pref(origin2)
    # Return preferred path.
    if origin1 == origin2:
        return None
    elif origin1 > origin2:
        return path1
    return path2