Use stringtools.natural_sorter.
This commit is contained in:
		
							parent
							
								
									40a3e9d1a0
								
							
						
					
					
						commit
						53127e59ad
					
				
					 2 changed files with 3 additions and 14 deletions
				
			
		|  | @ -328,18 +328,6 @@ def is_xor(*args): | ||||||
|     ''' |     ''' | ||||||
|     return [bool(a) for a in args].count(True) == 1 |     return [bool(a) for a in args].count(True) == 1 | ||||||
| 
 | 
 | ||||||
| def natural_sorter(x): |  | ||||||
|     ''' |  | ||||||
|     Used for sorting files in 'natural' order instead of lexicographic order, |  | ||||||
|     so that you get 1 2 3 4 5 6 7 8 9 10 11 12 13 ... |  | ||||||
|     instead of 1 10 11 12 13 2 3 4 5 ... |  | ||||||
|     Thank you Mark Byers |  | ||||||
|     http://stackoverflow.com/a/11150413 |  | ||||||
|     ''' |  | ||||||
|     convert = lambda text: int(text) if text.isdigit() else text.lower() |  | ||||||
|     alphanum_key = lambda key: [convert(c) for c in re.split('([0-9]+)', key)] |  | ||||||
|     return alphanum_key(x) |  | ||||||
| 
 |  | ||||||
| def now(timestamp=True): | def now(timestamp=True): | ||||||
|     ''' |     ''' | ||||||
|     Return the current UTC timestamp or datetime object. |     Return the current UTC timestamp or datetime object. | ||||||
|  |  | ||||||
|  | @ -17,6 +17,7 @@ from voussoirkit import pathclass | ||||||
| from voussoirkit import ratelimiter | from voussoirkit import ratelimiter | ||||||
| from voussoirkit import spinal | from voussoirkit import spinal | ||||||
| from voussoirkit import sqlhelpers | from voussoirkit import sqlhelpers | ||||||
|  | from voussoirkit import stringtools | ||||||
| from voussoirkit import vlogging | from voussoirkit import vlogging | ||||||
| 
 | 
 | ||||||
| from . import constants | from . import constants | ||||||
|  | @ -1569,7 +1570,7 @@ class PDBUtilMixin: | ||||||
|             same order that the files are listed when natural sorted. This is |             same order that the files are listed when natural sorted. This is | ||||||
|             essentially an aesthetic preference, that when you are viewing the |             essentially an aesthetic preference, that when you are viewing the | ||||||
|             photos sorted by timestamp they are also natural sorted. |             photos sorted by timestamp they are also natural sorted. | ||||||
|             See helpers.natural_sorter. |             See stringtools.natural_sorter. | ||||||
| 
 | 
 | ||||||
|         new_photo_kwargs: |         new_photo_kwargs: | ||||||
|             A dict of kwargs to pass into every call of new_photo. |             A dict of kwargs to pass into every call of new_photo. | ||||||
|  | @ -1747,7 +1748,7 @@ class PDBUtilMixin: | ||||||
| 
 | 
 | ||||||
|         for (current_directory, subdirectories, files) in walk_generator: |         for (current_directory, subdirectories, files) in walk_generator: | ||||||
|             if natural_sort: |             if natural_sort: | ||||||
|                 files = sorted(files, key=lambda f: helpers.natural_sorter(f.basename)) |                 files = sorted(files, key=lambda f: stringtools.natural_sorter(f.basename)) | ||||||
| 
 | 
 | ||||||
|             photos = [create_or_fetch_photo(file) for file in files] |             photos = [create_or_fetch_photo(file) for file in files] | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue