mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 10:14:46 -04:00
Changing the database path should use an already existing database at the new location if possible.
This commit is contained in:
parent
2a2f2ff2b7
commit
3d6919d73a
@ -15,6 +15,7 @@
|
|||||||
from libprs500.gui2.update import CheckForUpdates
|
from libprs500.gui2.update import CheckForUpdates
|
||||||
from libprs500 import iswindows
|
from libprs500 import iswindows
|
||||||
from libprs500 import isosx
|
from libprs500 import isosx
|
||||||
|
from libprs500.library.database import LibraryDatabase
|
||||||
|
|
||||||
import os, sys, textwrap, cStringIO, collections, traceback, shutil
|
import os, sys, textwrap, cStringIO, collections, traceback, shutil
|
||||||
|
|
||||||
@ -653,15 +654,25 @@ class Main(MainWindow, Ui_MainWindow):
|
|||||||
if os.path.dirname(self.database_path) != d.database_location:
|
if os.path.dirname(self.database_path) != d.database_location:
|
||||||
try:
|
try:
|
||||||
newloc = os.path.join(d.database_location, os.path.basename(self.database_path))
|
newloc = os.path.join(d.database_location, os.path.basename(self.database_path))
|
||||||
dest = open(newloc, 'wb')
|
if not os.path.exists(newloc):
|
||||||
self.status_bar.showMessage('Copying database to '+newloc)
|
dest = open(newloc, 'wb')
|
||||||
self.setCursor(Qt.BusyCursor)
|
self.status_bar.showMessage('Copying database to '+newloc)
|
||||||
self.library_view.setEnabled(False)
|
self.setCursor(Qt.BusyCursor)
|
||||||
self.library_view.close()
|
self.library_view.setEnabled(False)
|
||||||
src = open(self.database_path, 'rb')
|
self.library_view.close()
|
||||||
shutil.copyfileobj(src, dest)
|
src = open(self.database_path, 'rb')
|
||||||
src.close()
|
shutil.copyfileobj(src, dest)
|
||||||
dest.close()
|
src.close()
|
||||||
|
dest.close()
|
||||||
|
os.unlink(self.database_path)
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
db = LibraryDatabase(newloc)
|
||||||
|
db.close()
|
||||||
|
except Exception, err:
|
||||||
|
d = error_dialog(self, _('Invalid database'),
|
||||||
|
_('<p>An invalid database already exists at %s, delete it before trying to move the existing database.<br>Error: %s')%(newloc, str(err)))
|
||||||
|
newloc = self.database_path
|
||||||
self.database_path = newloc
|
self.database_path = newloc
|
||||||
settings = QSettings()
|
settings = QSettings()
|
||||||
settings.setValue("database path", QVariant(self.database_path))
|
settings.setValue("database path", QVariant(self.database_path))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user