Example #1
0
    def __eq__(self, other):
        """
        Return True if self effectively "equals" other, False otherwise. This equality
        check will take into account name, epoch, version, and release, allowing the
        release to be omitted from either object.

        :param other: Any object that has the following attributes: name, epoch, version, and
                      release. An RPM Unit is an example of such an object.
        :type  other: object
        :return:      True if self and other are equal, False otherwise
        :rtype:       bool
        """

        # Simple case, they are entirely different
        if self.name != other.name:
            return False

        # Attempt to compare the version information
        mine_version = version_utils.encode(self.version)
        mine_release = version_utils.encode(self.release) if self.release else None
        mine = [self.epoch, mine_version, mine_release]

        theirs_version = version_utils.encode(other.version)
        theirs_release = version_utils.encode(other.release) if other.release else None
        theirs = [other.epoch, theirs_version, theirs_release]

        # Release is optional, so if it's omitted in either case, remove it entirely
        # from the check.
        if mine[2] is None or theirs[2] is None:
            mine = mine[:2]
            theirs = theirs[:2]

        return mine == theirs
    def test_migrate(self):
        # Setup
        for type_id in (TYPE_ID_RPM, TYPE_ID_SRPM, TYPE_ID_DRPM):
            self.add_sample_data(type_id)

        # Test
        migration = _import_all_the_way(
            'pulp_rpm.plugins.migrations.0008_version_sort_index')
        migration.migrate()

        # Verify

        # The migration should cover these three types, so make sure they were all included
        for type_id in (TYPE_ID_RPM, TYPE_ID_SRPM, TYPE_ID_DRPM):
            collection = types_db.type_units_collection(type_id)

            test_me = collection.find_one({'version': '1.1'})
            self.assertEqual(test_me['version_sort_index'],
                             version_utils.encode('1.1'))
            self.assertEqual(test_me['release_sort_index'],
                             version_utils.encode('1.1'))

            # Make sure the script didn't run on units that already have the indexes
            test_me = collection.find_one({'version': '3.1'})
            self.assertEqual(test_me['version_sort_index'], 'fake')
            self.assertEqual(test_me['release_sort_index'], 'fake')
Example #3
0
    def __cmp__(self, other):
        """
        Compare a Requirement to any other object that has at least these attributes: name, epoch,
        version, and release. This method will return a negative value if self is "less than" other,
        0 if they are equal, and a positive value if self is "greater than" other. For example,
        a Requirement that references Firefox-23.0 compared to a Unit that references Firefox-23.1
        would return a negative value.

        The other object must have the same name as the Requirement, as it
        doesn't make sense to ask whether an object is greater or less than a Requirement when it
        has a different name. For example, a Requirement might reference Firefox-23.0, and other
        might be the package openssh-server-6.2. If this Requirement is asked to compare itself with
        openssh-server, it will raise ValueError.

        :param other: Any object that has the following attributes: name, epoch, version, and
                      release. An RPM Unit is an example of such an object.
        :type  other: object
        :return:      A negative value if self is less than other, 0 if self is equal to other, and
                      a positive value if self is greater than other.
        :rtype:       int
        """
        mine = [self.epoch, self.version, self.release]
        theirs = [other.epoch, other.version, other.release]
        # the encode function is rather picky about the type and length of its
        # argument, so we only call it for values that we know it will accept
        for i, value in enumerate(mine):
            if value:
                mine[i] = version_utils.encode(str(value))
        for i, value in enumerate(theirs):
            if value:
                theirs[i] = version_utils.encode(str(value))

        return cmp(mine, theirs)
Example #4
0
    def __cmp__(self, other):
        """
        Compare a Requirement to any other object that has at least these attributes: name, epoch,
        version, and release. This method will return a negative value if self is "less than" other,
        0 if they are equal, and a positive value if self is "greater than" other. For example,
        a Requirement that references Firefox-23.0 compared to a Unit that references Firefox-23.1
        would return a negative value.

        The other object must have the same name as the Requirement, as it
        doesn't make sense to ask whether an object is greater or less than a Requirement when it
        has a different name. For example, a Requirement might reference Firefox-23.0, and other
        might be the package openssh-server-6.2. If this Requirement is asked to compare itself with
        openssh-server, it will raise ValueError.

        :param other: Any object that has the following attributes: name, epoch, version, and
                      release. An RPM Unit is an example of such an object.
        :type  other: object
        :return:      A negative value if self is less than other, 0 if self is equal to other, and
                      a positive value if self is greater than other.
        :rtype:       int
        """
        mine = [self.epoch, self.version, self.release]
        theirs = [other.epoch, other.version, other.release]
        # the encode function is rather picky about the type and length of its
        # argument, so we only call it for values that we know it will accept
        for i, value in enumerate(mine):
            if value:
                mine[i] = version_utils.encode(str(value))
        for i, value in enumerate(theirs):
            if value:
                theirs[i] = version_utils.encode(str(value))

        return cmp(mine, theirs)
