diff options
author | Lars Wirzenius <liw@liw.fi> | 2011-03-12 12:56:40 +0000 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2011-03-12 12:56:40 +0000 |
commit | 46be3923f67a6720af65dc2e6d65ceda6199fcf6 (patch) | |
tree | 74d8b2aa07a4ed6255779640816049245e4e8340 | |
parent | c69f66a658d739b9dbfa2a890afc48a1028b8d39 (diff) | |
download | extrautils-46be3923f67a6720af65dc2e6d65ceda6199fcf6.tar.gz |
Adapt to new cliapp API.
-rwxr-xr-x | do-until | 41 |
1 files changed, 21 insertions, 20 deletions
@@ -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__': |