Switch to storing ebook files in the filesystem and only metadata in the database

This commit is contained in:
Kovid Goyal 2008-08-16 16:41:05 -07:00
parent c9fa1d673e
commit a33b1438e7
3 changed files with 14 additions and 10 deletions

View File

@ -13,7 +13,7 @@ RESOURCES = dict(
opf_template = '%p/ebooks/metadata/opf.xml', opf_template = '%p/ebooks/metadata/opf.xml',
ncx_template = '%p/ebooks/metadata/ncx.xml', ncx_template = '%p/ebooks/metadata/ncx.xml',
fb2_xsl = '%p/ebooks/lrf/fb2/fb2.xsl', fb2_xsl = '%p/ebooks/lrf/fb2/fb2.xsl',
metadata_sqlite = '%p/library/metadata_sqlite.sql', metadata_sqlite = '%p/library/metadata_sqlite.sql',
) )
def main(args=sys.argv): def main(args=sys.argv):
@ -41,4 +41,4 @@ def main(args=sys.argv):
return 0 return 0
if __name__ == '__main__': if __name__ == '__main__':
sys.exit(main()) sys.exit(main())

View File

@ -225,7 +225,7 @@ class Main(MainWindow, Ui_MainWindow):
pd.show() pd.show()
db.migrate_old(self.olddb, pd) db.migrate_old(self.olddb, pd)
self.olddb = None self.olddb = None
Settings().set('library path', self.library_path) prefs['library_path'] = self.library_path
self.library_view.sortByColumn(3, Qt.DescendingOrder) self.library_view.sortByColumn(3, Qt.DescendingOrder)
if not self.library_view.restore_column_widths(): if not self.library_view.restore_column_widths():
self.library_view.resizeColumnsToContents() self.library_view.resizeColumnsToContents()
@ -1106,7 +1106,7 @@ class Main(MainWindow, Ui_MainWindow):
_('<p>An invalid database already exists at %s, delete it before trying to move the existing database.<br>Error: %s')%(newloc, str(err))) _('<p>An invalid database already exists at %s, delete it before trying to move the existing database.<br>Error: %s')%(newloc, str(err)))
d.exec_() d.exec_()
self.library_path = self.library_view.model().db.library_path self.library_path = self.library_view.model().db.library_path
prefs['library path'] = self.library_path prefs['library_path'] = self.library_path
except Exception, err: except Exception, err:
traceback.print_exc() traceback.print_exc()
d = error_dialog(self, _('Could not move database'), unicode(err)) d = error_dialog(self, _('Could not move database'), unicode(err))
@ -1204,31 +1204,33 @@ class Main(MainWindow, Ui_MainWindow):
def initialize_database(self): def initialize_database(self):
self.library_path = prefs['library path'] self.library_path = prefs['library_path']
self.olddb = None self.olddb = None
if self.library_path is None: # Need to migrate to new database layout if self.library_path is None: # Need to migrate to new database layout
self.database_path = prefs['database_path'] self.database_path = prefs['database_path']
if not os.access(os.path.dirname(self.database_path), os.W_OK): if not os.access(os.path.dirname(self.database_path), os.W_OK):
error_dialog(self, _('Database does not exist'), _('The directory in which the database should be: %s no longer exists. Please choose a new database location.')%self.database_path).exec_() error_dialog(self, _('Database does not exist'),
self.database_path = choose_dir(self, 'database path dialog', 'Choose new location for database') _('The directory in which the database should be: %s no longer exists. Please choose a new database location.')%self.database_path).exec_()
self.database_path = choose_dir(self, 'database path dialog',
_('Choose new location for database'))
if not self.database_path: if not self.database_path:
self.database_path = os.path.expanduser('~').decode(sys.getfilesystemencoding()) self.database_path = os.path.expanduser('~').decode(sys.getfilesystemencoding())
if not os.path.exists(self.database_path): if not os.path.exists(self.database_path):
os.makedirs(self.database_path) os.makedirs(self.database_path)
self.database_path = os.path.join(self.database_path, 'library1.db') self.database_path = os.path.join(self.database_path, 'library1.db')
settings.set('database path', self.database_path) prefs['database_path'] = self.database_path
home = os.path.dirname(self.database_path) home = os.path.dirname(self.database_path)
if not os.path.exists(home): if not os.path.exists(home):
home = os.getcwd() home = os.getcwd()
from PyQt4.QtGui import QFileDialog from PyQt4.QtGui import QFileDialog
dir = qstring_to_unicode(QFileDialog.getExistingDirectory(self, _('Choose a location for your ebook library.'), home)) dir = unicode(QFileDialog.getExistingDirectory(self,
_('Choose a location for your ebook library.'), home))
if not dir: if not dir:
dir = os.path.dirname(self.database_path) dir = os.path.dirname(self.database_path)
self.library_path = os.path.abspath(dir) self.library_path = os.path.abspath(dir)
self.olddb = LibraryDatabase(self.database_path) self.olddb = LibraryDatabase(self.database_path)
def read_settings(self): def read_settings(self):
self.initialize_database() self.initialize_database()
geometry = config['main_window_geometry'] geometry = config['main_window_geometry']

View File

@ -451,6 +451,8 @@ def _prefs():
help=_('Access key for isbndb.com')) help=_('Access key for isbndb.com'))
c.add_opt('network_timeout', default=5, c.add_opt('network_timeout', default=5,
help=_('Default timeout for network operations (seconds)')) help=_('Default timeout for network operations (seconds)'))
c.add_opt('library_path', default=None,
help=_('Path to directory in which your library of books is stored'))
c.add_opt('migrated', default=False, help='For Internal use. Don\'t modify.') c.add_opt('migrated', default=False, help='For Internal use. Don\'t modify.')
return c return c