Example #5
0
    def __eq__(self, other):
        """
        Return True if self effectively "equals" other, False otherwise. This equality
        check will take into account name, epoch, version, and release, allowing the
        release to be omitted from either object.

        :param other: Any object that has the following attributes: name, epoch, version, and
                      release. An RPM Unit is an example of such an object.
        :type  other: object
        :return:      True if self and other are equal, False otherwise
        :rtype:       bool
        """

        # Simple case, they are entirely different
        if self.name != other.name:
            return False

        # Attempt to compare the version information
        mine_version = version_utils.encode(self.version)
        mine_release = version_utils.encode(self.release) if self.release else None
        mine = [self.epoch, mine_version, mine_release]

        theirs_version = version_utils.encode(other.version)
        theirs_release = version_utils.encode(other.release) if other.release else None
        theirs = [other.epoch, theirs_version, theirs_release]

        # Release is optional, so if it's omitted in either case, remove it entirely
        # from the check.
        if mine[2] is None or theirs[2] is None:
            mine = mine[:2]
            theirs = theirs[:2]

        return mine == theirs
Example #6
0
 def __init__(self, local_vars):
     self.metadata = local_vars.get('metadata', {})
     for name in self.UNIT_KEY_NAMES:
         setattr(self, name, local_vars[name])
         # Add the serialized version and release if available
         if name == 'version':
             self.metadata['version_sort_index'] = version_utils.encode(local_vars[name])
         elif name == 'release':
             self.metadata['release_sort_index'] = version_utils.encode(local_vars[name])
def _update_type(type_id):
    collection = types_db.type_units_collection(type_id)

    # Both indexes should be set at the same time, so this single check should be safe
    fix_us = collection.find({'version_sort_index' : None})
    for package in fix_us:
        package['version_sort_index'] = version_utils.encode(package['version'])
        package['release_sort_index'] = version_utils.encode(package['release'])

        collection.save(package, safe=True)
Example #8
0
    def pre_save_signal(cls, sender, document, **kwargs):
        """
        Generate the version & Release sort index before saving

        :param sender: sender class
        :type sender: object
        :param document: Document that sent the signal
        :type document: pulp_rpm.plugins.db.models.NonMetadataPackage
        """
        super(NonMetadataPackage, cls).pre_save_signal(sender, document, **kwargs)
        document.version_sort_index = version_utils.encode(document.version)
        document.release_sort_index = version_utils.encode(document.release)
def _update_type(type_id):
    collection = types_db.type_units_collection(type_id)

    # Both indexes should be set at the same time, so this single check should be safe
    fix_us = collection.find({'version_sort_index': None})
    for package in fix_us:
        package['version_sort_index'] = version_utils.encode(
            package['version'])
        package['release_sort_index'] = version_utils.encode(
            package['release'])

        collection.save(package, safe=True)
Example #10
0
    def pre_save_signal(cls, sender, document, **kwargs):
        """
        Generate the version & Release sort index before saving

        :param sender: sender class
        :type sender: object
        :param document: Document that sent the signal
        :type document: pulp_rpm.plugins.db.models.NonMetadataPackage
        """
        super(NonMetadataPackage, cls).pre_save_signal(sender, document, **kwargs)
        document.version_sort_index = version_utils.encode(document.version)
        document.release_sort_index = version_utils.encode(document.release)
    def assert_greater_than_or_equal(self, version1, version2):
        encoded1 = encode(version1)
        encoded2 = encode(version2)

        self.db.insert({'version' : version1, 'version_sort_index' : encoded1}, safe=True)
        self.db.insert({'version' : version2, 'version_sort_index' : encoded2}, safe=True)

        sorted_versions = self.db.find({}).sort([('version_sort_index', pymongo.DESCENDING)])

        msg = '[%s, %s] was less than [%s, %s]' % (version1, encoded1, version2, encoded2)
        self.assertEqual(sorted_versions[0]['version'], version1, msg=msg)

        self.db.remove()  # clean up for multiple calls to this in a single test
