From 4d27fda7eb96f1e2deb52969c1c32ef130f3cd86 Mon Sep 17 00:00:00 2001 From: Jan Date: Thu, 10 Oct 2013 13:56:43 +1100 Subject: [PATCH] Moved tokenize to utils Didn't see you had a dedicated file for utility functions, moved tokenize to utils. Added "re" reference to utils. --- mangle/book.py | 11 +---------- mangle/util.py | 9 +++++++++ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/mangle/book.py b/mangle/book.py index 633de50..00dd44e 100644 --- a/mangle/book.py +++ b/mangle/book.py @@ -24,15 +24,6 @@ from options import DialogOptions from convert import DialogConvert -import re -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))) - - class Book(object): DefaultDevice = 'Kindle 4' DefaultOutputFormat = 'Images & CBZ' @@ -379,7 +370,7 @@ class MainWindowBook(QtGui.QMainWindow): for directory in directories: directory = unicode(directory) - for item in sorted(os.listdir(directory), key=tokenize): + for item in sorted(os.listdir(directory), key=util.tokenize): item = unicode(item) path = os.path.join(directory, item) if self.isImageFile(path): diff --git a/mangle/util.py b/mangle/util.py index 6e39dc6..5b84855 100644 --- a/mangle/util.py +++ b/mangle/util.py @@ -15,8 +15,17 @@ import os.path +import re 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)))