mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-31 14:33:54 -04:00
...
This commit is contained in:
parent
137b555893
commit
b259677d6f
@ -11,7 +11,6 @@ from PyQt4.Qt import QWizard, QWizardPage, QIcon, QPixmap, Qt, QThread, \
|
|||||||
pyqtSignal
|
pyqtSignal
|
||||||
|
|
||||||
from calibre.gui2 import error_dialog, choose_dir, gprefs
|
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, \
|
from calibre.library.add_to_library import find_folders_under, \
|
||||||
find_books_in_folder, hash_merge_format_collections
|
find_books_in_folder, hash_merge_format_collections
|
||||||
|
|
||||||
@ -122,20 +121,19 @@ class WelcomePage(WizardPage, WelcomeWidget):
|
|||||||
x = unicode(self.opt_root_folder.text()).strip()
|
x = unicode(self.opt_root_folder.text()).strip()
|
||||||
if not x:
|
if not x:
|
||||||
return None
|
return None
|
||||||
return os.path.abspath(x.encode(filesystem_encoding))
|
return os.path.abspath(x)
|
||||||
|
|
||||||
def get_one_per_folder(self):
|
def get_one_per_folder(self):
|
||||||
return self.opt_one_per_folder.isChecked()
|
return self.opt_one_per_folder.isChecked()
|
||||||
|
|
||||||
def validatePage(self):
|
def validatePage(self):
|
||||||
x = self.get_root_folder()
|
x = self.get_root_folder()
|
||||||
xu = x.decode(filesystem_encoding)
|
|
||||||
if x and os.access(x, os.R_OK) and os.path.isdir(x):
|
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()
|
gprefs['add wizard one per folder'] = self.get_one_per_folder()
|
||||||
return True
|
return True
|
||||||
error_dialog(self, _('Invalid root folder'),
|
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
|
return False
|
||||||
|
|
||||||
# }}}
|
# }}}
|
||||||
|
@ -8,7 +8,6 @@ __docformat__ = 'restructuredtext en'
|
|||||||
import os
|
import os
|
||||||
from hashlib import sha1
|
from hashlib import sha1
|
||||||
|
|
||||||
from calibre.constants import filesystem_encoding
|
|
||||||
from calibre.ebooks import BOOK_EXTENSIONS
|
from calibre.ebooks import BOOK_EXTENSIONS
|
||||||
|
|
||||||
def find_folders_under(root, db, add_root=True, # {{{
|
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
|
Find all folders under the specified root path, ignoring any folders under
|
||||||
the library path of db
|
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
|
If follow_links is True, follow symbolic links. WARNING; this can lead to
|
||||||
infinite recursion.
|
infinite recursion.
|
||||||
|
|
||||||
cancel_callback must be a no argument callable that returns True to cancel
|
cancel_callback must be a no argument callable that returns True to cancel
|
||||||
the search
|
the search
|
||||||
'''
|
'''
|
||||||
assert not isinstance(root, unicode) # root must be in filesystem encoding
|
|
||||||
lp = db.library_path
|
lp = db.library_path
|
||||||
if isinstance(lp, unicode):
|
|
||||||
try:
|
|
||||||
lp = lp.encode(filesystem_encoding)
|
|
||||||
except:
|
|
||||||
lp = None
|
|
||||||
if lp:
|
if lp:
|
||||||
lp = os.path.abspath(lp)
|
lp = os.path.abspath(lp)
|
||||||
|
|
||||||
|
@ -147,6 +147,8 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
|||||||
|
|
||||||
def __init__(self, library_path, row_factory=False, default_prefs=None,
|
def __init__(self, library_path, row_factory=False, default_prefs=None,
|
||||||
read_only=False):
|
read_only=False):
|
||||||
|
if isbytestring(library_path):
|
||||||
|
library_path = library_path.decode(filesystem_encoding)
|
||||||
self.field_metadata = FieldMetadata()
|
self.field_metadata = FieldMetadata()
|
||||||
self._library_id_ = None
|
self._library_id_ = None
|
||||||
# Create the lock to be used to guard access to the metadata writer
|
# 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.path.join(library_path, 'metadata.db')
|
||||||
self.dbpath = os.environ.get('CALIBRE_OVERRIDE_DATABASE_PATH',
|
self.dbpath = os.environ.get('CALIBRE_OVERRIDE_DATABASE_PATH',
|
||||||
self.dbpath)
|
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):
|
if read_only and os.path.exists(self.dbpath):
|
||||||
# Work on only a copy of metadata.db to ensure that
|
# 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)
|
authors = self.authors(id, index_is_id=True)
|
||||||
if not authors:
|
if not authors:
|
||||||
authors = _('Unknown')
|
authors = _('Unknown')
|
||||||
author = ascii_filename(authors.split(',')[0])[:self.PATH_LIMIT].decode(filesystem_encoding, 'replace')
|
author = ascii_filename(authors.split(',')[0]
|
||||||
title = ascii_filename(self.title(id, index_is_id=True))[:self.PATH_LIMIT].decode(filesystem_encoding, 'replace')
|
)[: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 (' ', '.'):
|
while author[-1] in (' ', '.'):
|
||||||
author = author[:-1]
|
author = author[:-1]
|
||||||
if not author:
|
if not author:
|
||||||
author = ascii_filename(_('Unknown')).decode(filesystem_encoding, 'replace')
|
author = ascii_filename(_('Unknown')).decode(
|
||||||
|
'ascii', 'replace')
|
||||||
path = author + '/' + title + ' (%d)'%id
|
path = author + '/' + title + ' (%d)'%id
|
||||||
return path
|
return path
|
||||||
|
|
||||||
@ -505,8 +508,10 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
|||||||
authors = self.authors(id, index_is_id=True)
|
authors = self.authors(id, index_is_id=True)
|
||||||
if not authors:
|
if not authors:
|
||||||
authors = _('Unknown')
|
authors = _('Unknown')
|
||||||
author = ascii_filename(authors.split(',')[0])[:self.PATH_LIMIT].decode(filesystem_encoding, 'replace')
|
author = ascii_filename(authors.split(',')[0]
|
||||||
title = ascii_filename(self.title(id, index_is_id=True))[:self.PATH_LIMIT].decode(filesystem_encoding, 'replace')
|
)[: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
|
name = title + ' - ' + author
|
||||||
while name.endswith('.'):
|
while name.endswith('.'):
|
||||||
name = name[:-1]
|
name = name[:-1]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user