Revision 7d4da09e

b/lib/utils/algo.py
26 26
import time
27 27

  
28 28

  
29
_SORTER_RE = re.compile("^%s(.*)$" % (8 * "(\D+|\d+)?"))
29
_SORTER_GROUPS = 8
30
_SORTER_RE = re.compile("^%s(.*)$" % (_SORTER_GROUPS * "(\D+|\d+)?"))
30 31
_SORTER_DIGIT = re.compile("^\d+$")
31 32

  
32 33

  
......
78 79
    return val
79 80

  
80 81

  
81
def _NiceSortKey(value):
82
def NiceSortKey(value):
82 83
  """Extract key for sorting.
83 84

  
84 85
  """
......
107 108

  
108 109
  """
109 110
  if key is None:
110
    keyfunc = _NiceSortKey
111
    keyfunc = NiceSortKey
111 112
  else:
112
    keyfunc = lambda value: _NiceSortKey(key(value))
113
    keyfunc = lambda value: NiceSortKey(key(value))
113 114

  
114 115
  return sorted(values, key=keyfunc)
115 116

  
b/test/ganeti.utils.algo_unittest.py
218 218
    self.assertEqual(keyfn.count, len(data),
219 219
                     msg="Key function was not called once per value")
220 220

  
221
  def testNiceSortKey(self):
222
    self.assertEqual(algo.NiceSortKey(""),
223
                     ([None] * algo._SORTER_GROUPS) + [""])
224
    self.assertEqual(algo.NiceSortKey("Hello World"),
225
                     ["Hello World"] +
226
                     ([None] * int(algo._SORTER_GROUPS - 1)) + [""])
227
    self.assertEqual(algo.NiceSortKey("node1.net75.bld3.example.com"),
228
                     ["node", 1, ".net", 75, ".bld", 3, ".example.com",
229
                      None, ""])
230

  
221 231

  
222 232
class TimeMock:
223 233
  def __init__(self, values):

Also available in: Unified diff