#427 Support both progressbar and progressbar2
Merged 5 years ago by kparal. Opened 5 years ago by frantisekz.

file modified
+12 -4
@@ -185,7 +185,12 @@ 

          else:

              widgets = [progressbar.Percentage(), progressbar.Bar(), progressbar.ETA(),

                         progressbar.FileTransferSpeed()]

-             pbar = progressbar.ProgressBar(widgets=widgets, maxval=int(total_len)).start()

+ 

+             # Determine if we are using progressbar or progressbar2

+             if hasattr(progressbar.ProgressBar(), 'max_value'):

+                 pbar = progressbar.ProgressBar(widgets=widgets, max_value=int(total_len)).start()

+             else:

+                 pbar = progressbar.ProgressBar(widgets=widgets, maxval=int(total_len)).start()

  

              read = 0

              for chunk in r.iter_content(chunk_size):
@@ -195,9 +200,12 @@ 

                      # chunk can be smaller than chunk_size (end of file) or larger than it (content

                      # decompression)

                      read += min(len(chunk), chunk_size)

-                     # don't exceed pbar.maxval, which can happen due to content decompression (see

-                     # T755). This should not occur except for the last chunk.

-                     pbar.update(min(read, pbar.maxval))

+                     # don't exceed pbar.maxval/pbar.max_value, which can happen due to content

+                     # decompression (see T755). This should not occur except for the last chunk.

+                     if hasattr(progressbar.ProgressBar(), 'max_value'):

+                         pbar.update(min(read, pbar.max_value))

+                     else:

+                         pbar.update(min(read, pbar.maxval))

  

  

  # http://stackoverflow.com/questions/11325019

These libraries are not 100% compatible, so this adds runtime
detection and adapts to support both of them.

I've tested this both with python3-progressbar.noarch 2.3-13.20170808git32422c1.fc29 and python3-progressbar2-3.39.2-2.fc30.noarch.rpm .

Commit 7204772 fixes this pull-request

Pull-Request has been merged by kparal

5 years ago

Tested, seems to work. Merged, thanks.

Metadata