Revision 6d0accae lib/utils/algo.py
b/lib/utils/algo.py | ||
---|---|---|
25 | 25 |
import re |
26 | 26 |
import time |
27 | 27 |
|
28 |
from ganeti import compat |
|
29 |
from ganeti.utils import text |
|
30 |
|
|
28 | 31 |
|
29 | 32 |
_SORTER_GROUPS = 8 |
30 | 33 |
_SORTER_RE = re.compile("^%s(.*)$" % (_SORTER_GROUPS * "(\D+|\d+)?")) |
... | ... | |
169 | 172 |
return new |
170 | 173 |
|
171 | 174 |
|
175 |
def SequenceToDict(seq, key=compat.fst): |
|
176 |
"""Converts a sequence to a dictionary with duplicate detection. |
|
177 |
|
|
178 |
@type seq: sequen |
|
179 |
@param seq: Input sequence |
|
180 |
@type key: callable |
|
181 |
@param key: Function for retrieving dictionary key from sequence element |
|
182 |
@rtype: dict |
|
183 |
|
|
184 |
""" |
|
185 |
keys = map(key, seq) |
|
186 |
|
|
187 |
duplicates = FindDuplicates(keys) |
|
188 |
if duplicates: |
|
189 |
raise ValueError("Duplicate keys found: %s" % text.CommaJoin(duplicates)) |
|
190 |
|
|
191 |
assert len(keys) == len(seq) |
|
192 |
|
|
193 |
return dict(zip(keys, seq)) |
|
194 |
|
|
195 |
|
|
172 | 196 |
class RunningTimeout(object): |
173 | 197 |
"""Class to calculate remaining timeout when doing several operations. |
174 | 198 |
|
Also available in: Unified diff