Skip to content

Commit

Permalink
Apply format
Browse files Browse the repository at this point in the history
  • Loading branch information
wkentaro committed May 12, 2024
1 parent b51b6c4 commit fc243a7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 24 deletions.
9 changes: 3 additions & 6 deletions gdown/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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,
Expand Down
17 changes: 4 additions & 13 deletions gdown/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from .parse_url import parse_url

CHUNK_SIZE = 512 * 1024 # 512KB
TEMPFILE_SUFFIX = ".part"
home = osp.expanduser("~")


Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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),
)
Expand Down
9 changes: 4 additions & 5 deletions gdown/download_folder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit fc243a7

Please sign in to comment.