better errors management in webcontentedit

This commit is contained in:
Romain Bignon 2010-10-17 14:47:15 +02:00
commit 2556da6fbd
2 changed files with 16 additions and 15 deletions

View file

@ -19,6 +19,7 @@ import os
import sys import sys
import tempfile import tempfile
from weboob.core.bcall import CallErrors
from weboob.capabilities.content import ICapContent from weboob.capabilities.content import ICapContent
from weboob.tools.application.repl import ReplApplication from weboob.tools.application.repl import ReplApplication
@ -79,20 +80,26 @@ class WebContentEdit(ReplApplication):
print 'No changes. Abort.' print 'No changes. Abort.'
return return
message = self.ask('Enter a commit message')
print 'Contents changed:\n%s' % ('\n'.join([' * %s' % content.id for content in contents])) 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): if not self.ask('Do you want to push?', default=True):
return return
errors = CallErrors([])
for content in contents: 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.write('Pushing %s...' % content.id)
sys.stdout.flush() sys.stdout.flush()
try: try:
backend = self.weboob.get_backend(content.backend) self.do('push_content', content, message, backends=[content.backend]).wait()
backend.push_content(content, message) except CallErrors, e:
except Exception: errors.errors += e.errors
sys.stdout.write(' error\n') sys.stdout.write(' error (content saved in %s)\n' % path)
raise else:
sys.stdout.write(' done\n') sys.stdout.write(' done\n')
os.unlink(path)
if len(errors.errors) > 0:
raise errors

View file

@ -19,7 +19,6 @@
from __future__ import with_statement from __future__ import with_statement
from copy import copy from copy import copy
import logging
from logging import debug from logging import debug
from threading import Thread, Event, RLock, Timer from threading import Thread, Event, RLock, Timer
@ -32,17 +31,12 @@ __all__ = ['BackendsCall', 'CallErrors']
class CallErrors(Exception): class CallErrors(Exception):
def __init__(self, errors): def __init__(self, errors):
Exception.__init__(self, u'These errors have been raised in backend threads '\ Exception.__init__(self, 'Errors during backend calls')
'(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)))
self.errors = copy(errors) self.errors = copy(errors)
def __iter__(self): def __iter__(self):
return self.errors.__iter__() return self.errors.__iter__()
class BackendsCall(object): class BackendsCall(object):
def __init__(self, backends, function, *args, **kwargs): def __init__(self, backends, function, *args, **kwargs):
""" """