From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 80630138350 for ; Fri, 10 Apr 2020 21:04:44 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id CFB6AE0ACA; Fri, 10 Apr 2020 21:04:42 +0000 (UTC) Received: from smtp.gentoo.org (mail.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id B77F7E0ACA for ; Fri, 10 Apr 2020 21:04:42 +0000 (UTC) Received: from oystercatcher.gentoo.org (unknown [IPv6:2a01:4f8:202:4333:225:90ff:fed9:fc84]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 9FB3B34EF38 for ; Fri, 10 Apr 2020 21:04:41 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 35E3B1EF for ; Fri, 10 Apr 2020 21:04:38 +0000 (UTC) From: "Matt Turner" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Matt Turner" Message-ID: <1586552633.137a83f50b42ab9ddd4c3c0908aadc723ce940d2.mattst88@gentoo> Subject: [gentoo-commits] proj/catalyst:master commit in: catalyst/ X-VCS-Repository: proj/catalyst X-VCS-Files: catalyst/support.py X-VCS-Directories: catalyst/ X-VCS-Committer: mattst88 X-VCS-Committer-Name: Matt Turner X-VCS-Revision: 137a83f50b42ab9ddd4c3c0908aadc723ce940d2 X-VCS-Branch: master Date: Fri, 10 Apr 2020 21:04:38 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: add90003-cd5b-4f04-8b9e-3d0bf0950206 X-Archives-Hash: 011dfb369001e824bb2d0528f5eeff80 commit: 137a83f50b42ab9ddd4c3c0908aadc723ce940d2 Author: Matt Turner gentoo org> AuthorDate: Fri Apr 10 17:59:33 2020 +0000 Commit: Matt Turner gentoo 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 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):