diff options
author | Lars Wirzenius <liw@iki.fi> | 2008-05-18 18:44:49 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@iki.fi> | 2008-05-18 18:44:49 +0300 |
commit | ca1ea531246912040cc9e26e7e7d83f3c0f84e3b (patch) | |
tree | 2c37f5d72aaf53614fe3a8e7d173f82f820a9bfd /do-until | |
parent | 85f48ee98818840554f3e5f0b42bb38493a2153c (diff) | |
download | extrautils-ca1ea531246912040cc9e26e7e7d83f3c0f84e3b.tar.gz |
Rewrote do-until in Python, in preparation for command line parsing.
Diffstat (limited to 'do-until')
-rwxr-xr-x | do-until | 45 |
1 files changed, 33 insertions, 12 deletions
@@ -1,12 +1,33 @@ -#!/bin/sh -# -# do-until - run a command until it succeeds -# -# Lars Wirzenius <liw@liw.fi> - -cmdline="$@" -while ! $cmdline -do - echo "Command failed, trying again in 1 second" - sleep 1 -done +#!/usr/bin/python + + +"""Run a command until it succeeds. + +Lars Wirzenius <liw@liw.fi> +""" + + +import subprocess +import sys +import time + + +def do_until(argv): + while True: + p = subprocess.Popen(argv) + p.communicate() + if p.returncode == 0: + break + sys.stderr.write("do-until: command failed, " + "trying again in 1 second\n") + time.sleep(1) + + +def main(): + argv = sys.argv[1:] + if argv: + do_until(argv) + + +if __name__ == "__main__": + main() |