示例#1
0
文件: fs.py 项目: chutz/pkgcore
 def __cmp__(self, other):
     c = cmp(self.location, other.location)
     if c:
         return c
     if isinstance(other, self.__class__):
         return cmp(self.target, other.target)
     return 0
示例#2
0
 def __cmp__(self, other):
     c = cmp(self.location, other.location)
     if c:
         return c
     if isinstance(other, self.__class__):
         return cmp(self.target, other.target)
     return 0
示例#3
0
    def test_cmp(self):
        pkg1 = self.make_fakepkg()
        pkg2 = self.make_fakepkg(ver=2)
        mpkg1 = MutatedPkg(pkg1, {})
        mpkg2 = MutatedPkg(pkg2, {})

        for lpkg in (pkg1, mpkg1):
            self.assertTrue(cmp(lpkg, mpkg2) < 0)
            self.assertTrue(cmp(mpkg2, lpkg) > 0)
        self.assertEqual(mpkg1, mpkg1)
        self.assertEqual(pkg1, mpkg1)
示例#4
0
 def assertEqual2(self, o1, o2):
     # logic bugs hidden behind short circuiting comparisons for metadata
     # is why we test the comparison *both* ways.
     self.assertEqual(o1, o2)
     c = cmp(o1, o2)
     self.assertEqual(c, 0,
         msg="checking cmp for %r, %r, aren't equal: got %i" % (o1, o2, c))
     self.assertEqual(o2, o1)
     c = cmp(o2, o1)
     self.assertEqual(c, 0,
         msg="checking cmp for %r, %r,aren't equal: got %i" % (o2, o1, c))
示例#5
0
    def test_cmp(self):
        pkg1 = self.make_fakepkg()
        pkg2 = self.make_fakepkg(ver=2)
        mpkg1 = MutatedPkg(pkg1, {})
        mpkg2 = MutatedPkg(pkg2, {})

        for lpkg in (pkg1, mpkg1):
            self.assertTrue(cmp(lpkg, mpkg2) < 0)
            self.assertTrue(cmp(mpkg2, lpkg) > 0)
        self.assertEqual(mpkg1, mpkg1)
        self.assertEqual(pkg1, mpkg1)
示例#6
0
 def assertEqual2(self, o1, o2):
     # logic bugs hidden behind short circuiting comparisons for metadata
     # is why we test the comparison *both* ways.
     self.assertEqual(o1, o2)
     c = cmp(o1, o2)
     self.assertEqual(c, 0,
         msg="checking cmp for %r, %r, aren't equal: got %i" % (o1, o2, c))
     self.assertEqual(o2, o1)
     c = cmp(o2, o1)
     self.assertEqual(c, 0,
         msg="checking cmp for %r, %r,aren't equal: got %i" % (o2, o1, c))
示例#7
0
文件: cpv.py 项目: chutz/pkgcore
def cpy_ver_cmp(ver1, rev1, ver2, rev2):
    if ver1 == ver2:
        return cmp(rev1, rev2)
    if ver1 is None:
        ver1 = ''
    if ver2 is None:
        ver2 = ''
    c = cmp(cpy_CPV(fake_cat, fake_pkg, ver1, versioned=bool(ver1)),
            cpy_CPV(fake_cat, fake_pkg, ver2, versioned=bool(ver2)))
    if c != 0:
        return c
    return cmp(rev1, rev2)
示例#8
0
 def assertNotEqual2(self, o1, o2):
     # is why we test the comparison *both* ways.
     self.assertNotEqual(o1, o2)
     c = cmp(o1, o2)
     self.assertNotEqual(c, 0,
         msg="checking cmp for %r, %r, not supposed to be equal, got %i"
             % (o1, o2, c))
     self.assertNotEqual(o2, o1)
     c = cmp(o2, o1)
     self.assertNotEqual(c, 0,
         msg="checking cmp for %r, %r, not supposed to be equal, got %i"
             % (o2, o1, c))
示例#9
0
文件: cpv.py 项目: neko259/pkgcore
def cpy_ver_cmp(ver1, rev1, ver2, rev2):
    if ver1 == ver2:
        return cmp(rev1, rev2)
    if ver1 is None:
        ver1 = ''
    if ver2 is None:
        ver2 = ''
    c = cmp(cpy_CPV(fake_cat, fake_pkg, ver1, versioned=bool(ver1)),
            cpy_CPV(fake_cat, fake_pkg, ver2, versioned=bool(ver2)))
    if c != 0:
        return c
    return cmp(rev1, rev2)
示例#10
0
文件: cpv.py 项目: ulm/pkgcore
 def ver_cmp(ver1, rev1, ver2, rev2):
     if ver1 == ver2:
         return cmp(rev1, rev2)
     if ver1 is None:
         ver1 = ''
     if ver2 is None:
         ver2 = ''
     c = cmp(cpy_CPV("fake", "pkg", ver1, versioned=bool(ver1)),
             cpy_CPV("fake", "pkg", ver2, versioned=bool(ver2)))
     if c != 0:
         return c
     return cmp(rev1, rev2)
示例#11
0
文件: cpv.py 项目: radhermit/pkgcore
 def ver_cmp(ver1, rev1, ver2, rev2):
     if ver1 == ver2:
         return cmp(rev1, rev2)
     if ver1 is None:
         ver1 = ''
     if ver2 is None:
         ver2 = ''
     c = cmp(cpy_CPV("fake", "pkg", ver1, versioned=bool(ver1)),
             cpy_CPV("fake", "pkg", ver2, versioned=bool(ver2)))
     if c != 0:
         return c
     return cmp(rev1, rev2)
