[ux] better error message for not installed app

This commit is contained in:
Laurent Peuch 2019-07-30 01:27:50 +02:00
parent 933bf99052
commit 98d6735586
2 changed files with 26 additions and 9 deletions

View file

@ -30,7 +30,7 @@
"app_no_upgrade": "No apps to upgrade", "app_no_upgrade": "No apps to upgrade",
"app_not_upgraded": "The following apps were not upgraded: {apps}", "app_not_upgraded": "The following apps were not upgraded: {apps}",
"app_not_correctly_installed": "{app:s} seems to be incorrectly installed", "app_not_correctly_installed": "{app:s} seems to be incorrectly installed",
"app_not_installed": "{app:s} is not installed", "app_not_installed": "The application '{app:s}' is not installed. Here is the list of all installed apps: {all_apps}",
"app_not_properly_removed": "{app:s} has not been properly removed", "app_not_properly_removed": "{app:s} has not been properly removed",
"app_package_need_update": "The app {app} package needs to be updated to follow YunoHost changes", "app_package_need_update": "The app {app} package needs to be updated to follow YunoHost changes",
"app_removed": "{app:s} has been removed", "app_removed": "{app:s} has been removed",

View file

@ -343,7 +343,7 @@ def app_info(app, show_status=False, raw=False):
""" """
if not _is_installed(app): if not _is_installed(app):
raise YunohostError('app_not_installed', app=app) raise YunohostError('app_not_installed', app=app, all_apps=_get_all_installed_apps_id())
app_setting_path = APPS_SETTING_PATH + app app_setting_path = APPS_SETTING_PATH + app
@ -409,7 +409,7 @@ def app_map(app=None, raw=False, user=None):
if app is not None: if app is not None:
if not _is_installed(app): if not _is_installed(app):
raise YunohostError('app_not_installed', app=app) raise YunohostError('app_not_installed', app=app, all_apps=_get_all_installed_apps_id())
apps = [app, ] apps = [app, ]
else: else:
apps = os.listdir(APPS_SETTING_PATH) apps = os.listdir(APPS_SETTING_PATH)
@ -462,7 +462,7 @@ def app_change_url(operation_logger, app, domain, path):
installed = _is_installed(app) installed = _is_installed(app)
if not installed: if not installed:
raise YunohostError('app_not_installed', app=app) raise YunohostError('app_not_installed', app=app, all_apps=_get_all_installed_apps_id())
if not os.path.exists(os.path.join(APPS_SETTING_PATH, app, "scripts", "change_url")): if not os.path.exists(os.path.join(APPS_SETTING_PATH, app, "scripts", "change_url")):
raise YunohostError("app_change_no_change_url_script", app_name=app) raise YunohostError("app_change_no_change_url_script", app_name=app)
@ -607,7 +607,7 @@ def app_upgrade(app=[], url=None, file=None):
# Abort if any of those app is in fact not installed.. # Abort if any of those app is in fact not installed..
for app in [app for app in apps if not _is_installed(app)]: for app in [app for app in apps if not _is_installed(app)]:
raise YunohostError('app_not_installed', app=app) raise YunohostError('app_not_installed', app=app, all_apps=_get_all_installed_apps_id())
if len(apps) == 0: if len(apps) == 0:
raise YunohostError('app_no_upgrade') raise YunohostError('app_no_upgrade')
@ -971,7 +971,7 @@ def app_remove(operation_logger, app):
from yunohost.hook import hook_exec, hook_remove, hook_callback from yunohost.hook import hook_exec, hook_remove, hook_callback
from yunohost.permission import permission_remove, permission_sync_to_user from yunohost.permission import permission_remove, permission_sync_to_user
if not _is_installed(app): if not _is_installed(app):
raise YunohostError('app_not_installed', app=app) raise YunohostError('app_not_installed', app=app, all_apps=_get_all_installed_apps_id())
operation_logger.start() operation_logger.start()
@ -1443,7 +1443,7 @@ def app_ssowatconf():
def app_change_label(app, new_label): def app_change_label(app, new_label):
installed = _is_installed(app) installed = _is_installed(app)
if not installed: if not installed:
raise YunohostError('app_not_installed', app=app) raise YunohostError('app_not_installed', app=app, all_apps=_get_all_installed_apps_id())
app_setting(app, "label", value=new_label) app_setting(app, "label", value=new_label)
@ -1606,7 +1606,7 @@ def app_config_apply(app, args):
installed = _is_installed(app) installed = _is_installed(app)
if not installed: if not installed:
raise YunohostError('app_not_installed', app=app) raise YunohostError('app_not_installed', app=app, all_apps=_get_all_installed_apps_id())
config_panel = _get_app_config_panel(app) config_panel = _get_app_config_panel(app)
config_script = os.path.join(APPS_SETTING_PATH, app, 'scripts', 'config') config_script = os.path.join(APPS_SETTING_PATH, app, 'scripts', 'config')
@ -1653,6 +1653,23 @@ def app_config_apply(app, args):
logger.success("Config updated as expected") logger.success("Config updated as expected")
def _get_all_installed_apps_id():
"""
Return something like:
' * app1
* app2
* ...'
"""
all_apps_ids = [x["id"] for x in app_list(installed=True)["apps"]]
all_apps_ids = sorted(all_apps_ids)
all_apps_ids_formatted = "\n * ".join(all_apps_ids)
all_apps_ids_formatted = "\n * " + all_apps_ids_formatted
return all_apps_ids_formatted
def _get_app_actions(app_id): def _get_app_actions(app_id):
"Get app config panel stored in json or in toml" "Get app config panel stored in json or in toml"
actions_toml_path = os.path.join(APPS_SETTING_PATH, app_id, 'actions.toml') actions_toml_path = os.path.join(APPS_SETTING_PATH, app_id, 'actions.toml')
@ -1873,7 +1890,7 @@ def _get_app_settings(app_id):
""" """
if not _is_installed(app_id): if not _is_installed(app_id):
raise YunohostError('app_not_installed', app=app_id) raise YunohostError('app_not_installed', app=app_id, all_apps=_get_all_installed_apps_id())
try: try:
with open(os.path.join( with open(os.path.join(
APPS_SETTING_PATH, app_id, 'settings.yml')) as f: APPS_SETTING_PATH, app_id, 'settings.yml')) as f: