From 46be3923f67a6720af65dc2e6d65ceda6199fcf6 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sat, 12 Mar 2011 12:56:40 +0000 Subject: Adapt to new cliapp API. --- do-until | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) (limited to 'do-until') diff --git a/do-until b/do-until index 3d001e7..f71a233 100755 --- a/do-until +++ b/do-until @@ -29,30 +29,31 @@ import time class DoUntil(cliapp.Application): def add_settings(self): - self.add_boolean_setting(['no-act', 'n'], - 'Do not run command, just pretend to do it, ' - 'and pretend that it succeeds.') - self.add_boolean_setting(['verbose', 'v'], - 'Print command before executing it.') - self.add_integer_setting(['sleep'], - 'Wait SECS seconds before re-trying a ' - 'command. (Default is %default.)', - default=1) - self.add_integer_setting(['max-tries'], - 'Try at most COUNT times, with 0 meaning ' - 'forever. (Default is %default.)', - default=0) + self.settings.add_boolean_setting(['no-act', 'n'], + 'Do not run command, just pretend to do it, ' + 'and pretend that it succeeds.') + self.settings.add_boolean_setting(['verbose', 'v'], + 'Print command before executing it.') + self.settings.add_integer_setting(['sleep'], + 'Wait SECS seconds before re-trying a command. ' + '(Default is %default.)', + default=1) + self.settings.add_integer_setting(['max-tries'], + 'Try at most COUNT times, with 0 meaning forever. ' + '(Default is %default.)', + default=0) def process_args(self, argv): tries = 0 - while self.options.max_tries == 0 or tries < self.options.max_tries: + max_tries = self.settings['max-tries'] + while max_tries == 0 or tries < max_tries: tries += 1 - if self.options.verbose: + if self.settings['verbose']: sys.stderr.write('do-until: attempt #%d: %s\n' % (tries, ' '.join(argv))) - if self.options.no_act: - sys.stderr.write('do-until: not running command, pretending it ' - 'works anyway\n') + if self.settings['no-act']: + sys.stderr.write('do-until: not running command, ' + 'pretending it works anyway\n') break else: p = subprocess.Popen(argv) @@ -61,8 +62,8 @@ class DoUntil(cliapp.Application): break sys.stderr.write('do-until: command failed, ' 'trying again in %d second(s)\n' % - self.options.sleep) - time.sleep(self.options.sleep) + self.settings['sleep']) + time.sleep(self.settings['sleep']) if __name__ == '__main__': -- cgit v1.2.1