def _create_torrent_thread( self, path, tracker, piece_length, comment, target, webseeds, private, created_by, trackers, add_to_session, ): from deluge import metafile metafile.make_meta_file( path, tracker, piece_length, comment=comment, target=target, webseeds=webseeds, private=private, created_by=created_by, trackers=trackers, ) log.debug('torrent created!') if add_to_session: options = {} options['download_location'] = os.path.split(path)[0] with open(target, 'rb') as _file: filedump = b64encode(_file.read()) self.add_torrent_file( os.path.split(target)[1], filedump, options)
def test_save_singlefile(self): tmp_path = tempfile.mkstemp('testdata')[1] with open(tmp_path, 'wb') as tmp_file: tmp_file.write('a' * (2314 * 1024)) tmp_fd, tmp_file = tempfile.mkstemp('.torrent') metafile.make_meta_file(tmp_path, '', 32768, target=tmp_file) check_torrent(tmp_file) os.remove(tmp_path) os.close(tmp_fd) os.remove(tmp_file)
def test_save_singlefile(self): if windows_check(): raise unittest.SkipTest('on windows \\ != / for path names') tmp_path = tempfile.mkstemp('testdata')[1] with open(tmp_path, 'wb') as tmp_file: tmp_file.write(b'a' * (2314 * 1024)) tmp_fd, tmp_file = tempfile.mkstemp('.torrent') metafile.make_meta_file(tmp_path, '', 32768, target=tmp_file) check_torrent(tmp_file) os.remove(tmp_path) os.close(tmp_fd) os.remove(tmp_file)
def _create_torrent_thread(self, path, tracker, piece_length, comment, target, webseeds, private, created_by, trackers, add_to_session): from deluge import metafile metafile.make_meta_file( path, tracker, piece_length, comment=comment, target=target, webseeds=webseeds, private=private, created_by=created_by, trackers=trackers) log.debug('torrent created!') if add_to_session: options = {} options['download_location'] = os.path.split(path)[0] with open(target, 'rb') as _file: filedump = base64.encodestring(_file.read()) self.add_torrent_file(os.path.split(target)[1], filedump, options)
def test_save_multifile(self): # Create a temporary folder for torrent creation tmp_path = tempfile.mkdtemp() with open(os.path.join(tmp_path, 'file_A'), 'wb') as tmp_file: tmp_file.write('a' * (312 * 1024)) with open(os.path.join(tmp_path, 'file_B'), 'wb') as tmp_file: tmp_file.write('b' * (2354 * 1024)) with open(os.path.join(tmp_path, 'file_C'), 'wb') as tmp_file: tmp_file.write('c' * (11 * 1024)) tmp_fd, tmp_file = tempfile.mkstemp('.torrent') metafile.make_meta_file(tmp_path, '', 32768, target=tmp_file) check_torrent(tmp_file) os.remove(os.path.join(tmp_path, 'file_A')) os.remove(os.path.join(tmp_path, 'file_B')) os.remove(os.path.join(tmp_path, 'file_C')) os.rmdir(tmp_path) os.close(tmp_fd) os.remove(tmp_file)