mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Catalog generation: Work on a copy of the library database so as not to lock it
This commit is contained in:
parent
547cee660c
commit
7c084b0630
@ -30,7 +30,7 @@ def gui_catalog(fmt, title, dbspec, ids, out_file_name, sync, fmt_options, conne
|
|||||||
from calibre.library import db
|
from calibre.library import db
|
||||||
from calibre.utils.config import prefs
|
from calibre.utils.config import prefs
|
||||||
prefs.refresh()
|
prefs.refresh()
|
||||||
db = db()
|
db = db(read_only=True)
|
||||||
db.catalog_plugin_on_device_temp_mapping = dbspec
|
db.catalog_plugin_on_device_temp_mapping = dbspec
|
||||||
|
|
||||||
# Create a minimal OptionParser that we can append to
|
# Create a minimal OptionParser that we can append to
|
||||||
|
@ -2,10 +2,11 @@ __license__ = 'GPL v3'
|
|||||||
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
|
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||||
''' Code to manage ebook library'''
|
''' Code to manage ebook library'''
|
||||||
|
|
||||||
def db(path=None):
|
def db(path=None, read_only=False):
|
||||||
from calibre.library.database2 import LibraryDatabase2
|
from calibre.library.database2 import LibraryDatabase2
|
||||||
from calibre.utils.config import prefs
|
from calibre.utils.config import prefs
|
||||||
return LibraryDatabase2(path if path else prefs['library_path'])
|
return LibraryDatabase2(path if path else prefs['library_path'],
|
||||||
|
read_only=read_only)
|
||||||
|
|
||||||
|
|
||||||
def generate_test_db(library_path, # {{{
|
def generate_test_db(library_path, # {{{
|
||||||
|
@ -113,7 +113,8 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
|||||||
def exists_at(cls, path):
|
def exists_at(cls, path):
|
||||||
return path and os.path.exists(os.path.join(path, 'metadata.db'))
|
return path and os.path.exists(os.path.join(path, 'metadata.db'))
|
||||||
|
|
||||||
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):
|
||||||
self.field_metadata = FieldMetadata()
|
self.field_metadata = FieldMetadata()
|
||||||
self.dirtied_queue = Queue()
|
self.dirtied_queue = Queue()
|
||||||
if not os.path.exists(library_path):
|
if not os.path.exists(library_path):
|
||||||
@ -124,6 +125,12 @@ 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 read_only and os.path.exists(self.dbpath):
|
||||||
|
pt = PersistentTemporaryFile('_ro.db')
|
||||||
|
pt.close()
|
||||||
|
shutil.copyfile(self.dbpath, pt.name)
|
||||||
|
self.dbpath = pt.name
|
||||||
|
|
||||||
if isinstance(self.dbpath, unicode) and not iswindows:
|
if isinstance(self.dbpath, unicode) and not iswindows:
|
||||||
self.dbpath = self.dbpath.encode(filesystem_encoding)
|
self.dbpath = self.dbpath.encode(filesystem_encoding)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user