示例#12
0
 def assertNotEqual2(self, o1, o2):
     # is why we test the comparison *both* ways.
     self.assertNotEqual(o1, o2)
     c = cmp(o1, o2)
     self.assertNotEqual(c, 0,
         msg="checking cmp for %r, %r, not supposed to be equal, got %i"
             % (o1, o2, c))
     self.assertNotEqual(o2, o1)
     c = cmp(o2, o1)
     self.assertNotEqual(c, 0,
         msg="checking cmp for %r, %r, not supposed to be equal, got %i"
             % (o2, o1, c))
示例#13
0
文件: tar.py 项目: neko259/pkgcore
 def sort_func(x, y):
     if x.is_dir:
         if not y.is_dir:
             return -1
         return cmp(x, y)
     elif y.is_dir:
         return +1
     elif x.is_reg:
         if y.is_reg:
             return cmp(files_ordering[x.data], files_ordering[y.data])
         return +1
     elif y.is_reg:
         return -1
     return cmp(x, y)
示例#14
0
 def sort_func(x, y):
     if x.is_dir:
         if not y.is_dir:
             return -1
         return cmp(x, y)
     elif y.is_dir:
         return +1
     elif x.is_reg:
         if y.is_reg:
             return cmp(files_ordering[x.data], files_ordering[y.data])
         return +1
     elif y.is_reg:
         return -1
     return cmp(x, y)
示例#15
0
 def __cmp__(self, other):
     if isinstance(other, InjectedPkg):
         other = other._raw_pkg
     elif isinstance(other, pkg_base.base):
         other = other.versioned_atom
     if self._raw_pkg.intersects(other):
         return 0
     return cmp(self._raw_pkg, other)
示例#16
0
    def __cmp__(self, other):
        if not isinstance(other, self.__class__):
            raise TypeError("other isn't of %s type, is %s" %
                            (self.__class__, other.__class__))

        c = cmp(self.category, other.category)
        if c:
            return c

        c = cmp(self.package, other.package)
        if c:
            return c

        c = cmp(self.op, other.op)
        if c:
            return c

        c = cpv.ver_cmp(self.version, self.revision, other.version,
                        other.revision)
        if c:
            return c

        c = cmp(self.blocks, other.blocks)
        if c:
            # invert it; cmp(True, False) == 1
            # want non blockers then blockers.
            return -c

        c = cmp(self.blocks_strongly, other.blocks_strongly)
        if c:
            # want !! prior to !
            return c

        c = cmp(self.negate_vers, other.negate_vers)
        if c:
            return c

        def f(v):
            return '' if v is None else v

        c = cmp(f(self.slot), f(other.slot))
        if c:
            return c

        c = cmp(self.use, other.use)
        if c:
            return c

        return cmp(self.repo_id, other.repo_id)
示例#17
0
文件: atom.py 项目: chutz/pkgcore
    def __cmp__(self, other):
        if not isinstance(other, self.__class__):
            raise TypeError("other isn't of %s type, is %s" %
                            (self.__class__, other.__class__))

        c = cmp(self.category, other.category)
        if c:
            return c

        c = cmp(self.package, other.package)
        if c:
            return c

        c = cmp(self.op, other.op)
        if c:
            return c

        c = cpv.ver_cmp(self.version, self.revision,
                        other.version, other.revision)
        if c:
            return c

        c = cmp(self.blocks, other.blocks)
        if c:
            # invert it; cmp(True, False) == 1
            # want non blockers then blockers.
            return -c

        c = cmp(self.blocks_strongly, other.blocks_strongly)
        if c:
            # want !! prior to !
            return c

        c = cmp(self.negate_vers, other.negate_vers)
        if c:
            return c

        def f(v):
            return '' if v is None else v
        c = cmp(f(self.slot), f(other.slot))
        if c:
            return c

        c = cmp(self.use, other.use)
        if c:
            return c

        return cmp(self.repo_id, other.repo_id)
示例#18
0
文件: plan.py 项目: veelai/pkgcore
 def f(x, y):
     c = cmp(x, y)
     if c:
         return c
     elif x.repo.livefs:
         if y.repo.livefs:
             return 0
         return -1
     elif y.repo.livefs:
         return 1
     return 0
示例#19
0
文件: cpv.py 项目: neko259/pkgcore
    def __cmp__(self, other):
        try:
            if self.cpvstr == other.cpvstr:
                return 0

            if (self.category and other.category and self.category != other.category):
                return cmp(self.category, other.category)

            if self.package and other.package and self.package != other.package:
                return cmp(self.package, other.package)

            # note I chucked out valueerror, none checks on versions
            # passed in. I suck, I know.
            # ~harring
            # fails in doing comparison of unversioned atoms against
            # versioned atoms
            return native_ver_cmp(self.version, self.revision, other.version,
                              other.revision)
        except AttributeError:
            return 1
示例#20
0
文件: plan.py 项目: austin987/pkgcore
 def f(x, y):
     c = cmp(x, y)
     if c:
         return c
     elif x.repo.livefs:
         if y.repo.livefs:
             return 0
         return -1
     elif y.repo.livefs:
         return 1
     return 0
