def subcommand_resume(api: API, gids: List[str] = None, do_all: bool = False) -> int: """ Resume subcommand. Arguments: api: The API instance to use. gids: The GIDs of the downloads to resume. do_all: Pause all downloads if True. Returns: int: 0 if all success, 1 if one failure. """ if do_all: if api.resume_all(): return 0 return 1 try: downloads = api.get_downloads(gids) except ClientException as error: print(str(error), file=sys.stderr) return 1 result = api.resume(downloads) if all(result): return 0 for item in result: if isinstance(item, ClientException): print(item, file=sys.stderr) return 1
def remove(api: API, gids: List[str] = None, do_all: bool = False, force: bool = False) -> int: """ Remove subcommand. Arguments: api: The API instance to use. gids: The GIDs of the downloads to remove. do_all: Pause all downloads if True. force: Force pause or not (see API.remove). Returns: int: 0 if all success, 1 if one failure. """ if do_all: if api.remove_all(): return 0 return 1 try: downloads = api.get_downloads(gids) except ClientException as error: print(str(error), file=sys.stderr) return 1 ok = True result = api.remove(downloads, force=force) if all(result): return 0 if ok else 1 for item in result: if isinstance(item, ClientException): print(item, file=sys.stderr) return 1
def subcommand_show(api: API) -> int: """ Show subcommand. Arguments: api: The API instance to use. Returns: int: Always 0. """ downloads = api.get_downloads() def print_line(*args): # noqa: WPS430 (nested function) print("{:<17} {:<9} {:>8} {:>12} {:>12} {:>8} {}".format( *args)) # noqa: P101 (unindexed params) print_line("GID", "STATUS", "PROGRESS", "DOWN_SPEED", "UP_SPEED", "ETA", "NAME") for download in downloads: print_line( download.gid, download.status, download.progress_string(), download.download_speed_string(), download.upload_speed_string(), download.eta_string(), download.name, ) return 0