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

Add progress bar in the put method of Files class #93

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
10 changes: 10 additions & 0 deletions ampy/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import textwrap
import binascii

from progress.bar import Bar

from ampy.pyboard import PyboardError


Expand Down Expand Up @@ -213,6 +215,10 @@ def put(self, filename, data):
self._pyboard.enter_raw_repl()
self._pyboard.exec_("f = open('{0}', 'wb')".format(filename))
size = len(data)

# Init bar object for visualize progress bar
bar = Bar('Uploading: ' + filename, max=size//BUFFER_SIZE+1)

# Loop through and write a buffer size chunk of data at a time.
for i in range(0, size, BUFFER_SIZE):
chunk_size = min(BUFFER_SIZE, size - i)
Expand All @@ -221,6 +227,10 @@ def put(self, filename, data):
if not chunk.startswith("b"):
chunk = "b" + chunk
self._pyboard.exec_("f.write({0})".format(chunk))

bar.next()

bar.finish()
self._pyboard.exec_("f.close()")
self._pyboard.exit_raw_repl()

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
author='Adafruit Industries',
author_email='[email protected]',

install_requires=['click', 'pyserial', 'python-dotenv'],
install_requires=['click', 'pyserial', 'python-dotenv', 'progress'],

# Choose your license
license='MIT',
Expand Down