示例#21
0
    def __cmp__(self, other):
        try:
            if self.cpvstr == other.cpvstr:
                return 0

            if (self.category and other.category and self.category != other.category):
                return cmp(self.category, other.category)

            if self.package and other.package and self.package != other.package:
                return cmp(self.package, other.package)

            # note I chucked out valueerror, none checks on versions
            # passed in. I suck, I know.
            # ~harring
            # fails in doing comparison of unversioned atoms against
            # versioned atoms
            return native_ver_cmp(self.version, self.revision, other.version,
                              other.revision)
        except AttributeError:
            return 1
示例#22
0
 def test_simple(self):
     t = tuple([1, 2, 3])
     o = make_DI(tuple, lambda: t)
     objs = [o, t]
     self.assertEqual(*map(str, objs))
     self.assertEqual(*map(repr, objs))
     self.assertEqual(*map(hash, objs))
     self.assertEqual(*objs)
     self.assertTrue(cmp(t, o) == 0)
     self.assertFalse(t < o)
     self.assertTrue(t <= o)
     self.assertTrue(t == o)
     self.assertTrue(t >= o)
     self.assertFalse(t > o)
     self.assertFalse(t != o)
示例#23
0
文件: test_obj.py 项目: rhn/snakeoil
 def test_simple(self):
     t = tuple([1, 2, 3])
     o = make_DI(tuple, lambda: t)
     objs = [o, t]
     self.assertEqual(*map(str, objs))
     self.assertEqual(*map(repr, objs))
     self.assertEqual(*map(hash, objs))
     self.assertEqual(*objs)
     self.assertTrue(cmp(t, o) == 0)
     self.assertFalse(t < o)
     self.assertTrue(t <= o)
     self.assertTrue(t == o)
     self.assertTrue(t >= o)
     self.assertFalse(t > o)
     self.assertFalse(t != o)
示例#24
0
文件: plan.py 项目: ulm/pkgcore
 def f(x, y):
     c = cmp(x, y)
     if x.repo.livefs:
         if y.repo.livefs:
             return c
         return -1
     elif y.repo.livefs:
         return 1
     elif restrict.match(x):
         if restrict.match(y):
             return 1
         return -1
     elif restrict.match(y):
         return 1
     return c
示例#25
0
文件: base.py 项目: chutz/pkgcore
 def __eq__(self, other):
     if isinstance(other, wrapper):
         return cmp(self._raw_pkg, other._raw_pkg) == 0
     return cmp(self._raw_pkg, other) == 0
示例#26
0
    def test_cmp(self):
        ukls, vkls = self.ukls, self.vkls
        self.assertTrue(cmp(vkls("dev-util/diffball-0.1"), vkls("dev-util/diffball-0.2")) < 0)
        base = "dev-util/diffball-0.7.1"
        self.assertFalse(cmp(vkls(base), vkls(base)))
        for rev in ("", "-r1"):
            last = None
            for suf in ["_alpha", "_beta", "_pre", "", "_p"]:
                if suf == "":
                    sufs = [suf]
                else:
                    sufs = [suf, suf + "4"]
                for x in sufs:
                    cur = vkls(base + x + rev)
                    self.assertEqual(cur, vkls(base + x + rev))
                    if last is not None:
                        self.assertGT(cur, last)

        self.assertGT(vkls("da/ba-6a"), vkls("da/ba-6"))
        self.assertGT(vkls("da/ba-6a-r1"), vkls("da/ba-6a"))
        self.assertGT(vkls("da/ba-6.0"), vkls("da/ba-6"))
        self.assertGT(vkls("da/ba-6.0.0"), vkls("da/ba-6.0b"))
        self.assertGT(vkls("da/ba-6.02"), vkls("da/ba-6.0.0"))
        # float comparison rules.
        self.assertGT(vkls("da/ba-6.2"), vkls("da/ba-6.054"))
        self.assertEqual(vkls("da/ba-6"), vkls("da/ba-6"))
        self.assertGT(ukls("db/ba"), ukls("da/ba"))
        self.assertGT(ukls("da/bb"), ukls("da/ba"))
        self.assertGT(vkls("da/ba-6.0_alpha0_p1"), vkls("da/ba-6.0_alpha"))
        self.assertEqual(vkls("da/ba-6.0_alpha"), vkls("da/ba-6.0_alpha0"))
        self.assertGT(vkls("da/ba-6.1"), vkls("da/ba-6.09"))
        self.assertGT(vkls("da/ba-6.0.1"), vkls("da/ba-6.0"))
        self.assertGT(vkls("da/ba-12.2.5"), vkls("da/ba-12.2b"))

        # test for gentoo bug 287848
        self.assertGT(vkls("dev-lang/erlang-12.2.5"), vkls("dev-lang/erlang-12.2b"))
        self.assertGT(vkls("dev-lang/erlang-12.2.5-r1"), vkls("dev-lang/erlang-12.2b"))

        self.assertEqual(vkls("da/ba-6.01.0"), vkls("da/ba-6.010.0"))

        for v1, v2 in (
            ("1.001000000000000000001", "1.001000000000000000002"),
            ("1.00100000000", "1.0010000000000000001"),
            ("1.01", "1.1"),
        ):
            self.assertGT(vkls("da/ba-%s" % v2), vkls("da/ba-%s" % v1))

        for x in (18, 36, 100):
            s = "0" * x
            self.assertGT(vkls("da/ba-10%s1" % s), vkls("da/ba-1%s1" % s))

        for x in (18, 36, 100):
            s = "0" * x
            self.assertGT(vkls("da/ba-1-r10%s1" % s), vkls("da/ba-1-r1%s1" % s))

        self.assertGT(vkls("sys-apps/net-tools-1.60_p2010081516093"), vkls("sys-apps/net-tools-1.60_p2009072801401"))

        self.assertGT(vkls("sys-apps/net-tools-1.60_p20100815160931"), vkls("sys-apps/net-tools-1.60_p20090728014017"))

        self.assertGT(
            vkls("sys-apps/net-tools-1.60_p20100815160931"), vkls("sys-apps/net-tools-1.60_p20090728014017-r1")
        )

        # Regression test: python does comparison slightly differently
        # if the classes do not match exactly (it prefers rich
        # comparison over __cmp__).
        class DummySubclass(self.kls):
            pass

        self.assertNotEqual(DummySubclass("da/ba-6.0_alpha0_p1", versioned=True), vkls("da/ba-6.0_alpha"))
        self.assertEqual(DummySubclass("da/ba-6.0_alpha0", versioned=True), vkls("da/ba-6.0_alpha"))

        self.assertNotEqual(DummySubclass("da/ba-6.0", versioned=True), "foon")
        self.assertEqual(DummySubclass("da/ba-6.0", versioned=True), DummySubclass("da/ba-6.0-r0", versioned=True))
示例#27
0
    def test_cmp(self):
        ukls, vkls = self.ukls, self.vkls
        assert cmp(vkls("dev-util/diffball-0.1"), vkls("dev-util/diffball-0.2")) < 0
        base = "dev-util/diffball-0.7.1"
        assert not cmp(vkls(base), vkls(base))
        for rev in ("", "-r1"):
            last = None
            for suf in ["_alpha", "_beta", "_pre", "", "_p"]:
                if suf == "":
                    sufs = [suf]
                else:
                    sufs = [suf, suf+"4"]
                for x in sufs:
                    cur = vkls(base+x+rev)
                    assert cur == vkls(base+x+rev)
                    if last is not None:
                        assert cur > last

        assert vkls("da/ba-6a") > vkls("da/ba-6")
        assert vkls("da/ba-6a-r1") > vkls("da/ba-6a")
        assert vkls("da/ba-6.0") > vkls("da/ba-6")
        assert vkls("da/ba-6.0.0") > vkls("da/ba-6.0b")
        assert vkls("da/ba-6.02") > vkls("da/ba-6.0.0")
        # float comparison rules.
        assert vkls("da/ba-6.2") > vkls("da/ba-6.054")
        assert vkls("da/ba-6") == vkls("da/ba-6")
        assert ukls("db/ba") > ukls("da/ba")
        assert ukls("da/bb") > ukls("da/ba")
        assert vkls("da/ba-6.0_alpha0_p1") > vkls("da/ba-6.0_alpha")
        assert vkls("da/ba-6.0_alpha") == vkls("da/ba-6.0_alpha0")
        assert vkls("da/ba-6.1") > vkls("da/ba-6.09")
        assert vkls("da/ba-6.0.1") > vkls("da/ba-6.0")
        assert vkls("da/ba-12.2.5") > vkls("da/ba-12.2b")

        # test for gentoo bug 287848
        assert vkls("dev-lang/erlang-12.2.5") > vkls("dev-lang/erlang-12.2b")
        assert vkls("dev-lang/erlang-12.2.5-r1") > vkls("dev-lang/erlang-12.2b")

        assert vkls("da/ba-6.01.0") == vkls("da/ba-6.010.0")

        for v1, v2 in (("1.001000000000000000001", "1.001000000000000000002"),
            ("1.00100000000", "1.0010000000000000001"),
            ("1.01", "1.1")):
            assert vkls(f"da/ba-{v2}") > vkls(f"da/ba-{v1}")

        for x in (18, 36, 100):
            s = "0" * x
            assert vkls(f"da/ba-10{s}1") > vkls(f"da/ba-1{s}1")

        for x in (18, 36, 100):
            s = "0" * x
            assert vkls(f"da/ba-1-r10{s}1") > vkls(f"da/ba-1-r1{s}1")

        assert vkls('sys-apps/net-tools-1.60_p2010081516093') > \
            vkls('sys-apps/net-tools-1.60_p2009072801401')

        assert vkls('sys-apps/net-tools-1.60_p20100815160931') > \
            vkls('sys-apps/net-tools-1.60_p20090728014017')

        assert vkls('sys-apps/net-tools-1.60_p20100815160931') > \
            vkls('sys-apps/net-tools-1.60_p20090728014017-r1')

        # Regression test: python does comparison slightly differently
        # if the classes do not match exactly (it prefers rich
        # comparison over __cmp__).
        class DummySubclass(self.kls):
            pass

        assert DummySubclass("da/ba-6.0_alpha0_p1", versioned=True) != vkls("da/ba-6.0_alpha")
        assert DummySubclass("da/ba-6.0_alpha0", versioned=True) == vkls("da/ba-6.0_alpha")

        assert DummySubclass("da/ba-6.0", versioned=True) != "foon"
        assert DummySubclass("da/ba-6.0", versioned=True) == \
            DummySubclass("da/ba-6.0-r0", versioned=True)
