From b259677d6f0bdf5772266060c633058932ac9ecd Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 11 Mar 2011 11:19:28 -0700 Subject: [PATCH] ... --- src/calibre/gui2/add_wizard/__init__.py | 8 +++----- src/calibre/library/add_to_library.py | 9 --------- src/calibre/library/database2.py | 19 ++++++++++++------- 3 files changed, 15 insertions(+), 21 deletions(-) diff --git a/src/calibre/gui2/add_wizard/__init__.py b/src/calibre/gui2/add_wizard/__init__.py index da1879ae97..5df3f601a0 100644 --- a/src/calibre/gui2/add_wizard/__init__.py +++ b/src/calibre/gui2/add_wizard/__init__.py @@ -11,7 +11,6 @@ from PyQt4.Qt import QWizard, QWizardPage, QIcon, QPixmap, Qt, QThread, \ pyqtSignal from calibre.gui2 import error_dialog, choose_dir, gprefs -from calibre.constants import filesystem_encoding from calibre.library.add_to_library import find_folders_under, \ find_books_in_folder, hash_merge_format_collections @@ -122,20 +121,19 @@ class WelcomePage(WizardPage, WelcomeWidget): x = unicode(self.opt_root_folder.text()).strip() if not x: return None - return os.path.abspath(x.encode(filesystem_encoding)) + return os.path.abspath(x) def get_one_per_folder(self): return self.opt_one_per_folder.isChecked() def validatePage(self): x = self.get_root_folder() - xu = x.decode(filesystem_encoding) if x and os.access(x, os.R_OK) and os.path.isdir(x): - gprefs['add wizard root folder'] = xu + gprefs['add wizard root folder'] = x gprefs['add wizard one per folder'] = self.get_one_per_folder() return True error_dialog(self, _('Invalid root folder'), - xu + _('is not a valid root folder'), show=True) + x + _('is not a valid root folder'), show=True) return False # }}} diff --git a/src/calibre/library/add_to_library.py b/src/calibre/library/add_to_library.py index 8451241e3c..a453423a3c 100644 --- a/src/calibre/library/add_to_library.py +++ b/src/calibre/library/add_to_library.py @@ -8,7 +8,6 @@ __docformat__ = 'restructuredtext en' import os from hashlib import sha1 -from calibre.constants import filesystem_encoding from calibre.ebooks import BOOK_EXTENSIONS def find_folders_under(root, db, add_root=True, # {{{ @@ -17,21 +16,13 @@ def find_folders_under(root, db, add_root=True, # {{{ Find all folders under the specified root path, ignoring any folders under the library path of db - root must be a bytestring in filesystem_encoding - If follow_links is True, follow symbolic links. WARNING; this can lead to infinite recursion. cancel_callback must be a no argument callable that returns True to cancel the search ''' - assert not isinstance(root, unicode) # root must be in filesystem encoding lp = db.library_path - if isinstance(lp, unicode): - try: - lp = lp.encode(filesystem_encoding) - except: - lp = None if lp: lp = os.path.abspath(lp) diff --git a/src/calibre/library/database2.py b/src/calibre/library/database2.py index b506e7e82d..e3caa3ba6d 100644 --- a/src/calibre/library/database2.py +++ b/src/calibre/library/database2.py @@ -147,6 +147,8 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns): def __init__(self, library_path, row_factory=False, default_prefs=None, read_only=False): + if isbytestring(library_path): + library_path = library_path.decode(filesystem_encoding) self.field_metadata = FieldMetadata() self._library_id_ = None # Create the lock to be used to guard access to the metadata writer @@ -160,8 +162,6 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns): self.dbpath = os.path.join(library_path, 'metadata.db') self.dbpath = os.environ.get('CALIBRE_OVERRIDE_DATABASE_PATH', self.dbpath) - if isinstance(self.dbpath, unicode) and not iswindows: - self.dbpath = self.dbpath.encode(filesystem_encoding) if read_only and os.path.exists(self.dbpath): # Work on only a copy of metadata.db to ensure that @@ -489,12 +489,15 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns): authors = self.authors(id, index_is_id=True) if not authors: authors = _('Unknown') - author = ascii_filename(authors.split(',')[0])[:self.PATH_LIMIT].decode(filesystem_encoding, 'replace') - title = ascii_filename(self.title(id, index_is_id=True))[:self.PATH_LIMIT].decode(filesystem_encoding, 'replace') + author = ascii_filename(authors.split(',')[0] + )[:self.PATH_LIMIT].decode('ascii', 'replace') + title = ascii_filename(self.title(id, index_is_id=True) + )[:self.PATH_LIMIT].decode('ascii', 'replace') while author[-1] in (' ', '.'): author = author[:-1] if not author: - author = ascii_filename(_('Unknown')).decode(filesystem_encoding, 'replace') + author = ascii_filename(_('Unknown')).decode( + 'ascii', 'replace') path = author + '/' + title + ' (%d)'%id return path @@ -505,8 +508,10 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns): authors = self.authors(id, index_is_id=True) if not authors: authors = _('Unknown') - author = ascii_filename(authors.split(',')[0])[:self.PATH_LIMIT].decode(filesystem_encoding, 'replace') - title = ascii_filename(self.title(id, index_is_id=True))[:self.PATH_LIMIT].decode(filesystem_encoding, 'replace') + author = ascii_filename(authors.split(',')[0] + )[:self.PATH_LIMIT].decode('ascii', 'replace') + title = ascii_filename(self.title(id, index_is_id=True) + )[:self.PATH_LIMIT].decode('ascii', 'replace') name = title + ' - ' + author while name.endswith('.'): name = name[:-1]