Commit 4e11acc4 authored by Marcel Hellkamp's avatar Marcel Hellkamp
Browse files

Made "get -f" to disable the "No binary data to terminal" save guard.

parent 61d82eee
"""
Get (download) a single file from an archive.
Download a single file from an archive.
"""
import os
import sys
from pycdstar3.cli._utils import hbytes
from pycdstar3.cli import CliError
from pycdstar3.cli._utils import hbytes
def register(subparsers):
......@@ -16,7 +16,8 @@ def register(subparsers):
help="If a <DST>.part file exists, try to resume an"
" interrupted download. Also, keep the *.part file"
" on any errors.")
parser.add_argument("-f", "--force", action="store_true", help="Overwrite local files without asking")
parser.add_argument("-f", "--force", action="store_true",
help="Overwrite local files or print binary data to a terminal.")
parser.add_argument("ARCHIVE", help="Archive ID")
parser.add_argument("FILE", help="File Name")
parser.add_argument("DST", nargs="?", help="Destination filename, directory or '-' for stdout. (default: '-')")
......@@ -64,12 +65,12 @@ def get(ctx, args): # noqa: C901
try:
dl = client.get_file(vault, archive, file, offset=offset)
if ispipe and out.isatty() and not dl.type.startswith("text/"):
raise CliError("Not printing binary data ({}) a terminal".format(dl.type))
if ispipe and out.isatty() and not dl.type.startswith("text/") and not force:
raise CliError("Not printing binary data ({}) to a terminal. Use --force to override.".format(dl.type))
if progress and not ctx.print.quiet:
from tqdm import tqdm
pbar = tqdm(total=dl.size+offset, initial=offset, unit='b', unit_scale=True, unit_divisor=1024,
pbar = tqdm(total=dl.size + offset, initial=offset, unit='b', unit_scale=True, unit_divisor=1024,
dynamic_ncols=True, file=ctx.print.file)
def write(chunk):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment