Dump sources list in error message to help debugging

This commit is contained in:
Alexandre Aubin 2019-03-27 18:08:46 +01:00
parent e298838949
commit 162eeb7e06
2 changed files with 16 additions and 9 deletions

View file

@ -482,8 +482,8 @@
"unit_unknown": "Unknown unit '{unit:s}'", "unit_unknown": "Unknown unit '{unit:s}'",
"unlimit": "No quota", "unlimit": "No quota",
"unrestore_app": "App '{app:s}' will not be restored", "unrestore_app": "App '{app:s}' will not be restored",
"update_cache_failed": "Unable to update 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_cache_warning": "Some errors happened while updating APT cache", "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…", "updating_apt_cache": "Fetching available upgrades for system packages…",
"upgrade_complete": "Upgrade complete", "upgrade_complete": "Upgrade complete",
"upgrading_packages": "Upgrading packages…", "upgrading_packages": "Upgrading packages…",

View file

@ -30,6 +30,7 @@ import json
import subprocess import subprocess
import pwd import pwd
import socket import socket
from glob import glob
from xmlrpclib import Fault from xmlrpclib import Fault
from importlib import import_module from importlib import import_module
from collections import OrderedDict 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) returncode = call_async_output(command, callbacks, shell=True)
if returncode != 0: if returncode != 0:
raise YunohostError('update_apt_cache_failed', sourceslist='\n'.join(_dump_sources_list()))
# 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')
elif warnings: 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()) packages = list(_list_upgradable_apt_packages())
logger.debug(m18n.n('done')) 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() @is_unit_operation()
def tools_upgrade(operation_logger, auth, ignore_apps=False, ignore_packages=False): def tools_upgrade(operation_logger, auth, ignore_apps=False, ignore_packages=False):
""" """