Skip to content
This repository has been archived by the owner on Oct 31, 2022. It is now read-only.

Commit

Permalink
Reverted recursive sort, opted for natsorted lib
Browse files Browse the repository at this point in the history
Was having performance issue with very large directories.

This does have the issue of order "File (1)" before "File", have raised
an issue with natsorted.
  • Loading branch information
catmanjan committed Oct 10, 2013
1 parent df08b06 commit 6256c08
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 20 deletions.
20 changes: 8 additions & 12 deletions mangle/book.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from about import DialogAbout
from options import DialogOptions
from convert import DialogConvert
from natsort import natsorted


class Book(object):
Expand Down Expand Up @@ -352,13 +353,11 @@ def removeImageFiles(self):


def addImageFiles(self, filenames):
filenames.sort()

filenamesListed = []
for i in xrange(0, self.listWidgetFiles.count()):
filenamesListed.append(self.listWidgetFiles.item(i).text())

for filename in filenames:
for filename in natsorted(filenames):
if filename not in filenamesListed:
filename = QtCore.QString(filename)
self.listWidgetFiles.addItem(filename)
Expand All @@ -370,15 +369,12 @@ def addImageDirs(self, directories):
filenames = []

for directory in directories:
directory = unicode(directory)
for item in sorted(os.listdir(directory), key=util.tokenize):
item = unicode(item)
path = os.path.join(directory, item)
if self.isImageFile(path):
filenames.append(path)
elif os.path.isdir(path):
self.addImageDirs([path])

for root, subdirs, subfiles in os.walk(unicode(directory)):
for filename in subfiles:
path = os.path.join(root, filename)
if self.isImageFile(path):
filenames.append(path)

self.addImageFiles(filenames)


Expand Down
8 changes: 0 additions & 8 deletions mangle/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,3 @@
def buildResPath(relative):
directory = os.path.dirname(__file__)
return os.path.join(directory, relative)


digits = re.compile(r'(\d+)')
def tokenize(filename):
return tuple(int(token) if match else token
for token, match in
((fragment, digits.search(fragment))
for fragment in digits.split(filename)))

0 comments on commit 6256c08

Please sign in to comment.