示例#28
0
文件: cpv.py 项目: ulm/pkgcore
def native_ver_cmp(ver1, rev1, ver2, rev2):

    # If the versions are the same, comparing revisions will suffice.
    if ver1 == ver2:
        # revisions are equal if 0 or None (versionless cpv)
        if not rev1 and not rev2:
            return 0
        return cmp(rev1, rev2)

    # Split up the versions into dotted strings and lists of suffixes.
    parts1 = ver1.split("_")
    parts2 = ver2.split("_")

    # If the dotted strings are equal, we can skip doing a detailed comparison.
    if parts1[0] != parts2[0]:

        # First split up the dotted strings into their components.
        ver_parts1 = parts1[0].split(".")
        ver_parts2 = parts2[0].split(".")

        # Pull out any letter suffix on the final components and keep
        # them for later.
        letters = []
        for ver_parts in (ver_parts1, ver_parts2):
            if ver_parts[-1][-1].isalpha():
                letters.append(ord(ver_parts[-1][-1]))
                ver_parts[-1] = ver_parts[-1][:-1]
            else:
                # Using -1 simplifies comparisons later
                letters.append(-1)

        # OPT: Pull length calculation out of the loop
        ver_parts1_len = len(ver_parts1)
        ver_parts2_len = len(ver_parts2)

        # Iterate through the components
        for v1, v2 in zip(ver_parts1, ver_parts2):

            # If the string components are equal, the numerical
            # components will be equal too.
            if v1 == v2:
                continue

            # If one of the components begins with a "0" then they
            # are compared as floats so that 1.1 > 1.02; else ints.
            if v1[0] != "0" and v2[0] != "0":
                v1 = int(v1)
                v2 = int(v2)
            else:
                # handle the 0.060 == 0.060 case.
                v1 = v1.rstrip("0")
                v2 = v2.rstrip("0")

            # If they are not equal, the higher value wins.
            c = cmp(v1, v2)
            if c:
                return c

        if ver_parts1_len > ver_parts2_len:
            return 1
        elif ver_parts2_len > ver_parts1_len:
            return -1

        # The dotted components were equal. Let's compare any single
        # letter suffixes.
        if letters[0] != letters[1]:
            return cmp(letters[0], letters[1])

    # The dotted components were equal, so remove them from our lists
    # leaving only suffixes.
    del parts1[0]
    del parts2[0]

    # OPT: Pull length calculation out of the loop
    parts1_len = len(parts1)
    parts2_len = len(parts2)

    # Iterate through the suffixes
    for x in range(max(parts1_len, parts2_len)):

        # If we're at the end of one of our lists, we need to use
        # the next suffix from the other list to decide who wins.
        if x == parts1_len:
            match = suffix_regexp.match(parts2[x])
            val = suffix_value[match.group(1)]
            if val:
                return cmp(0, val)
            return cmp(0, int("0" + match.group(2)))
        if x == parts2_len:
            match = suffix_regexp.match(parts1[x])
            val = suffix_value[match.group(1)]
            if val:
                return cmp(val, 0)
            return cmp(int("0" + match.group(2)), 0)

        # If the string values are equal, no need to parse them.
        # Continue on to the next.
        if parts1[x] == parts2[x]:
            continue

        # Match against our regular expression to make a split between
        # "beta" and "1" in "beta1"
        match1 = suffix_regexp.match(parts1[x])
        match2 = suffix_regexp.match(parts2[x])

        # If our int'ified suffix names are different, use that as the basis
        # for comparison.
        c = cmp(suffix_value[match1.group(1)], suffix_value[match2.group(1)])
        if c:
            return c

        # Otherwise use the digit as the basis for comparison.
        c = cmp(int("0" + match1.group(2)), int("0" + match2.group(2)))
        if c:
            return c

    # Our versions had different strings but ended up being equal.
    # The revision holds the final difference.
    return cmp(rev1, rev2)
