61
61
if isinstance(value, six.string_types):
62
62
value = six.text_type(value)
64
msg = "Unable to interpret non-string value '%s' as boolean" % (value)
64
msg = "Unable to interpret non-string value '%s' as bytes" % (value)
65
65
raise ValueError(msg)
66
66
matches = re.match("([0-9]+)([a-zA-Z]+)", value)
68
msg = "Unable to interpret string value '%s' as bytes" % (value)
70
return int(matches.group(1)) * (1024 ** BYTE_POWER[matches.group(2)])
68
size = int(matches.group(1)) * (1024 ** BYTE_POWER[matches.group(2)])
70
# Assume that value passed in is bytes
74
msg = "Unable to interpret string value '%s' as bytes" % (value)
79
class BasicStringComparator(object):
80
"""Provides a class that will compare strings from an iterator type object.
81
Used to provide > and < comparisons on strings that may not necessarily be
82
alphanumerically ordered. e.g. OpenStack or Ubuntu releases AFTER the
88
def __init__(self, item):
89
if self._list is None:
90
raise Exception("Must define the _list in the class definition!")
92
self.index = self._list.index(item)
94
raise KeyError("Item '{}' is not in list '{}'"
95
.format(item, self._list))
97
def __eq__(self, other):
98
assert isinstance(other, str) or isinstance(other, self.__class__)
99
return self.index == self._list.index(other)
101
def __ne__(self, other):
102
return not self.__eq__(other)
104
def __lt__(self, other):
105
assert isinstance(other, str) or isinstance(other, self.__class__)
106
return self.index < self._list.index(other)
108
def __ge__(self, other):
109
return not self.__lt__(other)
111
def __gt__(self, other):
112
assert isinstance(other, str) or isinstance(other, self.__class__)
113
return self.index > self._list.index(other)
115
def __le__(self, other):
116
return not self.__gt__(other)
119
"""Always give back the item at the index so it can be used in
122
s_mitaka = CompareOpenStack('mitaka')
123
s_newton = CompareOpenstack('newton')
125
assert s_newton > s_mitaka
129
return self._list[self.index]