Esempio n. 1
0
def move_library(oldloc, newloc, parent, callback_on_complete):
    from calibre.db.legacy import LibraryDatabase
    callback = Callback(callback_on_complete)
    try:
        if not os.path.exists(os.path.join(newloc, 'metadata.db')):
            if oldloc and os.access(os.path.join(oldloc, 'metadata.db'),
                                    os.R_OK):
                # Move old library to new location
                try:
                    db = LibraryDatabase(oldloc)
                except:
                    return move_library(None, newloc, parent, callback)
                else:
                    rq = Queue()
                    m = MoveLibrary(oldloc, newloc,
                                    len(db.get_top_level_move_items()[0]), rq)
                    global _mm
                    _mm = MoveMonitor(m, rq, callback, parent)
                    return
            else:
                # Create new library at new location
                db = LibraryDatabase(newloc)
                callback(newloc)
                return

        # Try to load existing library at new location
        try:
            LibraryDatabase(newloc)
        except Exception as err:
            det = traceback.format_exc()
            error_dialog(parent,
                         _('Invalid database'),
                         _('<p>An invalid library already exists at '
                           '%(loc)s, delete it before trying to move the '
                           'existing library.<br>Error: %(err)s') %
                         dict(loc=newloc, err=str(err)),
                         det,
                         show=True)
            callback(None)
            return
        else:
            callback(newloc)
            return
    except Exception as err:
        det = traceback.format_exc()
        error_dialog(parent,
                     _('Could not move library'),
                     unicode(err),
                     det,
                     show=True)
    callback(None)
Esempio n. 2
0
def move_library(oldloc, newloc, parent, callback_on_complete):
    from calibre.db.legacy import LibraryDatabase
    callback = Callback(callback_on_complete)
    try:
        if not os.path.exists(os.path.join(newloc, 'metadata.db')):
            if oldloc and os.access(os.path.join(oldloc, 'metadata.db'), os.R_OK):
                # Move old library to new location
                try:
                    db = LibraryDatabase(oldloc)
                except:
                    return move_library(None, newloc, parent,
                        callback)
                else:
                    rq = Queue()
                    m = MoveLibrary(oldloc, newloc,
                            len(db.get_top_level_move_items()[0]), rq)
                    global _mm
                    _mm = MoveMonitor(m, rq, callback, parent)
                    return
            else:
                # Create new library at new location
                db = LibraryDatabase(newloc)
                callback(newloc)
                return

        # Try to load existing library at new location
        try:
            LibraryDatabase(newloc)
        except Exception as err:
            det = traceback.format_exc()
            error_dialog(parent, _('Invalid database'),
                _('<p>An invalid library already exists at '
                    '%(loc)s, delete it before trying to move the '
                    'existing library.<br>Error: %(err)s')%dict(loc=newloc,
                        err=str(err)), det, show=True)
            callback(None)
            return
        else:
            callback(newloc)
            return
    except Exception as err:
        det = traceback.format_exc()
        error_dialog(parent, _('Could not move library'),
                unicode(err), det, show=True)
    callback(None)