Example #12
0
 def test_non_letter_removal(self):
     # Each label is separated into a list of maximal alphabetic or numeric sections, with separators
     # (non-alphanumeric characters) ignored. So, '2.0.1' becomes ('2', '0', '1'), while
     # ('2xFg33.+f.5') becomes ('2', 'xFg', '33', 'f', '5').
     #
     # Test: Notice that the + is removed, in addition to the splitting apart of numbers and letters.
     self.assertEqual(encode('2xFg33.+f.5'), '01-2.$xFg.02-33.$f.01-5')
    def assert_greater_than_or_equal(self, version1, version2):
        encoded1 = encode(version1)
        encoded2 = encode(version2)

        self.db.insert({'version': version1, 'version_sort_index': encoded1})
        self.db.insert({'version': version2, 'version_sort_index': encoded2})

        sorted_versions = self.db.find({}).sort([('version_sort_index',
                                                  pymongo.DESCENDING)])

        msg = '[%s, %s] was less than [%s, %s]' % (version1, encoded1,
                                                   version2, encoded2)
        self.assertEqual(sorted_versions[0]['version'], version1, msg=msg)

        self.db.remove(
        )  # clean up for multiple calls to this in a single test
Example #14
0
 def test_non_letter_removal(self):
     # Each label is separated into a list of maximal alphabetic or numeric sections,
     # with separators (non-alphanumeric characters) ignored. So, '2.0.1' becomes
     # ('2', '0', '1'), while ('2xFg33.+f.5') becomes ('2', 'xFg', '33', 'f', '5').
     #
     # Test: Notice that the + is removed, in addition to the splitting apart of numbers and
     # letters.
     self.assertEqual(encode('2xFg33.+f.5'), '01-2.$xFg.02-33.$f.01-5')
Example #15
0
 def test_mixed(self):
     # Each label is separated into a list of maximal alphabetic or numeric sections, with separators
     # (non-alphanumeric characters) ignored. If there is any extra non-alphanumeric character at the
     # end, that. So, '2.0.1' becomes ('2', '0', '1'), while ('2xFg33.+f.5') becomes
     # ('2', 'xFg', '33', 'f', '5').
     #
     # Test: the int segments still need to be encoded as ints as well, hence the 1-1 in the second
     # segment.
     self.assertEqual(encode('2.1alpha'), '01-2.01-1.$alpha')
Example #16
0
    def test_parse(self):
        # Setup
        user_input = ['name=foo', 'version=1.0', 'release=2', 'license=GPL']

        # Test
        parsed = criteria_utils.parse_key_value(user_input)

        # Verify
        self.assertEqual(4, len(parsed))
        parsed.sort(key=lambda x : x[0])
        self.assertEqual(parsed[0][0], 'license')
        self.assertEqual(parsed[0][1], 'GPL')
        self.assertEqual(parsed[1][0], 'name')
        self.assertEqual(parsed[1][1], 'foo')
        self.assertEqual(parsed[2][0], version_utils.RELEASE_INDEX)
        self.assertEqual(parsed[2][1], version_utils.encode('2'))
        self.assertEqual(parsed[3][0], version_utils.VERSION_INDEX)
        self.assertEqual(parsed[3][1], version_utils.encode('1.0'))
Example #17
0
    def test_parse(self):
        # Setup
        user_input = ['name=foo', 'version=1.0', 'release=2', 'license=GPL']

        # Test
        parsed = criteria_utils.parse_key_value(user_input)

        # Verify
        self.assertEqual(4, len(parsed))
        parsed.sort(key=lambda x: x[0])
        self.assertEqual(parsed[0][0], 'license')
        self.assertEqual(parsed[0][1], 'GPL')
        self.assertEqual(parsed[1][0], 'name')
        self.assertEqual(parsed[1][1], 'foo')
        self.assertEqual(parsed[2][0], version_utils.RELEASE_INDEX)
        self.assertEqual(parsed[2][1], version_utils.encode('2'))
        self.assertEqual(parsed[3][0], version_utils.VERSION_INDEX)
        self.assertEqual(parsed[3][1], version_utils.encode('1.0'))
Example #18
0
 def test_mixed(self):
     # Each label is separated into a list of maximal alphabetic or numeric sections,
     # with separators (non-alphanumeric characters) ignored. If there is any extra
     # non-alphanumeric character at the end, that. So, '2.0.1' becomes ('2', '0', '1'),
     # while ('2xFg33.+f.5') becomes ('2', 'xFg', '33', 'f', '5').
     #
     # Test: the int segments still need to be encoded as ints as well, hence the 1-1 in the
     # second segment.
     self.assertEqual(encode('2.1alpha'), '01-2.01-1.$alpha')
Example #19
0
    def pre_save_signal(cls, sender, document, **kwargs):
        """
        Generate the version & Release sort index before saving

        :param sender: sender class
        :type sender: object
        :param document: Document that sent the signal
        :type document: pulp_rpm.plugins.db.models.Distribution
        """
        document.version_sort_index = version_utils.encode(document.version)
        super(Distribution, cls).pre_save_signal(sender, document, **kwargs)
