From 3f3a80da85b20dcf1ef7f7a3a20ec97422e95691 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sun, 18 May 2008 19:00:15 +0300 Subject: Implemented --max-tries option. --- do-until | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/do-until b/do-until index 1f60200..be6efee 100755 --- a/do-until +++ b/do-until @@ -14,9 +14,12 @@ import time def do_until(options, argv): - while True: + tries = 0 + while options.max_tries == 0 or tries < options.max_tries: + tries += 1 if options.verbose: - sys.stderr.write("do-until: executing: %s\n" % " ".join(argv)) + sys.stderr.write("do-until: attempt #%d: %s\n" % + (tries, " ".join(argv))) if options.no_act: sys.stderr.write("do-until: not running command, pretending it " "works anyway\n") @@ -41,6 +44,9 @@ def parse_args(args): parser.add_option("--sleep", type="int", default=1, metavar="SECS", help="Wait SECS seconds before re-trying a command. " "(Default is %default.)") + parser.add_option("--max-tries", type="int", default=0, metavar="COUNT", + help="Try at most COUNT times, with 0 meaning forever. " + "(Default is %default.)") options, argv = parser.parse_args(args) -- cgit v1.2.1