예제 #1
0
파일: mediator.py 프로젝트: stensonb/pkg5
def cmp_mediations(a, b):
    """Custom mediation sorting routine.  Sort is done by
        priority, version, implementation name, implementation
        version.
        """

    aprio = _MED_PRIORITIES.get(a[0], 3)
    bprio = _MED_PRIORITIES.get(b[0], 3)
    res = misc.cmp(aprio, bprio)
    if res != 0:
        return res

    aver = a[1]
    bver = b[1]
    res = misc.cmp(aver, bver)
    if res != 0:
        # Invert version sort so greatest is first.
        return res * -1

    aimpl, aver = parse_mediator_implementation(a[2])
    bimpl, bver = parse_mediator_implementation(b[2])
    res = misc.cmp(aimpl, bimpl)
    if res != 0:
        return res

    res = misc.cmp(aver, bver)
    if res != 0:
        # Invert version sort so greatest is first.
        return res * -1
    return 0
예제 #2
0
파일: api.py 프로젝트: stensonb/pkg5
                def cmp_fmris(resa, resb):
                    a = resa[2]
                    b = resb[2]

                    if a.pkg_name == b.pkg_name:
                        # Version in descending order.
                        return misc.cmp(a.version, b.version) * -1
                    return misc.cmp(a, b)
예제 #3
0
    def _cmp_all_values(self, other):
        """Compare all the facet values of two Facets objects.  This
                comparison takes masked values into account."""

        assert type(other) is Facets
        rv = misc.cmp(self.__inherited, other.__inherited)
        if rv == 0:
            rv = misc.cmp(self.__local, other.__local)
        return rv
예제 #4
0
 def cmp_aliases(a, b):
         if opt_format == FMT_V1:
                 # Simple comparison for V1 format.
                 return misc.cmp(a, b)
         # For V2 format, order aliases by interpreted value.
         c = misc.cmp(get_alias_key(a), get_alias_key(b))
         # misc.cmp returns NotImplemented for uncomparable types in
         # Python 3. Instead fallback to using the string of the key
         # generated from the alias and sort alphabetically. This
         # maintains the python 2 sorting behaviour.
         if c is NotImplemented:
             c = -misc.cmp(str(get_alias_key(a)), str(get_alias_key(b)))
         return c
예제 #5
0
    def _cmp_priority(self, other):
        """Compare the facet match priority of two Facets objects.
                Since the match priority of a Facets object is dependent upon
                facet sources (local vs parent) and names, we're essentially
                ensuring that both objects have the same set of facet sources
                and names."""

        assert type(other) is Facets
        return misc.cmp(self.__keylist, other.__keylist)
예제 #6
0
파일: pkgdiff.py 프로젝트: ripudamank2/pkg5
    def compare(a, b):
        # pull the relevant action out of the old value, new
        # value tuples
        a = a[0] if a[0] else a[1]
        b = b[0] if b[0] else b[1]

        if hasattr(a, "key_attr") and hasattr(b, "key_attr") and \
            a.key_attr == b.key_attr:
            res = misc.cmp(a.attrs[a.key_attr], b.attrs[b.key_attr])
            if res:
                return res
            # sort by variant
            res = misc.cmp(sorted(list(a.get_variant_template())),
                           sorted(list(b.get_variant_template())))
            if res:
                return res
        else:
            res = misc.cmp(a.ordinality, b.ordinality)
            if res:
                return res
        return misc.cmp(str(a), str(b))
예제 #7
0
    def compare(a, b):
        # pull the relevant action out of the old value, new
        # value tuples
        a = a[0] if a[0] else a[1]
        b = b[0] if b[0] else b[1]

        if hasattr(a, "key_attr") and hasattr(b, "key_attr") and \
            a.key_attr == b.key_attr:
            res = misc.cmp(a.attrs[a.key_attr], b.attrs[b.key_attr])
            if res != NotImplemented:
                return res
            # sort by variant
            res = misc.cmp(sorted(list(a.get_variant_template())),
                           sorted(list(b.get_variant_template())))
            if res != NotImplemented:
                return res
        else:
            res = misc.cmp(a.ordinality, b.ordinality)
            if res != NotImplemented:
                return res
        # Fall back to a simple string compare if we have
        # differing types (indicated by the above NotImplemented
        # return values.
        return misc.cmp(str(a), str(b))
