Fix #898 (TOC text block error)

This commit is contained in:
Kovid Goyal 2008-07-21 13:26:35 -07:00
parent 2d512fa7f7
commit 8d779e9156
6 changed files with 21 additions and 63 deletions

View File

@ -33,11 +33,17 @@ pictureflow :
cd ../PyQt && \ cd ../PyQt && \
mkdir -p .build && \ mkdir -p .build && \
cd .build && rm -f * && \ cd .build && rm -f * && \
python ../configure.py && make && \ ${PYTHON} ../configure.py && make && \
cd ../../../../../.. && \ cd ../../../../../.. && \
cp src/calibre/gui2/pictureflow/PyQt/.build/pictureflow.so src/calibre/plugins/ && \ cp src/calibre/gui2/pictureflow/PyQt/.build/pictureflow.so src/calibre/plugins/ && \
rm -rf src/calibre/gui2/pictureflow/.build rm -rf src/calibre/gui2/pictureflow/PyQt/.build rm -rf src/calibre/gui2/pictureflow/.build rm -rf src/calibre/gui2/pictureflow/PyQt/.build
lzx :
mkdir -p src/calibre/plugins && rm -f src/calibre/plugins/*pictureflow* && \
cd src/calibre/utils/lzx && mkdir .build && cd .build && \
${PYTHON} ../configure.py && make && cd - && \
cp src/calibre/utils/lzx/.build/lzx.so src/calibre/plugins/ && \
rm -rf src/calibre/utils/lzx/.build/
pot : pot :
cd src/calibre/translations && ${PYTHON} __init__.py pot cd src/calibre/translations && ${PYTHON} __init__.py pot

View File

@ -477,13 +477,16 @@ class Settings(QSettings):
'kovidgoyal.net', name) 'kovidgoyal.net', name)
def get(self, key, default=None): def get(self, key, default=None):
key = str(key) try:
if not self.contains(key): key = str(key)
if not self.contains(key):
return default
val = str(self.value(key, QVariant()).toByteArray())
if not val:
return None
return cPickle.loads(val)
except:
return default return default
val = str(self.value(key, QVariant()).toByteArray())
if not val:
return None
return cPickle.loads(val)
def set(self, key, val): def set(self, key, val):
val = cPickle.dumps(val, -1) val = cPickle.dumps(val, -1)

View File

@ -1453,6 +1453,7 @@ class HTMLConverter(object, LoggingInterface):
self.page_break_found = True self.page_break_found = True
if self.options.add_chapters_to_toc: if self.options.add_chapters_to_toc:
self.current_block.must_append = True
self.extra_toc_entries.append((self.get_text(tag, self.extra_toc_entries.append((self.get_text(tag,
limit=1000), self.current_block)) limit=1000), self.current_block))
@ -1666,6 +1667,7 @@ class HTMLConverter(object, LoggingInterface):
self.page_break_found = True self.page_break_found = True
if self.options.add_chapters_to_toc: if self.options.add_chapters_to_toc:
self.current_block.must_append = True
self.extra_toc_entries.append((self.get_text(tag, self.extra_toc_entries.append((self.get_text(tag,
limit=1000), self.current_block)) limit=1000), self.current_block))

View File

@ -40,7 +40,6 @@ from calibre.gui2.dialogs.search import SearchDialog
from calibre.gui2.dialogs.user_profiles import UserProfiles from calibre.gui2.dialogs.user_profiles import UserProfiles
from calibre.gui2.dialogs.choose_format import ChooseFormatDialog from calibre.gui2.dialogs.choose_format import ChooseFormatDialog
from calibre.gui2.dialogs.book_info import BookInfo from calibre.gui2.dialogs.book_info import BookInfo
from calibre.library.database import DatabaseLocked
from calibre.ebooks.metadata.meta import set_metadata from calibre.ebooks.metadata.meta import set_metadata
from calibre.ebooks.metadata import MetaInformation from calibre.ebooks.metadata import MetaInformation
from calibre.ebooks import BOOK_EXTENSIONS from calibre.ebooks import BOOK_EXTENSIONS
@ -1247,12 +1246,7 @@ path_to_ebook to the database.
'<p>%s is already running. %s</p>'%(__appname__, extra)) '<p>%s is already running. %s</p>'%(__appname__, extra))
return 1 return 1
initialize_file_icon_provider() initialize_file_icon_provider()
try: main = Main(single_instance, opts)
main = Main(single_instance, opts)
except DatabaseLocked, err:
QMessageBox.critical(None, 'Cannot Start '+__appname__,
'<p>Another program is using the database. <br/>Perhaps %s is already running?<br/>If not try deleting the file %s'%(__appname__, err.lock_file_path))
return 1
sys.excepthook = main.unhandled_exception sys.excepthook = main.unhandled_exception
if len(args) > 1: if len(args) > 1:
main.add_filesystem_book(args[1]) main.add_filesystem_book(args[1])

View File

@ -31,47 +31,9 @@ class Concatenate(object):
return self.ans[:-len(self.sep)] return self.ans[:-len(self.sep)]
return self.ans return self.ans
_lock_file = None
class DatabaseLocked(Exception):
def __init__(self, msg, lock_file_path):
Exception.__init__(self, msg)
self.lock_file_path = lock_file_path
def _lock(path):
path = os.path.join(os.path.dirname(path), '.'+os.path.basename(path)+'.lock')
global _lock_file
if _lock_file is not None:
raise DatabaseLocked('Database already locked in this instance.', _lock_file.name)
try:
_lock_file = open(path, 'wb')
except IOError:
raise DatabaseLocked('Database in use by another instance', path)
try:
import fcntl, errno
try:
fcntl.lockf(_lock_file.fileno(), fcntl.LOCK_EX|fcntl.LOCK_NB)
except IOError, err:
path = _lock_file.name
_lock_file = None
if err.errno in (errno.EACCES, errno.EAGAIN):
raise DatabaseLocked('Database in use by another instance', path)
except ImportError:
try:
import msvcrt
try:
msvcrt.locking(_lock_file.fileno(), msvcrt.LK_NBLCK, 1)
except IOError:
path = _lock_file.name
_lock_file = None
raise DatabaseLocked('Database in use by another instance', path)
except ImportError:
pass
def _connect(path): def _connect(path):
if isinstance(path, unicode): if isinstance(path, unicode):
path = path.encode('utf-8') path = path.encode('utf-8')
#_lock(path)
conn = sqlite.connect(path, detect_types=sqlite.PARSE_DECLTYPES|sqlite.PARSE_COLNAMES) conn = sqlite.connect(path, detect_types=sqlite.PARSE_DECLTYPES|sqlite.PARSE_COLNAMES)
conn.row_factory = lambda cursor, row : list(row) conn.row_factory = lambda cursor, row : list(row)
conn.create_aggregate('concat', 1, Concatenate) conn.create_aggregate('concat', 1, Concatenate)
@ -794,14 +756,6 @@ ALTER TABLE books ADD COLUMN isbn TEXT DEFAULT "" COLLATE NOCASE;
conn.commit() conn.commit()
def __del__(self):
global _lock_file
import os
if _lock_file is not None:
_lock_file.close()
if os.path.exists(_lock_file.name):
os.unlink(_lock_file.name)
def __init__(self, dbpath, row_factory=False): def __init__(self, dbpath, row_factory=False):
self.dbpath = dbpath self.dbpath = dbpath
self.conn = _connect(dbpath) self.conn = _connect(dbpath)

View File

@ -133,10 +133,9 @@ The graphical user interface of |app| is not starting on Windows?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If you've never used the graphical user interface before, try deleting the file library1.db (it will be somewhere under :file:`C:\\Documents and Settings` on Windows XP and :file:`C:\\Users` on Windows Vista. If that doesn't fix the problem, locate the file calibre.log (in the same places as library1.db) and post its contents in a help message on the `Forums <http://calibre.kovidgoyal.net/discussion>`_. If you can't find either file, try using the windows find feature to search for them. If the files dont exist on your system, try the following: If you've never used the graphical user interface before, try deleting the file library1.db (it will be somewhere under :file:`C:\\Documents and Settings` on Windows XP and :file:`C:\\Users` on Windows Vista. If that doesn't fix the problem, locate the file calibre.log (in the same places as library1.db) and post its contents in a help message on the `Forums <http://calibre.kovidgoyal.net/discussion>`_. If you can't find either file, try using the windows find feature to search for them. If the files dont exist on your system, try the following:
Start a command prompt (press the windows key and R and type cmd.exe in the run dialog). At the command prompt type the command `calibre-debug` and press enter. You will se a new, green prompt. At theis prompt, type the following two lines:: Start a command prompt (press the windows key and R and type cmd.exe in the run dialog). At the command prompt type the following command and press Enter::
from calibre.gui2.main import main calibre-debug -c "from calibre.gui2.main import main; main()"
main()
Post any output you see when asking for help. Post any output you see when asking for help.