本文整理汇总了Python中pulp_rpm.common.version_utils.encode函数的典型用法代码示例。如果您正苦于以下问题:Python encode函数的具体用法?Python encode怎么用?Python encode使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了encode函数的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: __cmp__
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)
开发者ID:roysjosh,项目名称:pulp_rpm,代码行数:33,代码来源:depsolve.py
示例2: __eq__
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
开发者ID:hjensas,项目名称:pulp_rpm,代码行数:33,代码来源:depsolve.py
示例3: __init__
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])
开发者ID:AndreaGiardini,项目名称:pulp_rpm,代码行数:9,代码来源:models.py
示例4: _update_type
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)
开发者ID:bechtoldt,项目名称:pulp_rpm,代码行数:10,代码来源:0008_version_sort_index.py
示例5: pre_save_signal
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)
开发者ID:bkearney,项目名称:pulp_rpm,代码行数:12,代码来源:models.py
示例6: assert_greater_than_or_equal
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
开发者ID:asmacdo,项目名称:pulp_rpm,代码行数:13,代码来源:test_version_utils_db_sort.py
示例7: test_non_letter_removal
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')
开发者ID:beav,项目名称:pulp_rpm,代码行数:7,代码来源:test_version_utils.py
示例8: test_parse
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'))
开发者ID:asmacdo,项目名称:pulp_rpm,代码行数:18,代码来源:test_criteria_utils.py
示例9: test_mixed
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')
开发者ID:beav,项目名称:pulp_rpm,代码行数:9,代码来源:test_version_utils.py
示例10: translate
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
开发者ID:ATIX-AG,项目名称:pulp_rpm,代码行数:11,代码来源:criteria_utils.py
示例11: test_migrate
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')
开发者ID:dkliban,项目名称:pulp_rpm,代码行数:23,代码来源:test_0008_version_sort_index.py
示例12: complete_version_serialized
def complete_version_serialized(self):
return tuple(version_utils.encode(field) for field in self.complete_version)
开发者ID:bkearney,项目名称:pulp_rpm,代码行数:2,代码来源:models.py
示例13: test_numbers
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')
开发者ID:beav,项目名称:pulp_rpm,代码行数:5,代码来源:test_version_utils.py
示例14: test_both
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')
开发者ID:beav,项目名称:pulp_rpm,代码行数:3,代码来源:test_version_utils.py
示例15: test_letters
def test_letters(self):
self.assertEqual(encode('alpha'), '$alpha')
self.assertEqual(encode('beta.gamma'), '$beta.$gamma')
开发者ID:beav,项目名称:pulp_rpm,代码行数:3,代码来源:test_version_utils.py
示例16: test_large_ints
def test_large_ints(self):
self.assertEqual(encode('1.1234567890'), '01-1.10-1234567890')
开发者ID:beav,项目名称:pulp_rpm,代码行数:2,代码来源:test_version_utils.py
示例17: test_leading_zeroes
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')
开发者ID:beav,项目名称:pulp_rpm,代码行数:4,代码来源:test_version_utils.py
注:本文中的pulp_rpm.common.version_utils.encode函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论