示例#29
0
文件: cpv.py 项目: neko259/pkgcore
def native_ver_cmp(ver1, rev1, ver2, rev2):

    # If the versions are the same, comparing revisions will suffice.
    if ver1 == ver2:
        return cmp(rev1, rev2)

    # Split up the versions into dotted strings and lists of suffixes.
    parts1 = ver1.split("_")
    parts2 = ver2.split("_")

    # If the dotted strings are equal, we can skip doing a detailed comparison.
    if parts1[0] != parts2[0]:

        # First split up the dotted strings into their components.
        ver_parts1 = parts1[0].split(".")
        ver_parts2 = parts2[0].split(".")

        # Pull out any letter suffix on the final components and keep
        # them for later.
        letters = []
        for ver_parts in (ver_parts1, ver_parts2):
            if ver_parts[-1][-1].isalpha():
                letters.append(ord(ver_parts[-1][-1]))
                ver_parts[-1] = ver_parts[-1][:-1]
            else:
                # Using -1 simplifies comparisons later
                letters.append(-1)

        # OPT: Pull length calculation out of the loop
        ver_parts1_len = len(ver_parts1)
        ver_parts2_len = len(ver_parts2)

        # Iterate through the components
        for v1, v2 in izip(ver_parts1, ver_parts2):

            # If the string components are equal, the numerical
            # components will be equal too.
            if v1 == v2:
                continue

            # If one of the components begins with a "0" then they
            # are compared as floats so that 1.1 > 1.02; else ints.
            if v1[0] != "0" and v2[0] != "0":
                v1 = int(v1)
                v2 = int(v2)
            else:
                # handle the 0.060 == 0.060 case.
                v1 = v1.rstrip("0")
                v2 = v2.rstrip("0")

            # If they are not equal, the higher value wins.
            c = cmp(v1, v2)
            if c:
                return c

        if ver_parts1_len > ver_parts2_len:
            return 1
        elif ver_parts2_len > ver_parts1_len:
            return -1

        # The dotted components were equal. Let's compare any single
        # letter suffixes.
        if letters[0] != letters[1]:
            return cmp(letters[0], letters[1])

    # The dotted components were equal, so remove them from our lists
    # leaving only suffixes.
    del parts1[0]
    del parts2[0]

    # OPT: Pull length calculation out of the loop
    parts1_len = len(parts1)
    parts2_len = len(parts2)

    # Iterate through the suffixes
    for x in xrange(max(parts1_len, parts2_len)):

        # If we're at the end of one of our lists, we need to use
        # the next suffix from the other list to decide who wins.
        if x == parts1_len:
            match = suffix_regexp.match(parts2[x])
            val = suffix_value[match.group(1)]
            if val:
                return cmp(0, val)
            return cmp(0, int("0"+match.group(2)))
        if x == parts2_len:
            match = suffix_regexp.match(parts1[x])
            val = suffix_value[match.group(1)]
            if val:
                return cmp(val, 0)
            return cmp(int("0"+match.group(2)), 0)

        # If the string values are equal, no need to parse them.
        # Continue on to the next.
        if parts1[x] == parts2[x]:
            continue

        # Match against our regular expression to make a split between
        # "beta" and "1" in "beta1"
        match1 = suffix_regexp.match(parts1[x])
        match2 = suffix_regexp.match(parts2[x])

        # If our int'ified suffix names are different, use that as the basis
        # for comparison.
        c = cmp(suffix_value[match1.group(1)], suffix_value[match2.group(1)])
        if c:
            return c

        # Otherwise use the digit as the basis for comparison.
        c = cmp(int("0"+match1.group(2)), int("0"+match2.group(2)))
        if c:
            return c

    # Our versions had different strings but ended up being equal.
    # The revision holds the final difference.
    return cmp(rev1, rev2)
示例#30
0
文件: fs.py 项目: chutz/pkgcore
 def __cmp__(self, other):
     return cmp(self.location, other.location)
示例#31
0
 def __cmp__(self, other):
     return cmp(self.value, other.value)
示例#32
0
    def test_cmp(self):
        ukls, vkls = self.ukls, self.vkls
        assert cmp(vkls("dev-util/diffball-0.1"),
                   vkls("dev-util/diffball-0.2")) < 0
        base = "dev-util/diffball-0.7.1"
        assert not cmp(vkls(base), vkls(base))
        for rev in ("", "-r1"):
            last = None
            for suf in ["_alpha", "_beta", "_pre", "", "_p"]:
                if suf == "":
                    sufs = [suf]
                else:
                    sufs = [suf, suf + "4"]
                for x in sufs:
                    cur = vkls(base + x + rev)
                    assert cur == vkls(base + x + rev)
                    if last is not None:
                        assert cur > last

        assert vkls("da/ba-6a") > vkls("da/ba-6")
        assert vkls("da/ba-6a-r1") > vkls("da/ba-6a")
        assert vkls("da/ba-6.0") > vkls("da/ba-6")
        assert vkls("da/ba-6.0.0") > vkls("da/ba-6.0b")
        assert vkls("da/ba-6.02") > vkls("da/ba-6.0.0")
        # float comparison rules.
        assert vkls("da/ba-6.2") > vkls("da/ba-6.054")
        assert vkls("da/ba-6") == vkls("da/ba-6")
        assert ukls("db/ba") > ukls("da/ba")
        assert ukls("da/bb") > ukls("da/ba")
        assert vkls("da/ba-6.0_alpha0_p1") > vkls("da/ba-6.0_alpha")
        assert vkls("da/ba-6.0_alpha") == vkls("da/ba-6.0_alpha0")
        assert vkls("da/ba-6.1") > vkls("da/ba-6.09")
        assert vkls("da/ba-6.0.1") > vkls("da/ba-6.0")
        assert vkls("da/ba-12.2.5") > vkls("da/ba-12.2b")

        # test for gentoo bug 287848
        assert vkls("dev-lang/erlang-12.2.5") > vkls("dev-lang/erlang-12.2b")
        assert vkls("dev-lang/erlang-12.2.5-r1") > vkls(
            "dev-lang/erlang-12.2b")

        assert vkls("da/ba-6.01.0") == vkls("da/ba-6.010.0")

        for v1, v2 in (("1.001000000000000000001", "1.001000000000000000002"),
                       ("1.00100000000", "1.0010000000000000001"), ("1.01",
                                                                    "1.1")):
            assert vkls(f"da/ba-{v2}") > vkls(f"da/ba-{v1}")

        for x in (18, 36, 100):
            s = "0" * x
            assert vkls(f"da/ba-10{s}1") > vkls(f"da/ba-1{s}1")

        for x in (18, 36, 100):
            s = "0" * x
            assert vkls(f"da/ba-1-r10{s}1") > vkls(f"da/ba-1-r1{s}1")

        assert vkls('sys-apps/net-tools-1.60_p2010081516093') > \
            vkls('sys-apps/net-tools-1.60_p2009072801401')

        assert vkls('sys-apps/net-tools-1.60_p20100815160931') > \
            vkls('sys-apps/net-tools-1.60_p20090728014017')

        assert vkls('sys-apps/net-tools-1.60_p20100815160931') > \
            vkls('sys-apps/net-tools-1.60_p20090728014017-r1')

        # Regression test: python does comparison slightly differently
        # if the classes do not match exactly (it prefers rich
        # comparison over __cmp__).
        class DummySubclass(self.kls):
            pass

        assert DummySubclass("da/ba-6.0_alpha0_p1",
                             versioned=True) != vkls("da/ba-6.0_alpha")
        assert DummySubclass("da/ba-6.0_alpha0",
                             versioned=True) == vkls("da/ba-6.0_alpha")

        assert DummySubclass("da/ba-6.0", versioned=True) != "foon"
        assert DummySubclass("da/ba-6.0", versioned=True) == \
            DummySubclass("da/ba-6.0-r0", versioned=True)
