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 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

View file

@ -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):
"""