From 162eeb7e06e04ec32ed66331a184c9527fa68e82 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Wed, 27 Mar 2019 18:08:46 +0100 Subject: [PATCH] Dump sources list in error message to help debugging --- locales/en.json | 4 ++-- src/yunohost/tools.py | 21 ++++++++++++++------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/locales/en.json b/locales/en.json index da27c7cb0..64f2e6766 100644 --- a/locales/en.json +++ b/locales/en.json @@ -482,8 +482,8 @@ "unit_unknown": "Unknown unit '{unit:s}'", "unlimit": "No quota", "unrestore_app": "App '{app:s}' will not be restored", - "update_cache_failed": "Unable to update APT cache", - "update_cache_warning": "Some errors happened while updating APT cache", + "update_apt_cache_failed": "Unable to update the cache of APT (Debian's package manager). Here is a dump of the sources.list lines which might help to identify problematic lines : \n{sourceslist}", + "update_apt_cache_warning": "Some errors happened while updating the cache of APT (Debian's package manager). Here is a dump of the sources.list lines which might help to identify problematic lines : \n{sourceslist}", "updating_apt_cache": "Fetching available upgrades for system packages…", "upgrade_complete": "Upgrade complete", "upgrading_packages": "Upgrading packages…", diff --git a/src/yunohost/tools.py b/src/yunohost/tools.py index f9d86ad09..635399801 100644 --- a/src/yunohost/tools.py +++ b/src/yunohost/tools.py @@ -30,6 +30,7 @@ import json import subprocess import pwd import socket +from glob import glob from xmlrpclib import Fault from importlib import import_module from collections import OrderedDict @@ -502,14 +503,9 @@ def tools_update(ignore_apps=False, ignore_packages=False): returncode = call_async_output(command, callbacks, shell=True) if returncode != 0: - - # TODO : here, we should run something like a - # `cat /etc/apt/sources.list /etc/apt/sources.list.d/*` - # and append it to the error message to improve debugging - - raise YunohostError('update_cache_failed') + raise YunohostError('update_apt_cache_failed', sourceslist='\n'.join(_dump_sources_list())) elif warnings: - logger.error(m18n.n('update_cache_warning')) + logger.error(m18n.n('update_apt_cache_warning', sourceslist='\n'.join(_dump_sources_list()))) packages = list(_list_upgradable_apt_packages()) logger.debug(m18n.n('done')) @@ -567,6 +563,17 @@ def _list_upgradable_apt_packages(): } +def _dump_sources_list(): + + filenames = glob("/etc/apt/sources.list") + glob("/etc/apt/sources.list.d/*") + for filename in filenames: + with open(filename, "r") as f: + for line in f.readlines(): + if line.startswith("#") or not line.strip(): + continue + yield filename.replace("/etc/apt/", "") + ":" + line.strip() + + @is_unit_operation() def tools_upgrade(operation_logger, auth, ignore_apps=False, ignore_packages=False): """