From 4d4714e92c11419f4f128aeb508ab9703f1144a2 Mon Sep 17 00:00:00 2001 From: Jinsung Date: Sat, 22 Aug 2020 22:51:00 +0900 Subject: [PATCH 1/2] Add progress bar in the put method of Files class --- ampy/files.py | 10 ++++++++++ setup.py | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/ampy/files.py b/ampy/files.py index e16fa6d..01d53de 100644 --- a/ampy/files.py +++ b/ampy/files.py @@ -23,6 +23,8 @@ import textwrap import binascii +from progress.bar import Bar + from ampy.pyboard import PyboardError @@ -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('Processing', 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) @@ -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() diff --git a/setup.py b/setup.py index d572df9..20f5968 100644 --- a/setup.py +++ b/setup.py @@ -49,7 +49,7 @@ author='Adafruit Industries', author_email='circuitpython@adafruit.com', - install_requires=['click', 'pyserial', 'python-dotenv'], + install_requires=['click', 'pyserial', 'python-dotenv', 'progress'], # Choose your license license='MIT', From 823a134cc9090d7f7f87395f35e8ced8d289b031 Mon Sep 17 00:00:00 2001 From: Jinsung Date: Sun, 23 Aug 2020 16:52:35 +0900 Subject: [PATCH 2/2] Add filename when uploading a file --- ampy/files.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ampy/files.py b/ampy/files.py index 01d53de..a28277a 100644 --- a/ampy/files.py +++ b/ampy/files.py @@ -217,7 +217,7 @@ def put(self, filename, data): size = len(data) # Init bar object for visualize progress bar - bar = Bar('Processing', max=size//BUFFER_SIZE+1) + 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):