Example #20
0
    def pre_save_signal(cls, sender, document, **kwargs):
        """
        Generate the version & Release sort index before saving

        :param sender: sender class
        :type sender: object
        :param document: Document that sent the signal
        :type document: pulp_rpm.plugins.db.models.Distribution
        """
        document.version_sort_index = version_utils.encode(document.version)
        super(Distribution, cls).pre_save_signal(sender, document, **kwargs)
Example #21
0
    def translate(key_value_tuple):
        """
        :param key_value_tuple: single key/value tuple to translate
        :return: new key-value tuple to use
        """
        for orig_key, translated_key in TRANSLATIONS.items():
            if key_value_tuple[0] == orig_key:
                encoded_value = version_utils.encode(key_value_tuple[1])
                return translated_key, encoded_value

        return key_value_tuple
Example #22
0
    def translate(key_value_tuple):
        """
        :param key_value_tuple: single key/value tuple to translate
        :return: new key-value tuple to use
        """
        for orig_key, translated_key in TRANSLATIONS.items():
            if key_value_tuple[0] == orig_key:
                encoded_value = version_utils.encode(key_value_tuple[1])
                return translated_key, encoded_value

        return key_value_tuple
    def test_migrate(self):
        # Setup
        for type_id in (TYPE_ID_RPM, TYPE_ID_SRPM, TYPE_ID_DRPM):
            self.add_sample_data(type_id)

        # Test
        migration = _import_all_the_way('pulp_rpm.plugins.migrations.0008_version_sort_index')
        migration.migrate()

        # Verify

        # The migration should cover these three types, so make sure they were all included
        for type_id in (TYPE_ID_RPM, TYPE_ID_SRPM, TYPE_ID_DRPM):
            collection = types_db.type_units_collection(type_id)

            test_me = collection.find_one({'version': '1.1'})
            self.assertEqual(test_me['version_sort_index'], version_utils.encode('1.1'))
            self.assertEqual(test_me['release_sort_index'], version_utils.encode('1.1'))

            # Make sure the script didn't run on units that already have the indexes
            test_me = collection.find_one({'version': '3.1'})
            self.assertEqual(test_me['version_sort_index'], 'fake')
            self.assertEqual(test_me['release_sort_index'], 'fake')
Example #24
0
 def complete_version_serialized(self):
     return tuple(
         version_utils.encode(field) for field in self.complete_version)
Example #25
0
 def test_letters(self):
     self.assertEqual(encode('alpha'), '$alpha')
     self.assertEqual(encode('beta.gamma'), '$beta.$gamma')
Example #26
0
 def test_both(self):
     self.assertEqual(encode('1.alpha'), '01-1.$alpha')
     self.assertEqual(encode('0.2.beta.1'), '01-0.01-2.$beta.01-1')
Example #27
0
 def test_leading_zeroes(self):
     # All numbers are converted to their numeric value. So '10' becomes 10, '000230' becomes 230,
     # and '00000' becomes 0.
     self.assertEqual(encode('1.001'), '01-1.01-1')
Example #28
0
 def test_large_ints(self):
     self.assertEqual(encode('1.1234567890'), '01-1.10-1234567890')
Example #29
0
 def complete_version_serialized(self):
     return tuple(version_utils.encode(field) for field in self.complete_version)
Example #30
0
 def test_numbers(self):
     self.assertEqual(encode('1.1'), '01-1.01-1')
     self.assertEqual(encode('2.3'), '01-2.01-3')
     self.assertEqual(encode('3.10'), '01-3.02-10')
     self.assertEqual(encode('127.0.0.1'), '03-127.01-0.01-0.01-1')
Example #31
0
 def test_numbers(self):
     self.assertEqual(encode('1.1'), '01-1.01-1')
     self.assertEqual(encode('2.3'), '01-2.01-3')
     self.assertEqual(encode('3.10'), '01-3.02-10')
     self.assertEqual(encode('127.0.0.1'), '03-127.01-0.01-0.01-1')
Example #32
0
 def test_leading_zeroes(self):
     # All numbers are converted to their numeric value. So '10' becomes 10, '000230' becomes
     # 230, and '00000' becomes 0.
     self.assertEqual(encode('1.001'), '01-1.01-1')
Example #33
0
 def test_both(self):
     self.assertEqual(encode('1.alpha'), '01-1.$alpha')
     self.assertEqual(encode('0.2.beta.1'), '01-0.01-2.$beta.01-1')
Example #34
0
 def test_letters(self):
     self.assertEqual(encode('alpha'), '$alpha')
     self.assertEqual(encode('beta.gamma'), '$beta.$gamma')
Example #35
0
 def test_large_ints(self):
     self.assertEqual(encode('1.1234567890'), '01-1.10-1234567890')