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}'",
"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…",

View file

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