async def add_handler(args): torrents = [TorrentInfo.from_file(filename, download_dir=args.download_dir) for filename in args.filenames] if args.include: paths = args.include mode = 'whitelist' elif args.exclude: paths = args.exclude mode = 'blacklist' else: paths = None mode = None if mode is not None: if len(torrents) > 1: raise ValueError('Can\'t handle "--include" and "--exclude" when several files are added') torrent_info = torrents[0] if torrent_info.download_info.single_file_mode: raise ValueError("Can't select files in a single-file torrent") paths = [PATH_SPLIT_RE.split(path) for path in paths] torrent_info.download_info.select_files(paths, mode) async with ControlClient() as client: for info in torrents: await client.execute(partial(ControlManager.add, torrent_info=info))
async def check_daemon_absence(): try: async with ControlClient(): pass except RuntimeError: pass else: raise RuntimeError('The daemon is already running')
async def control_action_handler(args): action = getattr(ControlManager, args.action) torrents = [TorrentInfo.from_file(filename, download_dir=None) for filename in args.filenames] # FIXME: Execute action with all torrents if torrents == [] async with ControlClient() as client: for info in torrents: await client.execute(partial(action, info_hash=info.download_info.info_hash))
async def status_handler(args): async with ControlClient() as client: torrent_states = await client.execute(status_server_handler) paragraphs = [formatters.join_lines(formatters.format_title(state, args.verbose) + formatters.format_status(state, args.verbose)) for state in torrent_states] print('\n'.join(paragraphs).rstrip())
async def find_another_daemon(filenames: List[str]) -> bool: try: async with ControlClient() as client: if filenames: await client.execute(partial(suggest_torrents, filenames=filenames)) return True except RuntimeError: return False
async def resume_torrent(paths, download_dir): torrents = map( lambda path: TorrentInfo.from_file(path, download_dir=download_dir), paths) async with ControlClient() as client: for info in torrents: await client.execute(partial( ControlManager.resume, info_hash=info.download_info.info_hash))
async def add_torrent(paths, download_dir): print("starting add_torrent... paths: {}".format(paths)) torrents = list( map( lambda path: TorrentInfo.from_file(path, download_dir=download_dir ), paths)) print("finished maping torrents... {}".format(torrents)) async with ControlClient() as client: print("In async function...") for info in torrents: print("awaiting execution of 'Controlmanager.add'" ) #TOFIX Tuple error in here! await client.execute(partial(ControlManager.add, torrent_info=info))
async def stop_handler(_): async with ControlClient() as client: with suppress(DaemonExit): await client.execute(stop_server_handler)
async def add_torrent(paths, download_dir): torrents = [TorrentInfo.from_file(path, download_dir=download_dir) for path in paths] async with ControlClient() as client: for info in torrents: await client.execute(partial(ControlManager.add, torrent_info=info))