From 2366edf5beaa34e7762189e1976cd236a51cf0a6 Mon Sep 17 00:00:00 2001 From: Laurent Bachelier Date: Fri, 13 Jul 2018 12:18:21 +0200 Subject: [PATCH] repositories: Better display of errors Especially with local_run --- tools/local_run.py | 7 ++++--- weboob/applications/weboobcfg/weboobcfg.py | 5 +++++ weboob/core/repositories.py | 19 +++++++++++++++++-- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/tools/local_run.py b/tools/local_run.py index 4f5b7929f0..d7dbbc0561 100644 --- a/tools/local_run.py +++ b/tools/local_run.py @@ -43,13 +43,14 @@ # Hide output unless there is an error p = subprocess.Popen( - [sys.executable, os.path.join(project, 'scripts', 'weboob-config'), 'update'], + [sys.executable, os.path.join(project, 'scripts', 'weboob-config'), 'update', '-d'], env=env, - stdout=subprocess.PIPE) + stdout=subprocess.PIPE, stderr=subprocess.STDOUT) s = p.communicate() if p.returncode != 0: print(s[0]) - sys.exit(p.returncode) + if p.returncode > 1: + sys.exit(p.returncode) if os.path.exists(script): spath = script diff --git a/weboob/applications/weboobcfg/weboobcfg.py b/weboob/applications/weboobcfg/weboobcfg.py index 53b6b61d2c..fcef933751 100644 --- a/weboob/applications/weboobcfg/weboobcfg.py +++ b/weboob/applications/weboobcfg/weboobcfg.py @@ -320,3 +320,8 @@ def do_update(self, line): Update weboob. """ self.weboob.update(ConsoleProgress(self)) + if self.weboob.repositories.errors: + print('Errors building modules: %s' % ', '.join(self.weboob.repositories.errors.keys()), file=self.stderr) + if not self.options.debug: + print('Use --debug to get more information.', file=self.stderr) + return 1 diff --git a/weboob/core/repositories.py b/weboob/core/repositories.py index dc8cbe80c0..47942be5fb 100644 --- a/weboob/core/repositories.py +++ b/weboob/core/repositories.py @@ -132,6 +132,7 @@ def __init__(self, url): self.key_update = 0 self.obsolete = False self.logger = getLogger('repository') + self.errors = {} self.modules = {} @@ -275,6 +276,7 @@ def build_index(self, path, filename): """ self.logger.debug('Rebuild index') self.modules.clear() + self.errors.clear() if os.path.isdir(os.path.join(path, self.KEYDIR)): self.signed = True @@ -296,8 +298,10 @@ def build_index(self, path, filename): if fp: fp.close() except Exception as e: - print('Unable to build module %s: [%s] %s' % (name, type(e).__name__, e), file=sys.stderr) - self.logger.debug(get_backtrace(e)) + self.logger.warning('Unable to build module %s: [%s] %s' % (name, type(e).__name__, e)) + bt = get_backtrace(e) + self.logger.debug(bt) + self.errors[name] = bt else: m = ModuleInfo(module.name) m.version = self.get_tree_mtime(module_path) @@ -745,6 +749,17 @@ def url2filename(url): """ return ''.join([l if l.isalnum() else '_' for l in url]) + def __iter__(self): + for repository in self.repositories: + yield repository + + @property + def errors(self): + errors = {} + for repository in self: + errors.update(repository.errors) + return errors + class InvalidSignature(Exception): def __init__(self, filename): -- GitLab