summaryrefslogtreecommitdiff
path: root/do-until
diff options
context:
space:
mode:
authorLars Wirzenius <liw@iki.fi>2008-05-18 18:49:52 +0300
committerLars Wirzenius <liw@iki.fi>2008-05-18 18:49:52 +0300
commit01c41e052ff18d58e3eb89c7199b800ea1206852 (patch)
tree0c8c23e464db608168f709e39f1da833fc844b5f /do-until
parentca1ea531246912040cc9e26e7e7d83f3c0f84e3b (diff)
downloadextrautils-01c41e052ff18d58e3eb89c7199b800ea1206852.tar.gz
Added option parsing and --no-act option.
Diffstat (limited to 'do-until')
-rwxr-xr-xdo-until29
1 files changed, 23 insertions, 6 deletions
diff --git a/do-until b/do-until
index 4aea815..6903102 100755
--- a/do-until
+++ b/do-until
@@ -7,26 +7,43 @@ Lars Wirzenius <liw@liw.fi>
"""
+import optparse
import subprocess
import sys
import time
-def do_until(argv):
+def do_until(options, argv):
while True:
- p = subprocess.Popen(argv)
- p.communicate()
- if p.returncode == 0:
+ if options.no_act:
+ sys.stderr.write("do-until: not running command, pretending it "
+ "works anyway\n")
break
+ else:
+ 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 parse_args(args):
+ parser = optparse.OptionParser()
+ parser.add_option("-n", "--no-act", action="store_true",
+ help="Do not run command, just pretend to do it, and "
+ "pretend that it succeeds.")
+
+ options, argv = parser.parse_args(args)
+
+ return options, argv
+
+
def main():
- argv = sys.argv[1:]
+ options, argv = parse_args(sys.argv[1:])
if argv:
- do_until(argv)
+ do_until(options, argv)
if __name__ == "__main__":