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

@ -24,6 +24,7 @@ from httplib import BadStatusLine
from logging import warning
import mechanize
import os
import sys
import re
import tempfile
from threading import RLock
@ -316,7 +317,7 @@ class BaseBrowser(mechanize.Browser):
"""
if self.responses_dirname is None:
self.responses_dirname = tempfile.mkdtemp(prefix='weboob_session_')
print 'Debug data will be saved in this directory: %s' % self.responses_dirname
print >>sys.stderr, 'Debug data will be saved in this directory: %s' % self.responses_dirname
response_filepath = os.path.join(self.responses_dirname, unicode(self.responses_count))
with open(response_filepath, 'w') as f:
f.write(result.read())
@ -513,7 +514,7 @@ class BaseBrowser(mechanize.Browser):
value = [self.str(is_list.index(args[label]))]
except ValueError, e:
if args[label]:
print '[%s] %s: %s' % (label, args[label], e)
print >>sys.stderr, '[%s] %s: %s' % (label, args[label], e)
return
else:
value = [self.str(args[label])]