From ce5be021d3ad9b0dfa07500dcbecfbdcceb3e96a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Lebleu?= Date: Mon, 13 Oct 2014 17:10:23 +0200 Subject: [PATCH] [fix] Fix app upgrade issue and handle errors in tools_upgrade --- app.py | 2 +- locales/en.json | 1 + locales/fr.json | 1 + tools.py | 17 +++++++++++++---- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/app.py b/app.py index 090d7d05b..62e3e8d5b 100644 --- a/app.py +++ b/app.py @@ -261,7 +261,7 @@ def app_map(app=None, raw=False, user=None): return result -def app_upgrade(auth, app, url=None, file=None): +def app_upgrade(auth, app=[], url=None, file=None): """ Upgrade app diff --git a/locales/en.json b/locales/en.json index 56da1da88..65cf911fb 100644 --- a/locales/en.json +++ b/locales/en.json @@ -20,6 +20,7 @@ "custom_app_url_required" : "You must provide an URL to upgrade your custom app {:s}", "app_recent_version_required" : "{:s} requires a more recent version of the moulinette", "app_upgraded" : "{:s} successfully upgraded", + "app_upgrade_failed" : "Unable to upgrade all apps", "app_id_invalid" : "Invalid app id", "app_already_installed" : "{:s} is already installed", "app_removed" : "{:s} successfully removed", diff --git a/locales/fr.json b/locales/fr.json index 874485d3f..375ece04d 100644 --- a/locales/fr.json +++ b/locales/fr.json @@ -20,6 +20,7 @@ "custom_app_url_required" : "Vous devez spécifier une URL pour mettre à jour votre application locale {:s}", "app_recent_version_required" : "{:s} nécessite une version plus récente de la moulinette", "app_upgraded" : "{:s} mis à jour avec succès", + "app_upgrade_failed" : "Impossible de mettre à jour toutes les applications", "app_id_invalid" : "Id d'application incorrect", "app_already_installed" : "{:s} est déjà installé", "app_removed" : "{:s} supprimé avec succès", diff --git a/tools.py b/tools.py index 5667c4d09..b58cb5149 100644 --- a/tools.py +++ b/tools.py @@ -31,6 +31,7 @@ import getpass import requests import json import errno +import logging import apt import apt.progress @@ -330,7 +331,7 @@ def tools_postinstall(domain, password, dyndns=False): # Enable iptables at boot time os.system('update-rc.d yunohost-firewall defaults') - + os.system('touch /etc/yunohost/installed') msignals.display(m18n.n('yunohost_configured'), 'success') @@ -416,6 +417,9 @@ def tools_upgrade(auth, ignore_apps=False, ignore_packages=False): """ from yunohost.app import app_upgrade + failure = False + + # Retrieve interface is_api = True if msettings.get('interface') == 'api' else False if not ignore_packages: @@ -449,6 +453,7 @@ def tools_upgrade(auth, ignore_apps=False, ignore_packages=False): cache.commit(apt.progress.text.AcquireProgress(), apt.progress.base.InstallProgress()) except Exception as e: + failure = True logging.warning('unable to upgrade packages: %s' % str(e)) msignals.display(m18n.n('packages_upgrade_failed'), 'error') else: @@ -459,11 +464,15 @@ def tools_upgrade(auth, ignore_apps=False, ignore_packages=False): if not ignore_apps: try: app_upgrade(auth) - except: pass + except Exception as e: + failure = True + logging.warning('unable to upgrade apps: %s' % str(e)) + msignals.display(m18n.n('app_upgrade_failed'), 'error') - msignals.display(m18n.n('system_upgraded'), 'success') + if not failure: + msignals.display(m18n.n('system_upgraded'), 'success') # Return API logs if it is an API call - if msettings.get('interface') == 'api': + if is_api: from yunohost.service import service_log return { "log": service_log('yunohost-api', number="100").values()[0] }