예제 #8
0
파일: pkgfmt.py 프로젝트: jahau/solaris-ips
 def cmp_aliases(a, b):
     if opt_format == FMT_V1:
         # Simple comparison for V1 format.
         return misc.cmp(a, b)
     # For V2 format, order aliases by interpreted value.
     return misc.cmp(get_alias_key(a), get_alias_key(b))
예제 #9
0
파일: pkgfmt.py 프로젝트: jahau/solaris-ips
def cmplines(a, b):
    """Compare two line tuples for sorting"""

    # we know that all lines that reach here have actions
    # make set actions first
    # depend actions last
    # rest in alpha order

    def typeord(a):
        if a.name == "set":
            return 1
        if opt_format == FMT_V2:
            if a.name in ("driver", "group", "user"):
                return 3
            if a.name in ("legacy", "license"):
                return 4
        if a.name == "depend":
            return 5
        return 2

    c = misc.cmp(typeord(a[0]), typeord(b[0]))
    if c:
        return c

    if opt_format != FMT_V2:
        c = misc.cmp(a[0].name, b[0].name)
        if c:
            return c

    # Place set pkg.fmri actions first among set actions.
    if a[0].name == "set" and a[0].attrs["name"] == "pkg.fmri":
        return -1
    if b[0].name == "set" and b[0].attrs["name"] == "pkg.fmri":
        return 1

    # Place set actions with names that start with pkg. before any
    # remaining set actions.
    if a[0].name == "set" and a[0].attrs["name"].startswith("pkg.") and \
        not (b[0].name != "set" or b[0].attrs["name"].startswith("pkg.")):
        return -1
    if b[0].name == "set" and b[0].attrs["name"].startswith("pkg.") and \
        not (a[0].name != "set" or a[0].attrs["name"].startswith("pkg.")):
        return 1

    if opt_format == FMT_V2:
        # Place set pkg.summary actions second and pkg.description
        # options third.
        for attr in ("pkg.summary", "pkg.description"):
            if (a[0].name == "set" and a[0].attrs["name"] == attr
                    and not b[0].attrs["name"] == attr):
                return -1
            if (b[0].name == "set" and b[0].attrs["name"] == attr
                    and not a[0].attrs["name"] == attr):
                return 1

    # Sort actions based on key attribute (if applicable).
    key_attr = a[0].key_attr
    if key_attr and key_attr == b[0].key_attr:
        a_sk = b_sk = None
        if opt_format == FMT_V2:
            if "path" in a[0].attrs and "path" in b[0].attrs:
                # This ensures filesystem actions are sorted by
                # path and link and hardlink actions are sorted
                # by path and then target (when compared against
                # each other).
                if "target" in a[0].attrs and \
                    "target" in b[0].attrs:
                    a_sk = operator.itemgetter("path", "target")(a[0].attrs)
                    b_sk = operator.itemgetter("path", "target")(b[0].attrs)
                else:
                    a_sk = a[0].attrs["path"]
                    b_sk = b[0].attrs["path"]
            elif a[0].name == "depend" and b[0].name == "depend":
                a_sk = operator.itemgetter("type", "fmri")(a[0].attrs)
                b_sk = operator.itemgetter("type", "fmri")(b[0].attrs)

        # If not using alternate format, or if no sort key has been
        # determined, fallback to sorting on key attribute.
        if not a_sk:
            a_sk = a[0].attrs[key_attr]
        if not b_sk:
            b_sk = b[0].attrs[key_attr]

        c = misc.cmp(a_sk, b_sk)
        # misc.cmp raises NotImplemented for uncomparable types in
        # Python 3. Sort them based on stringified key attribute.
        if c is NotImplemented:
            c = misc.cmp(str(a_sk), str(b_sk))
            if c:
                return c
        elif c:
            return c

    # No key attribute or key attribute sorting provides equal placement, so
    # sort based on stringified action.
    return misc.cmp(str(a[0]), str(b[0]))
예제 #10
0
 def facet_sort(x, y):
     i = len(y) - len(x)
     if i != 0:
         return i
     return misc.cmp(x, y)
예제 #11
0
    def _cmp_values(self, other):
        """Compare the facet values of two Facets objects.  This
                comparison ignores any masked values."""

        assert type(other) is Facets
        return misc.cmp(self, other)