Exemple #1
0
 def test_upgrade_17_to_latest(self):
     self.copy_and_initialize_upgrade_database('tribler_v17.sdb')
     db_migrator = DBUpgrader(self.session,
                              self.sqlitedb,
                              torrent_store=MockTorrentStore())
     db_migrator.start_migrate()
     self.assertEqual(self.sqlitedb.version, LATEST_DB_VERSION)
     self.assertFalse(
         os.path.exists(
             os.path.join(self.session.get_torrent_collecting_dir(),
                          'dir1')))
Exemple #2
0
    def test_reimport_torrents(self):
        self.copy_and_initialize_upgrade_database('tribler_v17.sdb')
        self.torrent_store = LevelDbStore(self.session.config.get_torrent_store_dir())
        db_migrator = DBUpgrader(self.session, self.sqlitedb, torrent_store=self.torrent_store)
        db_migrator.start_migrate()

        # Import a torrent
        self.torrent_store[TORRENT_UBUNTU_FILE_INFOHASH] = fix_torrent(TORRENT_UBUNTU_FILE)
        self.torrent_store.flush()

        db_migrator.reimport_torrents()

        torrent_db_handler = TorrentDBHandler(self.session)
        self.assertEqual(torrent_db_handler.getTorrentID(TORRENT_UBUNTU_FILE_INFOHASH), 3)
Exemple #3
0
    def test_reimport_torrents(self):
        self.copy_and_initialize_upgrade_database('tribler_v17.sdb')
        self.torrent_store = LevelDbStore(self.session.get_torrent_store_dir())
        db_migrator = DBUpgrader(self.session, self.sqlitedb, torrent_store=self.torrent_store)
        db_migrator.start_migrate()

        # Import a torrent
        self.torrent_store[TORRENT_FILE_INFOHASH] = fix_torrent(TORRENT_FILE)
        self.torrent_store.flush()

        db_migrator.reimport_torrents()

        torrent_db_handler = TorrentDBHandler(self.session)
        self.assertEqual(torrent_db_handler.getTorrentID(TORRENT_FILE_INFOHASH), 3)
Exemple #4
0
    def upgrade_database_to_current_version(self):
        """ Checks the database version and upgrade if it is not the latest version.
        """
        try:
            from Tribler.Core.leveldbstore import LevelDbStore
            torrent_store = LevelDbStore(self.session.config.get_torrent_store_dir())
            torrent_migrator = TorrentMigrator65(
                self.session.config.get_torrent_collecting_dir(), self.session.config.get_state_dir(),
                torrent_store=torrent_store, status_update_func=self.update_status)
            yield torrent_migrator.start_migrate()

            db_migrator = DBUpgrader(
                self.session, self.db, torrent_store=torrent_store, status_update_func=self.update_status)
            yield db_migrator.start_migrate()

            # Import all the torrent files not in the database, we do this in
            # case we have some unhandled torrent files left due to
            # bugs/crashes, etc.
            self.update_status("Recovering unregistered torrents...")
            yield db_migrator.reimport_torrents()

            yield torrent_store.close()
            del torrent_store

            self.failed = False
            self.is_done = True
        except Exception as e:
            self._logger.exception(u"failed to upgrade: %s", e)
Exemple #5
0
    def upgrade_database_to_current_version(self):
        """ Checks the database version and upgrade if it is not the latest version.
        """
        try:
            from Tribler.Core.leveldbstore import LevelDbStore
            torrent_store = LevelDbStore(
                self.session.config.get_torrent_store_dir())
            torrent_migrator = TorrentMigrator65(
                self.session.config.get_torrent_collecting_dir(),
                self.session.config.get_state_dir(),
                torrent_store=torrent_store,
                status_update_func=self.update_status)
            yield torrent_migrator.start_migrate()

            db_migrator = DBUpgrader(self.session,
                                     self.db,
                                     torrent_store=torrent_store,
                                     status_update_func=self.update_status)
            yield db_migrator.start_migrate()

            # Import all the torrent files not in the database, we do this in
            # case we have some unhandled torrent files left due to
            # bugs/crashes, etc.
            self.update_status("Recovering unregistered torrents...")
            yield db_migrator.reimport_torrents()

            yield torrent_store.close()
            del torrent_store

            self.failed = False
            self.is_done = True
        except Exception as e:
            self._logger.exception(u"failed to upgrade: %s", e)
Exemple #6
0
    def test_upgrade_17_to_latest_no_dispersy(self):
        # upgrade without dispersy DB should not raise an error
        self.copy_and_initialize_upgrade_database('tribler_v17.sdb')
        os.unlink(os.path.join(self.session.config.get_state_dir(), 'sqlite', 'dispersy.db'))
        db_migrator = DBUpgrader(self.session, self.sqlitedb, torrent_store=MockTorrentStore())
        db_migrator.start_migrate()
        self.assertEqual(self.sqlitedb.version, LATEST_DB_VERSION)

        # Check whether the torrents in the database are reindexed
        results = self.sqlitedb.fetchall("SELECT * FROM FullTextIndex")
        self.assertEqual(len(results), 1)
        self.assertTrue('test' in results[0][0])
        self.assertTrue('random' in results[0][1])
        self.assertTrue('tribler' in results[0][1])
        self.assertTrue('txt' in results[0][2])
        self.assertTrue('txt' in results[0][2])
Exemple #7
0
    def test_upgrade_17_to_latest_no_dispersy(self):
        # upgrade without dispersy DB should not raise an error
        self.copy_and_initialize_upgrade_database('tribler_v17.sdb')
        os.unlink(os.path.join(self.session.get_state_dir(), 'sqlite', 'dispersy.db'))
        db_migrator = DBUpgrader(self.session, self.sqlitedb, torrent_store=MockTorrentStore())
        db_migrator.start_migrate()
        self.assertEqual(self.sqlitedb.version, LATEST_DB_VERSION)

        # Check whether the torrents in the database are reindexed
        results = self.sqlitedb.fetchall("SELECT * FROM FullTextIndex")
        self.assertEqual(len(results), 1)
        self.assertTrue('test' in results[0][0])
        self.assertTrue('random' in results[0][1])
        self.assertTrue('tribler' in results[0][1])
        self.assertTrue('txt' in results[0][2])
        self.assertTrue('txt' in results[0][2])
Exemple #8
0
 def test_upgrade_17_to_latest(self):
     self.copy_and_initialize_upgrade_database('tribler_v17.sdb')
     db_migrator = DBUpgrader(self.session, self.sqlitedb, torrent_store=MockTorrentStore())
     db_migrator.start_migrate()
     self.assertEqual(self.sqlitedb.version, LATEST_DB_VERSION)
     self.assertFalse(os.path.exists(os.path.join(self.session.config.get_torrent_collecting_dir(), 'dir1')))