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

plumbum.cli.progress.Progress incompatible with python 2.6 #230

Closed
unux opened this issue Oct 19, 2015 · 4 comments
Closed

plumbum.cli.progress.Progress incompatible with python 2.6 #230

unux opened this issue Oct 19, 2015 · 4 comments
Milestone

Comments

@unux
Copy link

unux commented Oct 19, 2015

Here is a small patch that I applied to allow Progress to work with Python 2.6. There were two incompatibilities:.

  • datetime.timedelta doesn't handle automatic int division
  • print function doesn't support the flush argument.
--- plumbum/cli/progress.py 2015-10-19 09:56:17.000000000 -0600
+++ plumbum_py2.6/plumbum/cli/progress.py   2015-10-19 09:51:11.000000000 -0600
@@ -8,6 +8,7 @@
 import datetime
 from plumbum.lib import six
 from plumbum.cli.termsize import get_terminal_size
+import sys

 class ProgressBase(six.ABC):
     """Base class for progress bars. Customize for types of progress bars.
@@ -81,7 +82,7 @@
         if self.value < 1:
             return None, None
         elapsed_time = datetime.datetime.now() - self._start_time
-        time_each = elapsed_time / self.value
+        time_each = elapsed_time.seconds / self.value
         time_remaining = time_each * (self.length - self.value)
         return elapsed_time, time_remaining

@@ -151,7 +152,8 @@
             print(disptxt)
         else:
             print("\r", end='')
-            print(disptxt, end='', flush=True)
+            print(disptxt, end='')
+            sys.stdout.flush()


 class ProgressIPy(ProgressBase):
@henryiii
Copy link
Collaborator

Feel free to submit a pull request next time, that way you'll get the credit a little more directly. I'll go ahead and apply the patch.

@henryiii
Copy link
Collaborator

Fixed. Thanks! Changed the .seconds to use .days and .microseconds too, since those are not included.

@henryiii henryiii added this to the v1.6.1 milestone Oct 19, 2015
@henryiii
Copy link
Collaborator

Sorry, I tried to credit you in the commit, but my Mac decided to auto correct to unix.

@unux
Copy link
Author

unux commented Oct 19, 2015

Its fine thanks.

I'm not working on my home system or I'd have just submitted a merge request anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants