diff --git a/tools/make_man.py b/tools/make_man.py index 89b26c64..1b47f00b 100755 --- a/tools/make_man.py +++ b/tools/make_man.py @@ -118,7 +118,7 @@ def main(): try: script = imp.load_module("scripts.%s" % fname, f, tmpfile, desc) except ImportError, e: - print >> sys.stderr, "Unable to load the %s script (%s)" \ + print >>sys.stderr, "Unable to load the %s script (%s)" \ % (fname, e) else: print "Loaded %s" % fname diff --git a/weboob/applications/boobank/boobank.py b/weboob/applications/boobank/boobank.py index e920c26f..528c682c 100644 --- a/weboob/applications/boobank/boobank.py +++ b/weboob/applications/boobank/boobank.py @@ -146,7 +146,7 @@ class Boobank(ReplApplication): id, backend_name = self.parse_id(id) if not id: print >>sys.stderr, 'Error: please give an account ID (hint: use list command)' - return 1 + return 2 names = (backend_name,) if backend_name is not None else None def do(backend): @@ -204,7 +204,7 @@ class Boobank(ReplApplication): id_from, backend_name_from = self.parse_id(id_from) if not id_to: print >>sys.stderr, 'Error: listing recipient is not implemented yet' - return + return 4 id_to, backend_name_to = self.parse_id(id_to) @@ -212,11 +212,11 @@ class Boobank(ReplApplication): amount = float(amount) except (TypeError,ValueError): print >>sys.stderr, 'Error: please give a decimal amount to transfer' - return 1 + return 2 if backend_name_from != backend_name_to: print >>sys.stderr, "Transfer between different backends is not implemented" - return + return 4 else: backend_name = backend_name_from diff --git a/weboob/applications/boobathon/boobathon.py b/weboob/applications/boobathon/boobathon.py index 10e566eb..af3f822c 100644 --- a/weboob/applications/boobathon/boobathon.py +++ b/weboob/applications/boobathon/boobathon.py @@ -117,7 +117,7 @@ class Event(object): elif line.startswith('h3=. '): m = re.match('h3=. Event finished. Winner is "(.*)":/users/(\d+)\!', line) if not m: - print 'Unable to parse h3=: %s' % line + print >>sys.stderr, 'Unable to parse h3=: %s' % line continue self.winner = Member(int(m.group(2)), m.group(1)) elif line.startswith('h2. '): @@ -125,7 +125,7 @@ class Event(object): elif line.startswith('h3. '): m = re.match('h3. "(.*)":/users/(\d+)', line) if not m: - print 'Unable to parse user "%s"' % line + print >>sys.stderr, 'Unable to parse user "%s"' % line continue member = Member(int(m.group(2)), m.group(1)) if member.id == self.my_id: @@ -164,7 +164,7 @@ class Event(object): elif line.startswith('[['): m = re.match('\[\[(\w+)\]\]\|\[\[(\w+)\]\]\|(.*)\|', line) if not m: - print 'Unable to parse task: "%s"' % line + print >>sys.stderr, 'Unable to parse task: "%s"' % line continue task = Task(m.group(1), m.group(2)) member.tasks.append(task) @@ -467,7 +467,8 @@ class Boobathon(ReplApplication): print 'Event is now closed. Winner is %s!' % self.winner.name return - print '"%s" not found' % name + print >>sys.stderr, '"%s" not found' % name + return 3 def complete_edit(self, text, line, *ignored): args = line.split(' ') @@ -481,8 +482,8 @@ class Boobathon(ReplApplication): Edit information about you or about event. """ if not line: - print 'Syntax: edit [event | me]' - return + print >>sys.stderr, 'Syntax: edit [event | me]' + return 2 self.event.load() if line == 'event': @@ -491,12 +492,13 @@ class Boobathon(ReplApplication): elif line == 'me': mem = self.event.get_me() if not mem: - print 'You haven\'t joined the event.' - return + print >>sys.stderr, 'You haven\'t joined the event.' + return 1 self.edit_member(mem) self.save_event('Member edited') else: - print 'Unable to edit "%s"' % line + print >>sys.stderr, 'Unable to edit "%s"' % line + return 1 def do_info(self, line): """ @@ -552,12 +554,12 @@ class Boobathon(ReplApplication): """ self.event.load() if self.event.backend.browser.get_userid() in self.event.members: - print 'You have already joined this event.' - return + print >>sys.stderr, 'You have already joined this event.' + return 1 if self.event.is_closed(): - print 'Boobathon is closed.' - return + print >>sys.stderr, "Boobathon is closed." + return 1 m = Member(self.event.backend.browser.get_userid(), None) self.edit_member(m) @@ -573,17 +575,18 @@ class Boobathon(ReplApplication): self.event.load() if self.event.currently_in_event(): - print 'Unable to leave during the event, loser!' - return + print >>sys.stderr, 'Unable to leave during the event, loser!' + return 1 if self.event.is_closed(): - print 'Boobathon is closed.' - return + print >>sys.stderr, "Boobathon is closed." + return 1 try: self.event.members.pop(self.event.backend.browser.get_userid()) except KeyError: - print 'You have not joined this event.' + print >>sys.stderr, "You have not joined this event." + return 1 else: self.save_event('Left the event') @@ -596,23 +599,24 @@ class Boobathon(ReplApplication): self.event.load() mem = self.event.get_me() if not mem: - print 'You have not joined this event.' - return + print >>sys.stderr, "You have not joined this event." + return 1 if self.event.is_closed(): - print 'Boobathon is closed.' - return + print >>sys.stderr, "Boobathon is closed." + return 1 try: task_id = int(line) except ValueError: - print 'The task ID might be a number' - return + print >>sys.stderr, 'The task ID should be a number' + return 2 try: task = mem.tasks.pop(task_id) except IndexError: - print 'Unable to find task #%d' % task_id + print >>sys.stderr, 'Unable to find task #%d' % task_id + return 1 else: print 'Removing task #%d (%s,%s).' % (task_id, task.backend, task.capability) self.save_event('Remove task') @@ -626,25 +630,25 @@ class Boobathon(ReplApplication): self.event.load() mem = self.event.get_me() if not mem: - print 'You have not joined this event.' - return + print >>sys.stderr, "You have not joined this event." + return 1 if self.event.is_closed(): - print 'Boobathon is closed.' - return + print >>sys.stderr, "Boobathon is closed." + return 1 backend, capability = self.parse_command_args(line, 2, 2) if not backend[0].isupper(): - print 'The backend name "%s" needs to start with a capital.' % backend - return + print >>sys.stderr, 'The backend name "%s" needs to start with a capital.' % backend + return 2 if not capability.startswith('Cap') or not capability[3].isupper(): - print '"%s" is not a right capability name.' % capability - return + print >>sys.stderr, '"%s" is not a proper capability name (must start with Cap).' % capability + return 2 for task in mem.tasks: if (task.backend,task.capability) == (backend,capability): - print 'A task already exists for that.' - return + print >>sys.stderr, "A task already exists for that." + return 1 task = Task(backend, capability) mem.tasks.append(task) @@ -660,16 +664,16 @@ class Boobathon(ReplApplication): self.event.load() mem = self.event.get_me() if not mem: - print 'You have not joined this event.' - return + print >>sys.stderr, "You have not joined this event." + return 1 if len(mem.tasks) == 0: - print "You don't have any task to do." - return + print >>sys.stderr, "You don't have any task to do." + return 1 if not self.event.currently_in_event(): - print "You can't start a task, we are not in event." - return + print >>sys.stderr, "You can't start a task, we are not in event." + return 1 if line.isdigit(): task_id = int(line) @@ -687,11 +691,12 @@ class Boobathon(ReplApplication): if (i == task_id or task_id < 0) and task.status == task.STATUS_NONE: break else: - print 'Task not found.' + print >>sys.stderr, 'Task not found.' + return 3 if task.status == task.STATUS_DONE: - print 'Task is already done.' - return + print >>sys.stderr, 'Task is already done.' + return 1 task.status = task.STATUS_PROGRESS mem.tasks.remove(task) @@ -707,12 +712,12 @@ class Boobathon(ReplApplication): self.event.load() mem = self.event.get_me() if not mem: - print 'You have not joined this event.' - return + print >>sys.stderr, "You have not joined this event." + return 1 if self.event.is_closed(): - print 'Boobathon is closed.' - return + print >>sys.stderr, "Boobathon is closed." + return 1 for i, task in enumerate(mem.tasks): if task.status == task.STATUS_PROGRESS: @@ -724,11 +729,13 @@ class Boobathon(ReplApplication): self.save_event('Task accomplished') else: task.status = task.STATUS_NONE - print 'Oops, you are out of event. Canceling the task...' + print >>sys.stderr, 'Oops, you are out of event. Canceling the task...' self.save_event('Cancel task') + return 1 return - print "There isn't any task in progress." + print >>sys.stderr, "There isn't any task in progress." + return 1 def do_cancel(self, line): """ @@ -739,12 +746,12 @@ class Boobathon(ReplApplication): self.event.load() mem = self.event.get_me() if not mem: - print 'You have not joined this event.' - return + print >>sys.stderr, "You have not joined this event." + return 1 if self.event.is_closed(): - print 'Boobathon is closed.' - return + print >>sys.stderr, "Boobathon is closed." + return 1 for task in mem.tasks: if task.status == task.STATUS_PROGRESS: @@ -753,7 +760,8 @@ class Boobathon(ReplApplication): self.save_event('Cancel task') return - print "There isn't any task in progress." + print >>sys.stderr, "There isn't any task in progress." + return 1 def load_default_backends(self): @@ -769,7 +777,7 @@ class Boobathon(ReplApplication): return if not self.check_loaded_backends({'url': 'https://symlink.me'}): - print 'Ok, so leave now, fag.' + print "Ok, so leave now, fag." sys.exit(0) def is_backend_loadable(self, backend): diff --git a/weboob/applications/boobmsg/boobmsg.py b/weboob/applications/boobmsg/boobmsg.py index 633344f4..9c760649 100644 --- a/weboob/applications/boobmsg/boobmsg.py +++ b/weboob/applications/boobmsg/boobmsg.py @@ -342,8 +342,8 @@ class Boobmsg(ReplApplication): Read a message """ if len(arg) == 0: - print 'Please give a message ID.' - return + print >>sys.stderr, 'Please give a message ID.' + return 2 try: message = self.messages[int(arg) - 1] @@ -355,6 +355,8 @@ class Boobmsg(ReplApplication): return if not self.interactive: - print 'Oops, you need to be in interactive mode to read messages' + print >>sys.stderr, 'Oops, you need to be in interactive mode to read messages' + return 1 else: - print 'Message not found' + print >>sys.stderr, 'Message not found' + return 3 diff --git a/weboob/applications/galleroob/galleroob.py b/weboob/applications/galleroob/galleroob.py index daf79b86..4b1be21d 100644 --- a/weboob/applications/galleroob/galleroob.py +++ b/weboob/applications/galleroob/galleroob.py @@ -102,8 +102,8 @@ class Galleroob(ReplApplication): gallery = result if not gallery: - print 'Gallery not found: %s' % _id - return 1 + print >>sys.stderr, 'Gallery not found: %s' % _id + return 3 backend.fillobj(gallery, ('title',)) if dest is None: @@ -127,7 +127,7 @@ class Galleroob(ReplApplication): if img.data is None: backend.fillobj(img, ('url','data')) if img.data is None: - print "Couldn't get page %d, exiting" % i + print >>sys.stderr, "Couldn't get page %d, exiting" % i break ext = search(r"\.([^\.]{1,5})$", img.url) @@ -156,6 +156,6 @@ class Galleroob(ReplApplication): gallery = self.get_object(_id, 'get_gallery') if not gallery: print >>sys.stderr, 'Gallery not found: %s' % _id - return + return 3 self.format(gallery) self.flush() diff --git a/weboob/applications/geolooc/geolooc.py b/weboob/applications/geolooc/geolooc.py index 6969207b..ce979868 100644 --- a/weboob/applications/geolooc/geolooc.py +++ b/weboob/applications/geolooc/geolooc.py @@ -37,9 +37,7 @@ class Geolooc(ReplApplication): def main(self, argv): if len(argv) < 2: print >>sys.stderr, 'Syntax: %s ipaddr' % argv[0] - return 1 + return 2 for backend, location in self.do('get_location', argv[1]): self.format(location) - - return 0 diff --git a/weboob/applications/havesex/havesex.py b/weboob/applications/havesex/havesex.py index 6e2828d6..22ef0afb 100644 --- a/weboob/applications/havesex/havesex.py +++ b/weboob/applications/havesex/havesex.py @@ -133,7 +133,7 @@ class HaveSex(ReplApplication): def edit_optims(self, backend_names, optims_names, stop=False): if optims_names is None: print >>sys.stderr, 'Error: missing parameters.' - return 1 + return 2 for optim_name in optims_names.split(): backends_optims = {} @@ -165,7 +165,7 @@ class HaveSex(ReplApplication): def optims(self, function, backend_names, optims, store=True): if optims is None: print >>sys.stderr, 'Error: missing parameters.' - return 1 + return 2 for optim_name in optims.split(): try: @@ -211,8 +211,6 @@ class HaveSex(ReplApplication): if store: self.storage.save() - return 0 - def complete_optim(self, text, line, *ignored): args = line.split(' ') if len(args) == 2: diff --git a/weboob/applications/pastoob/pastoob.py b/weboob/applications/pastoob/pastoob.py index 8e5ca632..81c266d2 100644 --- a/weboob/applications/pastoob/pastoob.py +++ b/weboob/applications/pastoob/pastoob.py @@ -53,16 +53,16 @@ class Pastoob(ReplApplication): print args if not _id: print >>sys.stderr, 'This command takes an argument: %s' % self.get_command_help('get', short=True) - return 1 + return 2 try: paste = self.get_object(_id, 'get_paste', ['contents']) except PasteNotFound: print >>sys.stderr, 'Paste not found: %s' % _id - return 2 + return 3 if not paste: print >>sys.stderr, 'Unable to handle paste: %s' % _id - return 3 + return 1 output = codecs.getwriter(sys.stdout.encoding)(sys.stdout) output.write(paste.contents) # add a newline unless we are writing diff --git a/weboob/applications/radioob/radioob.py b/weboob/applications/radioob/radioob.py index 123e6725..64d67994 100644 --- a/weboob/applications/radioob/radioob.py +++ b/weboob/applications/radioob/radioob.py @@ -87,13 +87,13 @@ class Radioob(ReplApplication): Play a radio with a found player. """ if not _id: - print 'This command takes an argument: %s' % self.get_command_help('play', short=True) - return + print >>sys.stderr, 'This command takes an argument: %s' % self.get_command_help('play', short=True) + return 2 radio = self.get_object(_id, 'get_radio', ['streams']) if not radio: print >>sys.stderr, 'Radio not found: ' % _id - return + return 1 try: player_name = self.config.get('media_player') if not player_name: @@ -115,13 +115,13 @@ class Radioob(ReplApplication): Get information about a radio. """ if not _id: - print 'This command takes an argument: %s' % self.get_command_help('info', short=True) - return + print >>sys.stderr, 'This command takes an argument: %s' % self.get_command_help('info', short=True) + return 2 radio = self.get_object(_id, 'get_radio') if not radio: - print 'Radio not found:', _id - return + print >>sys.stderr, 'Radio not found:', _id + return 3 self.format(radio) self.flush() diff --git a/weboob/applications/videoob/videoob.py b/weboob/applications/videoob/videoob.py index 7093e5ab..69ea49b6 100644 --- a/weboob/applications/videoob/videoob.py +++ b/weboob/applications/videoob/videoob.py @@ -93,8 +93,8 @@ class Videoob(ReplApplication): _id, dest = self.parse_command_args(line, 2, 1) video = self.get_object(_id, 'get_video', ['url']) if not video: - print 'Video not found: %s' % _id - return 1 + print >>sys.stderr, 'Video not found: %s' % _id + return 3 def check_exec(executable): with open('/dev/null', 'w') as devnull: @@ -136,13 +136,13 @@ class Videoob(ReplApplication): Play a video with a found player. """ if not _id: - print 'This command takes an argument: %s' % self.get_command_help('play', short=True) - return + print >>sys.stderr, 'This command takes an argument: %s' % self.get_command_help('play', short=True) + return 2 video = self.get_object(_id, 'get_video', ['url']) if not video: - print 'Video not found: %s' % _id - return + print >>sys.stderr, 'Video not found: %s' % _id + return 3 try: player_name = self.config.get('media_player') if not player_name: @@ -164,13 +164,13 @@ class Videoob(ReplApplication): Get information about a video. """ if not _id: - print 'This command takes an argument: %s' % self.get_command_help('info', short=True) - return + print >>sys.stderr, 'This command takes an argument: %s' % self.get_command_help('info', short=True) + return 2 video = self.get_object(_id, 'get_video') if not video: print >>sys.stderr, 'Video not found: %s' % _id - return + return 3 self.format(video) self.flush() @@ -193,6 +193,7 @@ class Videoob(ReplApplication): self.nsfw = False else: print 'Invalid argument "%s".' % line + return 2 else: print "on" if self.nsfw else "off" @@ -206,9 +207,9 @@ class Videoob(ReplApplication): """ if len(self.enabled_backends) == 0: if self.interactive: - print 'No backend loaded. Please use the "backends" command.' + print >>sys.stderr, 'No backend loaded. Please use the "backends" command.' else: - print 'No backend loaded.' + print >>sys.stderr, 'No backend loaded.' return 1 self.set_formatter_header(u'Search pattern: %s' % pattern if pattern else u'Latest videos') diff --git a/weboob/applications/webcontentedit/webcontentedit.py b/weboob/applications/webcontentedit/webcontentedit.py index d006de36..5d7c9e76 100644 --- a/weboob/applications/webcontentedit/webcontentedit.py +++ b/weboob/applications/webcontentedit/webcontentedit.py @@ -54,8 +54,8 @@ class WebContentEdit(ReplApplication): contents += [content for backend, content in self.do('get_content', _id, backends=backend_names) if content] if len(contents) == 0: - print >> sys.stderr, 'No contents found' - return 1 + print >>sys.stderr, 'No contents found' + return 3 paths = {} for content in contents: @@ -92,8 +92,8 @@ class WebContentEdit(ReplApplication): contents.remove(content) if len(contents) == 0: - print 'No changes. Abort.' - return + print >>sys.stderr, 'No changes. Abort.' + return 1 print 'Contents changed:\n%s' % ('\n'.join(' * %s' % content.id for content in contents)) @@ -126,8 +126,8 @@ class WebContentEdit(ReplApplication): Display log of a page """ if not line: - print >> sys.stderr, 'Error: please give a page ID' - return 1 + print >>sys.stderr, 'Error: please give a page ID' + return 2 _id, backend_name = self.parse_id(line) backend_names = (backend_name,) if backend_name is not None else self.enabled_backends diff --git a/weboob/applications/weboobcfg/weboobcfg.py b/weboob/applications/weboobcfg/weboobcfg.py index 4c342ae0..7994c44a 100644 --- a/weboob/applications/weboobcfg/weboobcfg.py +++ b/weboob/applications/weboobcfg/weboobcfg.py @@ -52,7 +52,7 @@ class WeboobCfg(ReplApplication): """ if not line: print >>sys.stderr, 'You must specify a backend name. Hint: use the "backends" command.' - return + return 2 name, options = self.parse_command_args(line, 2, 1) if options: options = options.split(' ') @@ -65,8 +65,8 @@ class WeboobCfg(ReplApplication): try: key, value = option.split('=', 1) except ValueError: - print 'Parameters have to be formatted "key=value"' - return + print >>sys.stderr, 'Parameters have to be formatted "key=value"' + return 2 params[key] = value self.add_backend(name, params) @@ -133,9 +133,8 @@ class WeboobCfg(ReplApplication): Remove a configured backend. """ if not self.weboob.backends_config.remove_backend(instance_name): - print 'Backend instance "%s" does not exist' % instance_name + print >>sys.stderr, 'Backend instance "%s" does not exist' % instance_name return 1 - return 0 def do_edit(self, line): """ @@ -175,7 +174,7 @@ class WeboobCfg(ReplApplication): """ if not line: print >>sys.stderr, 'You must specify a backend name. Hint: use the "backends" command.' - return + return 2 try: backend = self.weboob.modules_loader.get_or_load_module(line) @@ -183,7 +182,7 @@ class WeboobCfg(ReplApplication): backend = None if not backend: - print 'Backend "%s" does not exist.' % line + print >>sys.stderr, 'Backend "%s" does not exist.' % line return 1 print '.------------------------------------------------------------------------------.' diff --git a/weboob/applications/weboobcli/weboobcli.py b/weboob/applications/weboobcli/weboobcli.py index cd8da101..ca9e64b2 100644 --- a/weboob/applications/weboobcli/weboobcli.py +++ b/weboob/applications/weboobcli/weboobcli.py @@ -42,7 +42,7 @@ class WeboobCli(ReplApplication): def main(self, argv): if len(argv) < 3: print >>sys.stderr, "Syntax: %s capability method [args ..]" % argv[0] - return 1 + return 2 cap_s = argv[1] cmd = argv[2] diff --git a/weboob/applications/weboorrents/weboorrents.py b/weboob/applications/weboorrents/weboorrents.py index 367ee6e0..a2741e89 100644 --- a/weboob/applications/weboorrents/weboorrents.py +++ b/weboob/applications/weboorrents/weboorrents.py @@ -113,6 +113,7 @@ class Weboorrents(ReplApplication): if not found: print >>sys.stderr, 'Torrent "%s" not found' % id + return 3 else: self.flush() @@ -149,6 +150,7 @@ class Weboorrents(ReplApplication): return print >>sys.stderr, 'Torrent "%s" not found' % id + return 3 def do_search(self, pattern): """ diff --git a/weboob/tools/application/base.py b/weboob/tools/application/base.py index 4f47a59c..b63f04c8 100644 --- a/weboob/tools/application/base.py +++ b/weboob/tools/application/base.py @@ -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) diff --git a/weboob/tools/application/console.py b/weboob/tools/application/console.py index e96bf2d9..5ba01c6b 100644 --- a/weboob/tools/application/console.py +++ b/weboob/tools/application/console.py @@ -126,7 +126,7 @@ class ConsoleApplication(BaseApplication): if r.isdigit(): i = int(r) - 1 if i < 0 or i >= len(backends): - print 'Error: %s is not a valid choice' % r + print >>sys.stderr, 'Error: %s is not a valid choice' % r continue name = backends[i] try: @@ -182,7 +182,7 @@ class ConsoleApplication(BaseApplication): if response.isdigit(): i = int(response) - 1 if i < 0 or i >= len(backends): - print 'Error: %s is not a valid choice' % response + print >>sys.stderr, 'Error: %s is not a valid choice' % response continue backend_name = backends[i][0] else: @@ -208,12 +208,12 @@ class ConsoleApplication(BaseApplication): backend = None if not backend: - print 'Backend "%s" does not exist.' % name - return None + print >>sys.stderr, 'Backend "%s" does not exist.' % name + return 1 if not backend.has_caps(ICapAccount) or backend.klass.ACCOUNT_REGISTER_PROPERTIES is None: - print 'You can\'t register a new account with %s' % name - return None + print >>sys.stderr, 'You can\'t register a new account with %s' % name + return 1 account = Account() account.properties = {} @@ -274,8 +274,8 @@ class ConsoleApplication(BaseApplication): items.update(params) params = items if not backend: - print 'Backend "%s" does not exist. Hint: use the "backends" command.' % name - return None + print >>sys.stderr, 'Backend "%s" does not exist. Hint: use the "backends" command.' % name + return 1 # ask for params non-specified on command-line arguments asked_config = False @@ -296,7 +296,7 @@ class ConsoleApplication(BaseApplication): print 'Backend "%s" successfully %s.' % (name, 'updated' if edit else 'added') return name except BackendAlreadyExists: - print 'Backend "%s" is already configured in file "%s"' % (name, self.weboob.backends_config.confpath) + print >>sys.stderr, 'Backend "%s" is already configured in file "%s"' % (name, self.weboob.backends_config.confpath) while self.ask('Add new instance of "%s" backend?' % name, default=False): new_name = self.ask('Please give new instance name (could be "%s_1")' % name, regexp=r'^[\w\-_]+$') try: @@ -304,7 +304,8 @@ class ConsoleApplication(BaseApplication): print 'Backend "%s" successfully added.' % new_name return new_name except BackendAlreadyExists: - print 'Instance "%s" already exists for backend "%s".' % (new_name, name) + print >>sys.stderr, 'Instance "%s" already exists for backend "%s".' % (new_name, name) + return 1 def ask(self, question, default=None, masked=False, regexp=None, choices=None): """ @@ -396,7 +397,7 @@ class ConsoleApplication(BaseApplication): try: v.set_value(line) except ValueError, e: - print 'Error: %s' % e + print >>sys.stderr, 'Error: %s' % e else: break diff --git a/weboob/tools/application/repl.py b/weboob/tools/application/repl.py index 0433d93a..100e67d3 100644 --- a/weboob/tools/application/repl.py +++ b/weboob/tools/application/repl.py @@ -298,7 +298,8 @@ class ReplApplication(Cmd, ConsoleApplication): pass def default(self, line): - print 'Unknown command: "%s"' % line + print >>sys.stderr, 'Unknown command: "%s"' % line + return 2 def completenames(self, text, *ignored): return [name for name in Cmd.completenames(self, text, *ignored) if name not in self.hidden_commands] @@ -440,11 +441,12 @@ class ReplApplication(Cmd, ConsoleApplication): else: self.stdout.write('%s\n' % command_help) else: - print 'Unknown command: "%s"' % arg + print >>sys.stderr, 'Unknown command: "%s"' % arg else: cmds = self._parser.formatter.format_commands(self._parser.commands) self.stdout.write('%s\n' % cmds) self.stdout.write('Type "help " for more info about a command.\n') + return 2 def complete_backends(self, text, line, begidx, endidx): choices = [] @@ -518,7 +520,7 @@ class ReplApplication(Cmd, ConsoleApplication): if action in ('enable', 'disable', 'only', 'add', 'register', 'edit', 'remove'): if not given_backend_names: print >>sys.stderr, 'Please give at least a backend name.' - return + return 2 given_backends = set(backend for backend in self.weboob.iter_backends() if backend.name in given_backend_names) @@ -530,7 +532,7 @@ class ReplApplication(Cmd, ConsoleApplication): try: self.enabled_backends.remove(backend) except KeyError: - print '%s is not enabled' % backend.name + print >>sys.stderr, '%s is not enabled' % backend.name elif action == 'only': self.enabled_backends = set() for backend in given_backends: @@ -564,11 +566,11 @@ class ReplApplication(Cmd, ConsoleApplication): self.weboob.backends_config.remove_backend(backend.name) self.unload_backends(backend.name) else: - print 'Unknown action: "%s"' % action + print >>sys.stderr, 'Unknown action: "%s"' % action return 1 if len(self.enabled_backends) == 0: - print 'Warning: no more backends are loaded. %s is probably unusable.' % self.APPNAME.capitalize() + print >>sys.stderr, 'Warning: no more backends are loaded. %s is probably unusable.' % self.APPNAME.capitalize() def complete_logging(self, text, line, begidx, endidx): levels = ('debug', 'info', 'warning', 'error', 'quiet', 'default') @@ -611,6 +613,7 @@ class ReplApplication(Cmd, ConsoleApplication): except KeyError: print >>sys.stderr, 'Level "%s" does not exist.' % args[0] print >>sys.stderr, 'Availables: %s' % ' '.join(levels.iterkeys()) + return 2 else: logging.root.setLevel(level) for handler in logging.root.handlers: @@ -634,6 +637,7 @@ class ReplApplication(Cmd, ConsoleApplication): self.condition = ResultsCondition(line) except ResultsConditionError, e: print >>sys.stderr, '%s' % e + return 2 else: if self.condition is None: print 'No condition is set.' @@ -658,12 +662,14 @@ class ReplApplication(Cmd, ConsoleApplication): try: count = int(line) except ValueError: - print 'Could not interpret "%s" as a number.' % line + print >>sys.stderr, 'Could not interpret "%s" as a number.' % line + return 2 else: if count > 0: self.options.count = count else: - print 'Number must be at least 1.' + print >>sys.stderr, 'Number must be at least 1.' + return 2 else: if self.options.count is None: print 'Counting disabled.' @@ -717,14 +723,16 @@ class ReplApplication(Cmd, ConsoleApplication): print 'off' if self.options.no_keys else 'on' else: if args[2] not in ('on', 'off'): - print 'Invalid value "%s". Please use "on" or "off" values.' % args[2] + print >>sys.stderr, 'Invalid value "%s". Please use "on" or "off" values.' % args[2] + return 2 else: if args[1] == 'header': self.options.no_header = True if args[2] == 'off' else False elif args[1] == 'keys': self.options.no_keys = True if args[2] == 'off' else False else: - print 'Don\'t know which option to set. Available options: header, keys.' + print >>sys.stderr, 'Don\'t know which option to set. Available options: header, keys.' + return 2 else: if args[0] in self.formatters_loader.get_available_formatters(): if len(args) > 1: @@ -733,8 +741,9 @@ class ReplApplication(Cmd, ConsoleApplication): self.commands_formatters = {} self.DEFAULT_FORMATTER = self.set_formatter(args[0]) else: - print 'Formatter "%s" is not available.\n' \ + print >>sys.stderr, 'Formatter "%s" is not available.\n' \ 'Available formatters: %s.' % (args[0], ', '.join(self.formatters_loader.get_available_formatters())) + return 1 else: print 'Default formatter: %s' % self.DEFAULT_FORMATTER for key, klass in self.commands_formatters.iteritems(): @@ -779,16 +788,16 @@ class ReplApplication(Cmd, ConsoleApplication): else: backend_name = line.strip() if not backend_name: - print 'Please specify a backend name.' - return + print >>sys.stderr, 'Please specify a backend name.' + return 2 backends = set(backend for backend in self.enabled_backends if backend.name == backend_name) if not backends: - print 'No backend found for "%s"' % backend_name - return + print >>sys.stderr, 'No backend found for "%s"' % backend_name + return 1 backend = backends.pop() if not hasattr(backend, '_browser'): - print 'No browser created for backend "%s" yet. Please invoke a command before.' % backend.name - return + print >>sys.stderr, 'No browser created for backend "%s" yet. Please invoke a command before.' % backend.name + return 1 browser = backend._browser data = browser.parser.tostring(browser.page.document) try: @@ -866,10 +875,10 @@ class ReplApplication(Cmd, ConsoleApplication): try: self.formatter = self.formatters_loader.build_formatter(name) except FormatterLoadError, e: - print '%s' % e + print >>sys.stderr, '%s' % e if self.DEFAULT_FORMATTER == name: self.DEFAULT_FORMATTER = ReplApplication.DEFAULT_FORMATTER - print 'Falling back to "%s".' % (self.DEFAULT_FORMATTER) + print >>sys.stderr, 'Falling back to "%s".' % (self.DEFAULT_FORMATTER) self.formatter = self.formatters_loader.build_formatter(self.DEFAULT_FORMATTER) name = self.DEFAULT_FORMATTER if self.options.no_header: @@ -892,9 +901,9 @@ class ReplApplication(Cmd, ConsoleApplication): try: self.formatter.format(obj=result, selected_fields=fields) except FieldNotFound, e: - print e + print >>sys.stderr, e except MandatoryFieldsNotFound, e: - print >> sys.stderr, '%s Hint: select missing fields or use another formatter (ex: multiline).' % e + print >>sys.stderr, '%s Hint: select missing fields or use another formatter (ex: multiline).' % e def flush(self): self.formatter.flush() diff --git a/weboob/tools/browser/browser.py b/weboob/tools/browser/browser.py index 3c380ac8..fa11b06e 100644 --- a/weboob/tools/browser/browser.py +++ b/weboob/tools/browser/browser.py @@ -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])]