Better messages and return codes in applications

Use stderr and return codes >0 when it makes sense.
Loose return code conventions:
* 1 for generic errors
* 2 for user input errors
* 3 for remote errors (not found, etc.)
* 4 for not implemented
This commit is contained in:
Laurent Bachelier 2011-05-03 01:02:00 +02:00
commit 8075d538f0
18 changed files with 168 additions and 149 deletions

View file

@ -304,7 +304,7 @@ class BaseApplication(object):
if self.options.save_responses:
responses_dirname = tempfile.mkdtemp(prefix='weboob_session_')
print 'Debug data will be saved in this directory: %s' % responses_dirname
print >>sys.stderr, 'Debug data will be saved in this directory: %s' % responses_dirname
from weboob.tools.browser import BaseBrowser
BaseBrowser.SAVE_RESPONSES = True
BaseBrowser.responses_dirname = responses_dirname
@ -359,7 +359,7 @@ class BaseApplication(object):
try:
app = klass()
except BackendsConfig.WrongPermissions, e:
print e
print >>sys.stderr, e
sys.exit(1)
try:
@ -367,12 +367,12 @@ class BaseApplication(object):
args = app.parse_args(args)
sys.exit(app.main(args))
except KeyboardInterrupt:
print 'Program killed by SIGINT'
print >>sys.stderr, 'Program killed by SIGINT'
sys.exit(0)
except EOFError:
sys.exit(0)
except ConfigError, e:
print 'Configuration error: %s' % e
print >>sys.stderr, 'Configuration error: %s' % e
sys.exit(1)
except CallErrors, e:
app.bcall_errors_handler(e)