Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update scp_functions.py | Added support to display progress bar without cleaning the screen. #3247

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 5 additions & 13 deletions netmiko/scp_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,30 @@
from netmiko.scp_handler import BaseFileTransfer
from netmiko.ssh_dispatcher import FileTransfer
from netmiko.cisco.cisco_ios import InLineTransfer

import sys
if TYPE_CHECKING:
from netmiko.base_connection import BaseConnection


def progress_bar(
filename: AnyStr, size: int, sent: int, peername: Optional[str] = None
) -> None:
max_width = 50
if isinstance(filename, bytes):
filename_str = filename.decode()
else:
filename_str = filename
clear_screen = chr(27) + "[2J"
terminating_char = "|"

# Percentage done
percent_complete = sent / size
percent_str = f"{percent_complete*100:.2f}%"
hash_count = int(percent_complete * max_width)
progress = hash_count * ">"

if peername is None:
header_msg = f"Transferring file: {filename_str}\n"
header_msg = f"Transferring file: {filename_str}"
else:
header_msg = f"Transferring file to {peername}: {filename_str}\n"

msg = f"{progress:<50}{terminating_char:1} ({percent_str})"
print(clear_screen)
print(header_msg)
print(msg)
header_msg = f"Transferring file to {peername}: {filename_str}"

msg = f"({percent_str})"
sys.stdout.writelines(f"%s %s\r" % (header_msg, msg))

def verifyspace_and_transferfile(scp_transfer: BaseFileTransfer) -> None:
"""Verify space and transfer file."""
Expand Down
Loading