summaryrefslogtreecommitdiff
path: root/do-until
diff options
context:
space:
mode:
authorLars Wirzenius <liw@iki.fi>2008-05-18 18:44:49 +0300
committerLars Wirzenius <liw@iki.fi>2008-05-18 18:44:49 +0300
commitca1ea531246912040cc9e26e7e7d83f3c0f84e3b (patch)
tree2c37f5d72aaf53614fe3a8e7d173f82f820a9bfd /do-until
parent85f48ee98818840554f3e5f0b42bb38493a2153c (diff)
downloadextrautils-ca1ea531246912040cc9e26e7e7d83f3c0f84e3b.tar.gz
Rewrote do-until in Python, in preparation for command line parsing.
Diffstat (limited to 'do-until')
-rwxr-xr-xdo-until45
1 files changed, 33 insertions, 12 deletions
diff --git a/do-until b/do-until
index d9dc863..4aea815 100755
--- a/do-until
+++ b/do-until
@@ -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()