File tree 1 file changed +17
-7
lines changed
1 file changed +17
-7
lines changed Original file line number Diff line number Diff line change @@ -49,6 +49,22 @@ def __bool__(self):
49
49
return False
50
50
__nonzero__ = __bool__ # stupid python2
51
51
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 ()
52
68
53
69
class DiskQueue (OKTypesMixin ):
54
70
sep = b' '
@@ -235,14 +251,8 @@ def pop(self):
235
251
@property
236
252
def files (self ):
237
253
""" 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
244
254
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 )]:
246
256
if fname .endswith ('.meta' ):
247
257
continue
248
258
yield fname
You can’t perform that action at this time.
0 commit comments