def create_torrents(): try: if self.combineRadio.GetValue(): params['name'] = self.specifiedName.GetValue() create_torrent_file(self.selectedPaths, params, self._torrentCreated) else: for path in self.selectedPaths: if os.path.isfile(path): create_torrent_file([path], params, self._torrentCreated) except: print_exc() wx.CallAfter(do_gui)
def create_torrents(): try: if self.combineRadio.GetValue(): params['name'] = self.specifiedName.GetValue() create_torrent_file(self.selectedPaths, params, self._torrentCreated) else: for path in self.selectedPaths: if os.path.isfile(path): create_torrent_file([path], params, self._torrentCreated) except: print_exc() wx.CallAfter(do_gui)
def test_create_torrent_two_files(self): file_path_list = [ os.path.join(self.TORRENT_DATA_DIR, self.FILE1_NAME), os.path.join(self.TORRENT_DATA_DIR, self.FILE2_NAME) ] result = create_torrent_file(file_path_list, self.get_params()) self.assertTrue(result["success"])
def save(self, torrent_filepath=None): """ Generate the metainfo and save the torrent file. :param torrent_filepath: An optional absolute path to where to save the generated .torrent file. """ torrent_dict = create_torrent_file(self.files_list, self.torrent_parameters, torrent_filepath=torrent_filepath) self.metainfo = bdecode(torrent_dict['metainfo']) self.copy_metainfo_to_torrent_parameters() self.infohash = torrent_dict['infohash']
def save(self, torrent_filepath=None): """ Generate the metainfo and save the torrent file. :param torrent_filepath: An optional absolute path to where to save the generated .torrent file. """ torrent_dict = create_torrent_file(self.files_list, self.torrent_parameters, torrent_filepath=torrent_filepath) self.metainfo = bdecode(torrent_dict['metainfo']) self.copy_metainfo_to_torrent_parameters() self.infohash = torrent_dict['infohash']
def test_create_torrent(self): """ Tests the create_torrent_file() function. """ def on_torrent_created(result): # start a libtorrent session to check if the file is correct lt_session = libtorrent.session() p = {'save_path': self._temp_dir, 'ti': libtorrent.torrent_info(result['torrent_file_path'])} handle = lt_session.add_torrent(p) # check progress time.sleep(1) assert handle.status().progress == 1.0, \ "The created torrent seems to be incorrect: progress = %s" % handle.status().progress # cleanup libtorrent session lt_session.remove_torrent(handle) del lt_session params = {'': ''} create_torrent_file([self._test_torrent_path], params, callback=on_torrent_created)
def test_create_torrent(self): """ Tests the create_torrent_file() function. """ def _on_torrent_created(result): # start a libtorrent session to check if the file is correct lt_session = libtorrent.session() p = {'save_path': self._temp_dir, 'ti': libtorrent.torrent_info(result['torrent_file_path'])} handle = lt_session.add_torrent(p) # if handle.is_valid() returns false, the created torrent file is invalid self.assertTrue(handle.is_valid()) # cleanup libtorrent session lt_session.remove_torrent(handle) del lt_session params = {} result = create_torrent_file([self._test_torrent_path], params) _on_torrent_created(result)
def test_create_torrent(self): """ Tests the create_torrent_file() function. """ def _on_torrent_created(result): # start a libtorrent session to check if the file is correct lt_session = libtorrent.session() p = { 'save_path': self._temp_dir, 'ti': libtorrent.torrent_info(result['torrent_file_path']) } handle = lt_session.add_torrent(p) # if handle.is_valid() returns false, the created torrent file is invalid self.assertTrue(handle.is_valid()) # cleanup libtorrent session lt_session.remove_torrent(handle) del lt_session params = {} result = create_torrent_file([self._test_torrent_path], params) _on_torrent_created(result)
def test_create_torrent_two_files(self): file_path_list = [os.path.join(self.TORRENT_DATA_DIR, self.FILE1_NAME), os.path.join(self.TORRENT_DATA_DIR, self.FILE2_NAME)] result = create_torrent_file(file_path_list, self.get_params()) self.assertTrue(os.path.isfile(result["torrent_file_path"])) os.remove(result["torrent_file_path"])
def test_create_torrent_one_file(self): result = create_torrent_file( [os.path.join(self.TORRENT_DATA_DIR, self.FILE1_NAME)], self.get_params()) self.created_torrent_one_file(result)
def test_create_torrent_one_file_2(self): result = create_torrent_file([os.path.join(self.TORRENT_DATA_DIR, self.FILE2_NAME)], {}) self.assertTrue(os.path.isfile(result["torrent_file_path"])) os.remove(result["torrent_file_path"])
def test_create_torrent_with_nodes(self): params = self.get_params() params["nodes"] = [("127.0.0.1", 1234)] result = create_torrent_file([os.path.join(self.TORRENT_DATA_DIR, self.FILE1_NAME)], params) self.created_torrent_one_file(result)
def test_create_torrent_one_file(self): result = create_torrent_file([os.path.join(self.TORRENT_DATA_DIR, self.FILE1_NAME)], self.get_params()) self.created_torrent_one_file(result)
def test_create_torrent_one_file_2(self): create_torrent_file([os.path.join(self.TORRENT_DATA_DIR, self.FILE2_NAME)], {})
def test_create_torrent_with_nodes(self): params = self.get_params() params["nodes"] = [("127.0.0.1", 1234)] result = create_torrent_file( [os.path.join(self.TORRENT_DATA_DIR, self.FILE1_NAME)], params) self.created_torrent_one_file(result)
def test_create_torrent_one_file_2(self): result = create_torrent_file( [os.path.join(self.TORRENT_DATA_DIR, self.FILE2_NAME)], {}) self.verify_created_torrent(result)
def test_create_torrent_two_files(self): file_path_list = [os.path.join(self.TORRENT_DATA_DIR, self.FILE1_NAME), os.path.join(self.TORRENT_DATA_DIR, self.FILE2_NAME)] create_torrent_file(file_path_list, self.get_params()) self.assertTrue(os.path.isfile(os.path.abspath(os.path.join(self.TORRENT_DATA_DIR, u"torrent_creation_files.torrent")))) os.remove(os.path.abspath(os.path.join(self.TORRENT_DATA_DIR, u"torrent_creation_files.torrent")))
def test_create_torrent_one_file_2(self): result = create_torrent_file( [os.path.join(self.TORRENT_DATA_DIR, self.FILE2_NAME)], {}) self.assertTrue(os.path.isfile(result["torrent_file_path"])) os.remove(result["torrent_file_path"])
def test_create_torrent_one_file_2(self): result = create_torrent_file([os.path.join(self.TORRENT_DATA_DIR, self.FILE2_NAME)], {}) self.verify_created_torrent(result)