示例#33
0
    def _verify(self, file_location, target, all_chksums=True, handlers=None):
        """
        Internal function for derivatives.

        Digs through chksums, and either returns None, or throws an
        errors.FetchFailed exception.
          - -2: file doesn't exist.
          - -1: if (size chksum is available, and
                file is smaller than stated chksum)
          - 0:  if all chksums match
          - 1:  if file is too large (if size chksums are available)
                or else size is right but a chksum didn't match.

        if all_chksums is True, all chksums must be verified; if false, all
        a handler can be found for are used.
        """

        nondefault_handlers = handlers
        if handlers is None:
            try:
                handlers = get_handlers(target.chksums)
            except KeyError:
                compatibility.raise_from(
                    errors.FetchFailed(
                        file_location,
                        "Couldn't find a required checksum handler"))
        if all_chksums:
            missing = set(target.chksums).difference(handlers)
            if missing:
                raise errors.RequiredChksumDataMissing(target,
                                                       *sorted(missing))

        if "size" in handlers:
            val = handlers["size"](file_location)
            if val == -1:
                raise errors.MissingDistfile(file_location)
            c = cmp(val, target.chksums["size"])
            if c:
                resumable = (c < 0)
                if resumable:
                    msg = "File is too small."
                else:
                    msg = "File is too big."
                raise errors.FetchFailed(file_location,
                                         msg,
                                         resumable=resumable)
        elif not os.path.exists(file_location):
            raise errors.MissingDistfile(file_location)
        elif not os.stat(file_location).st_size:
            raise errors.FetchFailed(file_location,
                                     'file is empty',
                                     resumable=False)

        chfs = set(target.chksums).intersection(handlers)
        chfs.discard("size")
        chfs = list(chfs)
        if nondefault_handlers:
            for x in chfs:
                val = handlers[x](file_location)
                if val != target.chksums[x]:
                    raise errors.FetchFailed(
                        file_location,
                        "Validation handler %s: expected %s, got %s" %
                        (x, target.chksums[x], val))
        else:
            desired_vals = [target.chksums[x] for x in chfs]
            calced = get_chksums(file_location, *chfs)
            for desired, got, chf in zip(desired_vals, calced, chfs):
                if desired != got:
                    raise errors.FetchFailed(
                        file_location,
                        "Validation handler %s: expected %s, got %s" %
                        (chf, desired, got))
示例#34
0
文件: base.py 项目: chutz/pkgcore
 def __eq__(self, other):
     if isinstance(other, wrapper):
         return cmp(self._raw_pkg, other._raw_pkg) == 0
     return cmp(self._raw_pkg, other) == 0
示例#35
0
 def __cmp__(self, other):
     return cmp(self.ver, other.ver)
示例#36
0
 def __cmp__(self, other):
     return cmp(self.ver, other.ver)
示例#37
0
 def __cmp__(self, other):
     return cmp(self.value, other.value)
示例#38
0
文件: base.py 项目: den4ix/pkgcore
    def _verify(self, file_location, target, all_chksums=True, handlers=None):
        """
        Internal function for derivatives.

        Digs through chksums, and either returns None, or throws an
        errors.FetchFailed exception.
          - -2: file doesn't exist.
          - -1: if (size chksum is available, and
                file is smaller than stated chksum)
          - 0:  if all chksums match
          - 1:  if file is too large (if size chksums are available)
                or else size is right but a chksum didn't match.

        if all_chksums is True, all chksums must be verified; if false, all
        a handler can be found for are used.
        """

        nondefault_handlers = handlers
        if handlers is None:
            try:
                handlers = get_handlers(target.chksums)
            except KeyError:
                compatibility.raise_from(errors.FetchFailed(
                    file_location, "Couldn't find a required checksum handler"))
        if all_chksums:
            missing = set(target.chksums).difference(handlers)
            if missing:
                raise errors.RequiredChksumDataMissing(target, *sorted(missing))

        if "size" in handlers:
            val = handlers["size"](file_location)
            if val == -1:
                raise errors.MissingDistfile(file_location)
            c = cmp(val, target.chksums["size"])
            if c:
                resumable = (c < 0)
                if resumable:
                    msg = "File is too small."
                else:
                    msg = "File is too big."
                raise errors.FetchFailed(
                    file_location, msg, resumable=resumable)
        elif not os.path.exists(file_location):
            raise errors.MissingDistfile(file_location)
        elif not os.stat(file_location).st_size:
            raise errors.FetchFailed(
                file_location, 'file is empty', resumable=False)

        chfs = set(target.chksums).intersection(handlers)
        chfs.discard("size")
        chfs = list(chfs)
        if nondefault_handlers:
            for x in chfs:
                val = handlers[x](file_location)
                if val != target.chksums[x]:
                    raise errors.FetchFailed(
                        file_location,
                        "Validation handler %s: expected %s, got %s" %
                        (x, target.chksums[x], val))
        else:
            desired_vals = [target.chksums[x] for x in chfs]
            calced = get_chksums(file_location, *chfs)
            for desired, got, chf in zip(desired_vals, calced, chfs):
                if desired != got:
                    raise errors.FetchFailed(
                        file_location,
                        "Validation handler %s: expected %s, got %s" %
                        (chf, desired, got))
