async def check_daemon_absence(): try: async with ControlClient(): pass except RuntimeError: pass else: raise exceptions.CoreError("torrent daemon", 'A daemon on this port is already running')
async def _status(future, verbose=True): async with ControlClient() as client: torrent_states = await client.execute(_status_server_handler) future.set_result([ formatters.join_lines( formatters.format_title(state, verbose) + formatters.format_status(state, verbose)) for state in torrent_states ])
async def _add(filename, download_dir=None, files=None, mode=None): tf = TorrentInfo.from_file(filename, download_dir=download_dir) if mode: if tf.download_info.single_file_mode: raise exceptions.CoreError( "torrent addition", "Can't select files in a single-file torrent") files = [PATH_SPLIT_RE.split(path) for path in files] tf.download_info.select_files(files, mode) async with ControlClient() as client: await client.execute(partial(ControlManager.add, torrent_info=tf))
async def _set_state(filenames, state): assert isinstance(filenames, list) state = getattr(ControlManager, state) torrents = [ TorrentInfo.from_file(filename, download_dir=None) for filename in filenames ] # FIXME: Execute action with all torrents if torrents == [] async with ControlClient() as client: for info in torrents: await client.execute( partial(state, info_hash=info.download_info.info_hash))
async def _stop(): async with ControlClient() as client: with suppress(DaemonExit): await client.execute(_stop_server_handler)