diff --git a/src/calibre/ebooks/pml/pmlconverter.py b/src/calibre/ebooks/pml/pmlconverter.py index 3fdd627d7e..d2eb2c3736 100644 --- a/src/calibre/ebooks/pml/pmlconverter.py +++ b/src/calibre/ebooks/pml/pmlconverter.py @@ -576,10 +576,15 @@ class PML_HTMLizer(object): if indent_state[c]: basic_indent = True elif c == 'T': - indent_state[c] = not indent_state[c] - if indent_state[c]: + # Ensure we only store the value on the first T set for the line. + if not indent_state['T']: adv_indent = True adv_indent_val = self.code_value(line) + else: + # We detected a T previously on this line. + # Don't replace the first detected value. + self.code_value(line) + indent_state['T'] = True elif c == '-': empty = False text = '­' diff --git a/src/calibre/gui2/actions/choose_library.py b/src/calibre/gui2/actions/choose_library.py index 001970f9db..d45843995e 100644 --- a/src/calibre/gui2/actions/choose_library.py +++ b/src/calibre/gui2/actions/choose_library.py @@ -343,7 +343,7 @@ class ChooseLibraryAction(InterfaceAction): db.dirtied(list(db.data.iterallids())) info_dialog(self.gui, _('Backup metadata'), _('Metadata will be backed up while calibre is running, at the ' - 'rate of approximately 1 book per second.'), show=True) + 'rate of approximately 1 book every three seconds.'), show=True) def check_library(self): db = self.gui.library_view.model().db diff --git a/src/calibre/library/caches.py b/src/calibre/library/caches.py index 2049feaa18..67529397b3 100644 --- a/src/calibre/library/caches.py +++ b/src/calibre/library/caches.py @@ -10,7 +10,6 @@ import re, itertools, time, traceback from itertools import repeat from datetime import timedelta from threading import Thread -from Queue import Empty from calibre.utils.config import tweaks from calibre.utils.date import parse_date, now, UNDEFINED_DATE @@ -54,7 +53,7 @@ class MetadataBackup(Thread): # {{{ (id_, sequence) = self.db.get_a_dirtied_book() if id_ is None: continue - print 'writer thread', id_, sequence + # print 'writer thread', id_, sequence except: # Happens during interpreter shutdown break diff --git a/src/calibre/library/database2.py b/src/calibre/library/database2.py index 7c8d5aee13..e1a1adc4ff 100644 --- a/src/calibre/library/database2.py +++ b/src/calibre/library/database2.py @@ -117,6 +117,9 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns): def __init__(self, library_path, row_factory=False, default_prefs=None, read_only=False): self.field_metadata = FieldMetadata() + # Create the lock to be used to guard access to the metadata writer + # queues. This must be an RLock, not a Lock + self.dirtied_lock = threading.RLock() if not os.path.exists(library_path): os.makedirs(library_path) self.listeners = set([]) @@ -167,10 +170,6 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns): return row[loc] def initialize_dynamic(self): - # Create the lock to be used to guard access to the metadata writer - # queues. This must be an RLock, not a Lock - self.dirtied_lock = threading.RLock() - self.field_metadata = FieldMetadata() #Ensure we start with a clean copy self.prefs = DBPrefs(self) defs = self.prefs.defaults @@ -624,6 +623,7 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns): # print 'needs to be cleaned' self.conn.execute('DELETE FROM metadata_dirtied WHERE book=?', (book_id,)) + self.conn.commit() try: del self.dirtied_cache[book_id] except: @@ -631,7 +631,6 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns): elif dc_sequence is not None: # print 'book needs to be done again' pass - self.conn.commit() def dump_metadata(self, book_ids=None, remove_from_dirtied=True, commit=True): @@ -659,6 +658,7 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns): self.conn.commit() def dirtied(self, book_ids, commit=True): + changed = False for book in book_ids: with self.dirtied_lock: # print 'dirtied: check id', book @@ -671,6 +671,7 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns): self.conn.execute( 'INSERT INTO metadata_dirtied (book) VALUES (?)', (book,)) + changed = True except IntegrityError: # Already in table pass @@ -680,7 +681,7 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns): # could lead to a problem because on restart, we won't put the book back # into the dirtied_cache. We deal with this by writing the dirtied_cache # back to the table on GUI exit. Not perfect, but probably OK - if commit: + if commit and changed: self.conn.commit() def get_a_dirtied_book(self):