Skip to content

Commit 8cd07f4

Browse files
committed
py3 is pickier about comparisons in sorted
1 parent 9802ad1 commit 8cd07f4

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

hubblestack/hec/dq.py

+17-7
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,22 @@ def __bool__(self):
4949
return False
5050
__nonzero__ = __bool__ # stupid python2
5151

52+
def numbered_file_split_key(x):
53+
""" for sorting purposes, split filenames like '238048.11', '238048.17',
54+
'238048.0' into lists of integers. E.g.:
55+
56+
for fname in sorted(filenames, key=numbered_file_split_key):
57+
do_things_ordered_by_integer_sort()
58+
"""
59+
try:
60+
return [int(i) for i in x.split('.')]
61+
except:
62+
pass
63+
try:
64+
return [int(x)]
65+
except:
66+
pass
67+
return list()
5268

5369
class DiskQueue(OKTypesMixin):
5470
sep = b' '
@@ -235,14 +251,8 @@ def pop(self):
235251
@property
236252
def files(self):
237253
""" generate all filenames in the diskqueue (returns iterable) """
238-
def _k(x):
239-
try:
240-
return [int(i) for i in x.split('.')]
241-
except:
242-
pass
243-
return x
244254
for path, dirs, files in sorted(os.walk(self.directory)):
245-
for fname in [os.path.join(path, f) for f in sorted(files, key=_k)]:
255+
for fname in [os.path.join(path, f) for f in sorted(files, key=numbered_file_split_key)]:
246256
if fname.endswith('.meta'):
247257
continue
248258
yield fname

0 commit comments

Comments
 (0)