def run(self): self.current_status = u"Checking Tribler version..." failed, has_to_upgrade = self.check_should_upgrade() if has_to_upgrade and not failed: self.notify_starting() self.upgrade_database_to_current_version() # Convert old (pre 6.3 Tribler) pickle files to the newer .state format pickle_converter = PickleConverter(self.session) pickle_converter.convert() if self.failed: self.notify_starting() self.stash_database()
def test_convert_session_config(self): old_pickle_dict = { "state_dir": "/", "mainline_dht_port": 1337, "torrent_checking": "false", "torrent_collecting": "true", "libtorrent": False, "dispersy_port": 1337, "minport": 1234 } self.write_pickle_file(old_pickle_dict, "sessconfig.pickle") PickleConverter(self.mock_session).convert_session_config() self.assertTrue( os.path.exists( os.path.join(self.session_base_dir, TRIBLER_CONFIG_FILENAME))) self.assertFalse( os.path.exists( os.path.join(self.session_base_dir, "sessconfig.pickle"))) # Check the content of the config file config = TriblerConfig.load(config_path=os.path.join( self.session_base_dir, TRIBLER_CONFIG_FILENAME)) self.assertEqual(config.get_state_dir(), '/') self.assertEqual(config.get_mainline_dht_port(), 1337) self.assertEqual(config.get_torrent_checking_enabled(), False) self.assertEqual(config.get_torrent_collecting_enabled(), True) self.assertFalse(config.get_libtorrent_enabled()) self.assertEqual(config.get_dispersy_port(), 1337) self.assertEqual(config.get_libtorrent_port(), 1234)
def test_convert_default_download_config(self): old_pickle_dict = {"saveas": "dunno", "max_upload_rate": 33, "unrelatedkey": "test"} self.write_pickle_file(old_pickle_dict, "dlconfig.pickle") PickleConverter(self.mock_session).convert_default_download_config() self.assertTrue(os.path.exists(get_default_dscfg_filename(self.session_base_dir)))
def test_convert_session_config(self): old_pickle_dict = {"state_dir": "/", "mainline_dht_port": 1337, "torrent_checking": "maybe", "torrent_collecting": "maybe", "libtorrent": 1337, "dispersy_port": 1337} self.write_pickle_file(old_pickle_dict, "sessconfig.pickle") PickleConverter(self.mock_session).convert_session_config() self.assertTrue(os.path.exists(SessionConfigInterface.get_default_config_filename(self.session_base_dir))) self.assertFalse(os.path.exists(os.path.join(self.session_base_dir, "sessconfig.pickle")))
def test_convert_download_checkpoints(self): with open(os.path.join(self.session_base_dir, 'corrupt.pickle'), 'wb') as corrupt_file: corrupt_file.write("This is not a pickle file!") old_pickle_dict = {"dlconfig": {"saveas": "dunno", "abc": "def"}, "engineresumedata": "test", "dlstate": "test", "metainfo": "none"} self.write_pickle_file(old_pickle_dict, "download.pickle") PickleConverter(self.mock_session).convert_download_checkpoints() self.assertTrue(os.path.exists(os.path.join(self.session_base_dir, 'download.state'))) self.assertFalse(os.path.exists(os.path.join(self.session_base_dir, 'corrupt.pickle')))
def test_convert_main_config(self): pickle_dict = {"download_state": {"abc": "stop"}} self.write_pickle_file(pickle_dict, "user_download_choice.pickle") PickleConverter(self.mock_session).convert_main_config() self.assertFalse( os.path.exists( os.path.join(self.session_base_dir, "user_download_choice.pickle"))) self.assertTrue( os.path.exists( os.path.join(self.session_base_dir, TRIBLER_CONFIG_FILENAME)))
def run(self): """ Run the upgrader if it is enabled in the config. Note that by default, upgrading is enabled in the config. It is then disabled after upgrading to Tribler 7. """ self.current_status = u"Checking Tribler version..." failed, has_to_upgrade = self.check_should_upgrade_database() if has_to_upgrade and not failed: self.notify_starting() self.upgrade_database_to_current_version() # Convert old (pre 6.3 Tribler) pickle files to the newer .state format pickle_converter = PickleConverter(self.session) pickle_converter.convert() if self.failed: self.notify_starting() self.stash_database() self.upgrade_to_tribler7()
def test_convert_main_config(self): pickle_dict = {"download_state": {"abc": "stop"}} self.write_pickle_file(pickle_dict, "user_download_choice.pickle") conf_filepath = os.path.join(self.session_base_dir, 'abc.conf') with open(conf_filepath, 'wb') as conf_file: conf_file.write("[ABC]") gui_filepath = os.path.join(self.session_base_dir, 'gui_settings') with open(gui_filepath, 'wb') as gui_settings_file: gui_settings_file.write("a=b\nc=d") history_filepath = os.path.join(self.session_base_dir, 'recent_download_history') with open(history_filepath, 'wb') as history_file: history_file.write("a=b\nc=d\ne=\n") PickleConverter(self.mock_session).convert_main_config() self.assertFalse(os.path.exists(os.path.join(self.session_base_dir, "user_download_choice.pickle"))) self.assertFalse(os.path.exists(conf_filepath)) self.assertFalse(os.path.exists(gui_filepath)) self.assertFalse(os.path.exists(history_filepath)) self.assertTrue(os.path.exists(os.path.join(self.session_base_dir, "tribler.conf")))