From c8ca1afe7044635c693bd603fe1768ad5c372e73 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 2 Feb 2010 10:49:40 -0700 Subject: [PATCH] Fix regression that broke recursive adding on windows with non ascii file paths --- src/calibre/gui2/add.py | 42 +++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/src/calibre/gui2/add.py b/src/calibre/gui2/add.py index ace2ac5c7e..0b37fe2515 100644 --- a/src/calibre/gui2/add.py +++ b/src/calibre/gui2/add.py @@ -43,28 +43,34 @@ class RecursiveFind(QThread): self.single_book_per_directory = single self.canceled = False + def walk(self, root): + self.books = [] + for dirpath in os.walk(root): + if self.canceled: + return + self.emit(SIGNAL('update(PyQt_PyObject)'), + _('Searching in')+' '+dirpath[0]) + self.books += list(self.db.find_books_in_directory(dirpath[0], + self.single_book_per_directory)) + def run(self): root = os.path.abspath(self.path) - self.books = [] - if isinstance(root, unicode): - root = root.encode(filesystem_encoding) try: - for dirpath in os.walk(root): - if self.canceled: - return - self.emit(SIGNAL('update(PyQt_PyObject)'), - _('Searching in')+' '+dirpath[0]) - self.books += list(self.db.find_books_in_directory(dirpath[0], - self.single_book_per_directory)) - except Exception, err: - import traceback - traceback.print_exc() + self.walk(root) + except: try: - msg = unicode(err) - except: - msg = repr(err) - self.emit(SIGNAL('found(PyQt_PyObject)'), msg) - return + if isinstance(root, unicode): + root = root.encode(filesystem_encoding) + self.walk(root) + except Exception, err: + import traceback + traceback.print_exc() + try: + msg = unicode(err) + except: + msg = repr(err) + self.emit(SIGNAL('found(PyQt_PyObject)'), msg) + return self.books = [formats for formats in self.books if formats]