commit:     137a83f50b42ab9ddd4c3c0908aadc723ce940d2
Author:     Matt Turner <mattst88 <AT> gentoo <DOT> org>
AuthorDate: Fri Apr 10 17:59:33 2020 +0000
Commit:     Matt Turner <mattst88 <AT> gentoo <DOT> org>
CommitDate: Fri Apr 10 21:03:53 2020 +0000
URL:        https://gitweb.gentoo.org/proj/catalyst.git/commit/?id=137a83f5

catalyst: Simplify countdown()

Signed-off-by: Matt Turner <mattst88 <AT> gentoo.org>

 catalyst/support.py | 26 +++++++++++---------------
 1 file changed, 11 insertions(+), 15 deletions(-)

diff --git a/catalyst/support.py b/catalyst/support.py
index eb0b7d14..c7a8fc73 100644
--- a/catalyst/support.py
+++ b/catalyst/support.py
@@ -218,23 +218,19 @@ def 
addl_arg_parse(myspec,addlargs,requiredspec,validspec):
 
 
 def countdown(secs=5, doing="Starting"):
-       # If this is non-interactive (e.g. a cronjob), then sleeping is 
pointless.
-       if not os.isatty(sys.stdin.fileno()):
+       # Don't sleep if this is non-interactive
+       if not os.isatty(sys.stdin.fileno()) or secs == 0:
                return
 
-       if secs:
-               sys.stdout.write(
-                       ('>>> Waiting %s seconds before starting...\n'
-                        '>>> (Control-C to abort)...\n'
-                        '%s in: ') % (secs, doing))
-               # py3 now creates a range object, so wrap it with list()
-               ticks=list(range(secs))
-               ticks.reverse()
-               for sec in ticks:
-                       sys.stdout.write(str(sec+1)+" ")
-                       sys.stdout.flush()
-                       time.sleep(1)
-               sys.stdout.write('\n')
+       sys.stdout.write(
+               ('>>> Waiting %s seconds before starting...\n'
+                '>>> (Control-C to abort)...\n'
+                '%s in: ') % (secs, doing))
+       for sec in reversed(range(1, secs + 1)):
+               sys.stdout.write(str(sec) + " ")
+               sys.stdout.flush()
+               time.sleep(1)
+       sys.stdout.write('\n')
 
 
 def normpath(mypath):

Reply via email to