From 2556da6fbd474edab7e703a0b4a06a09c247f077 Mon Sep 17 00:00:00 2001 From: Romain Bignon Date: Sun, 17 Oct 2010 14:47:15 +0200 Subject: [PATCH] better errors management in webcontentedit --- .../webcontentedit/webcontentedit.py | 23 ++++++++++++------- weboob/core/bcall.py | 8 +------ 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/weboob/applications/webcontentedit/webcontentedit.py b/weboob/applications/webcontentedit/webcontentedit.py index d260b7d7..f5839fba 100644 --- a/weboob/applications/webcontentedit/webcontentedit.py +++ b/weboob/applications/webcontentedit/webcontentedit.py @@ -19,6 +19,7 @@ import os import sys import tempfile +from weboob.core.bcall import CallErrors from weboob.capabilities.content import ICapContent from weboob.tools.application.repl import ReplApplication @@ -79,20 +80,26 @@ class WebContentEdit(ReplApplication): print 'No changes. Abort.' return - message = self.ask('Enter a commit message') - print 'Contents changed:\n%s' % ('\n'.join([' * %s' % content.id for content in contents])) + message = self.ask('Enter a commit message') + if not self.ask('Do you want to push?', default=True): return + errors = CallErrors([]) for content in contents: + path = [path for path, c in paths.iteritems() if c == content][0] sys.stdout.write('Pushing %s...' % content.id) sys.stdout.flush() try: - backend = self.weboob.get_backend(content.backend) - backend.push_content(content, message) - except Exception: - sys.stdout.write(' error\n') - raise - sys.stdout.write(' done\n') + self.do('push_content', content, message, backends=[content.backend]).wait() + except CallErrors, e: + errors.errors += e.errors + sys.stdout.write(' error (content saved in %s)\n' % path) + else: + sys.stdout.write(' done\n') + os.unlink(path) + + if len(errors.errors) > 0: + raise errors diff --git a/weboob/core/bcall.py b/weboob/core/bcall.py index 2e7879d6..f3739eef 100644 --- a/weboob/core/bcall.py +++ b/weboob/core/bcall.py @@ -19,7 +19,6 @@ from __future__ import with_statement from copy import copy -import logging from logging import debug from threading import Thread, Event, RLock, Timer @@ -32,17 +31,12 @@ __all__ = ['BackendsCall', 'CallErrors'] class CallErrors(Exception): def __init__(self, errors): - Exception.__init__(self, u'These errors have been raised in backend threads '\ - '(use --debug option to print backtraces):\n%s' % ( - u'\n'.join((u' * %s: %s%s' % (backend.name, repr(error), backtrace.decode('utf-8') + '\n' - if logging.root.level == logging.DEBUG else '')) - for backend, error, backtrace in errors))) + Exception.__init__(self, 'Errors during backend calls') self.errors = copy(errors) def __iter__(self): return self.errors.__iter__() - class BackendsCall(object): def __init__(self, backends, function, *args, **kwargs): """