示例#39
0
 def __cmp__(self, other):
     return cmp(self.location, other.location)
示例#40
0
    def test_cmp(self):
        ukls, vkls = self.ukls, self.vkls
        self.assertTrue(
            cmp(vkls("dev-util/diffball-0.1"),
                vkls("dev-util/diffball-0.2")) < 0)
        base = "dev-util/diffball-0.7.1"
        self.assertFalse(cmp(vkls(base), vkls(base)))
        for rev in ("", "-r1"):
            last = None
            for suf in ["_alpha", "_beta", "_pre", "", "_p"]:
                if suf == "":
                    sufs = [suf]
                else:
                    sufs = [suf, suf+"4"]
                for x in sufs:
                    cur = vkls(base+x+rev)
                    self.assertEqual(cur, vkls(base+x+rev))
                    if last is not None:
                        self.assertGT(cur, last)

        self.assertGT(vkls("da/ba-6a"), vkls("da/ba-6"))
        self.assertGT(vkls("da/ba-6a-r1"), vkls("da/ba-6a"))
        self.assertGT(vkls("da/ba-6.0"), vkls("da/ba-6"))
        self.assertGT(vkls("da/ba-6.0.0"), vkls("da/ba-6.0b"))
        self.assertGT(vkls("da/ba-6.02"), vkls("da/ba-6.0.0"))
        # float comparison rules.
        self.assertGT(vkls("da/ba-6.2"), vkls("da/ba-6.054"))
        self.assertEqual(vkls("da/ba-6"), vkls("da/ba-6"))
        self.assertGT(ukls("db/ba"), ukls("da/ba"))
        self.assertGT(ukls("da/bb"), ukls("da/ba"))
        self.assertGT(vkls("da/ba-6.0_alpha0_p1"), vkls("da/ba-6.0_alpha"))
        self.assertEqual(vkls("da/ba-6.0_alpha"), vkls("da/ba-6.0_alpha0"))
        self.assertGT(vkls("da/ba-6.1"), vkls("da/ba-6.09"))
        self.assertGT(vkls("da/ba-6.0.1"), vkls("da/ba-6.0"))
        self.assertGT(vkls("da/ba-12.2.5"), vkls("da/ba-12.2b"))

        # test for gentoo bug 287848
        self.assertGT(vkls("dev-lang/erlang-12.2.5"),
            vkls("dev-lang/erlang-12.2b"))
        self.assertGT(vkls("dev-lang/erlang-12.2.5-r1"),
            vkls("dev-lang/erlang-12.2b"))

        self.assertEqual(vkls("da/ba-6.01.0"), vkls("da/ba-6.010.0"))

        for v1, v2 in (("1.001000000000000000001", "1.001000000000000000002"),
            ("1.00100000000", "1.0010000000000000001"),
            ("1.01", "1.1")):
            self.assertGT(vkls("da/ba-%s" % v2), vkls("da/ba-%s" % v1))

        for x in (18, 36, 100):
            s = "0" * x
            self.assertGT(vkls("da/ba-10%s1" % s), vkls("da/ba-1%s1" % s))

        for x in (18, 36, 100):
            s = "0" * x
            self.assertGT(vkls("da/ba-1-r10%s1" % s),
                vkls("da/ba-1-r1%s1" % s))

        self.assertGT(vkls('sys-apps/net-tools-1.60_p2010081516093'),
            vkls('sys-apps/net-tools-1.60_p2009072801401'))

        self.assertGT(vkls('sys-apps/net-tools-1.60_p20100815160931'),
            vkls('sys-apps/net-tools-1.60_p20090728014017'))

        self.assertGT(vkls('sys-apps/net-tools-1.60_p20100815160931'),
            vkls('sys-apps/net-tools-1.60_p20090728014017-r1'))

        # Regression test: python does comparison slightly differently
        # if the classes do not match exactly (it prefers rich
        # comparison over __cmp__).
        class DummySubclass(self.kls):
            pass
        self.assertNotEqual(
            DummySubclass("da/ba-6.0_alpha0_p1", versioned=True),
                vkls("da/ba-6.0_alpha"))
        self.assertEqual(
            DummySubclass("da/ba-6.0_alpha0", versioned=True),
                vkls("da/ba-6.0_alpha"))

        self.assertNotEqual(DummySubclass("da/ba-6.0", versioned=True),
            "foon")
        self.assertEqual(DummySubclass("da/ba-6.0", versioned=True),
            DummySubclass("da/ba-6.0-r0", versioned=True))