Beispiel #1
0
 def compare(clazz, v1, v2):
   epoch_cmp = cmp(v1.epoch, v2.epoch)
   if epoch_cmp != 0:
     return epoch_cmp
   upstream_version_cmp = clazz.compare_upstream_version(v1.upstream_version, v2.upstream_version)
   if upstream_version_cmp != 0:
     return upstream_version_cmp
   return cmp(v1.revision, v2.revision)
Beispiel #2
0
 def __lt__(self, other):
     check.check_package_descriptor(other)
     name_rv = cmp(self.name, other.name)
     if name_rv < 0:
         return True
     version_rv = build_version.compare(self.version, other.version)
     if version_rv < 0:
         return True
     requirements_rv = cmp(self.requirements, other.requirements)
     if requirements_rv < 0:
         return True
     if self.properties.keys() < other.properties.keys():
         return True
     return False
Beispiel #3
0
 def compare(self, other):
     check.check(other, (type_checked_list, list, tuple), allow_none=True)
     if other == None:
         return -1
     len_cmp = cmp(len(self), len(other))
     if len_cmp != 0:
         return len_cmp
     other_values = self._get_values(other)
     for a, b in zip(self._values, other_values):
         #      if isinstance(b, tuple):
         #        b = self.__value_type__(*b)
         next_cmp = cmp(a, b)
         if next_cmp != 0:
             return next_cmp
     return 0
Beispiel #4
0
    def test___cmp__(self):
        a = KVL()
        a.append(KV('foo', 'hi'))
        a.append(KV('bar', '666'))

        b = KVL()
        b.append(KV('apple', '6'))
        b.append(KV('kiwi', '7'))

        self.assertEqual(1, cmp(a, b))

        c = KVL()
        c.append(KV('foo', 'hi'))
        c.append(KV('bar', '666'))

        self.assertEqual(0, cmp(a, c))
Beispiel #5
0
    def test___cmp__(self):
        a = SL()
        a.append('foo')
        a.append('bar')

        b = SL()
        b.append('apple')
        b.append('kiwi')

        self.assertEqual(1, cmp(a, b))

        c = SL()
        c.append('foo')
        c.append('bar')

        self.assertEqual(0, cmp(a, c))
Beispiel #6
0
 def full_name_cmp(clazz, pi1, pi2):
     'Compare name, version and revision and return an int either -1, 0, or 1'
     check.check_package_descriptor(pi1)
     check.check_package_descriptor(pi2)
     name_cmp = cmp(pi1.name, pi2.name)
     if name_cmp != 0:
         return name_cmp
     return build_version.compare(pi1.version, pi2.version)
Beispiel #7
0
 def test_binary_search(self):
   a = [ 1, 5, 7, 9, 20, 1000, 1001, 1002, 3000 ]
   comp = lambda a, b: cmp(a, b)
   self.assertEqual( 0, algorithm.binary_search(a, 1, comp) )
   self.assertEqual( -1, algorithm.binary_search(a, 0, comp) )
   self.assertEqual( -1, algorithm.binary_search(a, 2, comp) )
   self.assertEqual( 4, algorithm.binary_search(a, 20, comp) )
   self.assertEqual( 8, algorithm.binary_search(a, 3000, comp) )
   self.assertEqual( -1, algorithm.binary_search(a, 3001, comp) )
Beispiel #8
0
 def compare(self, other, remote_only = False):
   check.check_git_branch(other)
   if remote_only:
     t1 = ( self.name, self.commit, self.comment )
     t2 = ( other.name, other.commit, other.comment )
   else:
     t1 = self
     t2 = other
   return cmp(t1, t2)
Beispiel #9
0
 def compare(clazz, a1, a2):
     check.check_artifact_descriptor(a1)
     check.check_artifact_descriptor(a2)
     t1 = (a1.name, a1.system, a1.level, a1.arch, a1.distro,
           a1.distro_version_major, a1.distro_version_minor)
     t2 = (a2.name, a2.system, a2.level, a2.arch, a2.distro,
           a2.distro_version_major, a2.distro_version_minor)
     result = cmp(t1, t2)
     if result != 0:
         return result
     return build_version.compare(a1.build_version, a2.build_version)
Beispiel #10
0
    def compare(clazz, v1, v2):
        '''
    Compare software versions taking into account punctuation using an algorithm similar to debian's
    This function should really try to match debian perfectly:
    https://manpages.debian.org/wheezy/dpkg-dev/deb-version.5.en.html#Sorting_Algorithm
    '''
        check.check_string(v1)
        check.check_string(v2)

        sv1 = semantic_version(v1)
        sv2 = semantic_version(v2)
        return cmp(sv1._tokens, sv2._tokens)
Beispiel #11
0
 def _line_number_comparator(line1, line2):
     return cmp(line1.line_number, line2.line_number)
Beispiel #12
0
 def compare_upstream_version(clazz, v1, v2):
   check.check_string(v1)
   check.check_string(v2)
   tokens1 = [ token for token in upstream_version_lexer.tokenize(v1, 'build_version') ]
   tokens2 = [ token for token in upstream_version_lexer.tokenize(v2, 'build_version') ]
   return cmp(tokens1, tokens2)