From fc243a7d6d6540ca1a08161eadd2544dba495713 Mon Sep 17 00:00:00 2001 From: Kentaro Wada Date: Sun, 12 May 2024 15:21:41 +0900 Subject: [PATCH] Apply format --- gdown/__main__.py | 9 +++------ gdown/download.py | 17 ++++------------- gdown/download_folder.py | 9 ++++----- 3 files changed, 11 insertions(+), 24 deletions(-) diff --git a/gdown/__main__.py b/gdown/__main__.py index e53368eb..1220bfcb 100644 --- a/gdown/__main__.py +++ b/gdown/__main__.py @@ -106,11 +106,8 @@ def main(): "-c", dest="continue_", action="store_true", - help=( - "resume getting partially-downloaded files " - "from their download tempfile, " - "and skip fully transferred files" - ), + help="resume getting partially-downloaded files while " + "skipping fully downloaded ones", ) parser.add_argument( "--folder", @@ -200,7 +197,7 @@ def main(): sys.exit(1) except requests.exceptions.ProxyError as e: print( - "Failed to use proxy:\n\n{}\n\n" "Please check your proxy settings.".format( + "Failed to use proxy:\n\n{}\n\nPlease check your proxy settings.".format( indent("\n".join(textwrap.wrap(str(e))), prefix="\t") ), file=sys.stderr, diff --git a/gdown/download.py b/gdown/download.py index e57c9eb1..cd242f15 100644 --- a/gdown/download.py +++ b/gdown/download.py @@ -19,7 +19,6 @@ from .parse_url import parse_url CHUNK_SIZE = 512 * 1024 # 512KB -TEMPFILE_SUFFIX = ".part" home = osp.expanduser("~") @@ -153,9 +152,7 @@ def download( fuzzy: bool Fuzzy extraction of Google Drive's file Id. Default is False. resume: bool - Resume interrupted transfers. - Completed output files will be skipped. - Partial tempfiles will be reused, if the transfer is incomplete. + Resume interrupted downloads while skipping completed ones. Default is False. format: str, optional Format of Google Docs, Spreadsheets and Slides. Default is: @@ -298,19 +295,14 @@ def download( output = osp.join(output, filename_from_url) if output_is_path: - - # Shortcut any 100% transfers to avoid excessive GETs, - # when it's reasonable to assume that gdown would've been - # using tempfiles and atomic renames before. if resume and os.path.isfile(output): if not quiet: - print(f"resume: already have {output}") + print(f"Skipping already downloaded file {output}", file=sys.stderr) return output - # Alternatively, resume mode can reuse partial tmp_files. existing_tmp_files = [] for file in os.listdir(osp.dirname(output) or "."): - if file.startswith(osp.basename(output)) and file.endswith(TEMPFILE_SUFFIX): + if file.startswith(osp.basename(output)): existing_tmp_files.append(osp.join(osp.dirname(output), file)) if resume and existing_tmp_files: if len(existing_tmp_files) != 1: @@ -328,13 +320,12 @@ def download( ) return tmp_file = existing_tmp_files[0] - # Perhaps it should select the biggest one? else: resume = False # mkstemp is preferred, but does not work on Windows # https://github.com/wkentaro/gdown/issues/153 tmp_file = tempfile.mktemp( - suffix=TEMPFILE_SUFFIX, + suffix=tempfile.template, prefix=osp.basename(output), dir=osp.dirname(output), ) diff --git a/gdown/download_folder.py b/gdown/download_folder.py index 6d9a63af..8c59c96d 100644 --- a/gdown/download_folder.py +++ b/gdown/download_folder.py @@ -313,13 +313,12 @@ def download_folder( GoogleDriveFileToDownload(id=id, path=path, local_path=local_path) ) else: - # Shortcut existing 100% transfers here, - # instead of invoking download(), - # to avoid making unnecessary requests. if resume and os.path.isfile(local_path): - # already downloaded this file if not quiet: - print(f"resume: already have {local_path}") + print( + f"Skipping already downloaded file {local_path}", + file=sys.stderr, + ) files.append(local_path) continue