diff --git a/locales/en.json b/locales/en.json index 41c3c2098..9b5acd87f 100644 --- a/locales/en.json +++ b/locales/en.json @@ -30,6 +30,7 @@ "app_unsupported_remote_type": "Unsupported remote type used for the app", "app_upgrade_failed": "Unable to upgrade {app:s}", "app_upgraded": "{app:s} has been upgraded", + "app_already_up_to_date": "{app:s} is already up to date", "appslist_fetched": "The application list {appslist:s} has been fetched", "appslist_removed": "The application list {appslist:s} has been removed", "appslist_unknown": "Application list {appslist:s} unknown.", diff --git a/src/yunohost/app.py b/src/yunohost/app.py index f3f945d1e..f25d35b72 100644 --- a/src/yunohost/app.py +++ b/src/yunohost/app.py @@ -332,6 +332,19 @@ def app_info(app, show_status=False, raw=False): if raw: ret = app_list(filter=app, raw=True)[app] ret['settings'] = _get_app_settings(app) + + # Determine upgradability + local_update_time = ret['settings'].get('update_time', ret['settings']['install_time']) + + if 'lastUpdate' not in ret or 'git' not in ret: + upgradable = "url_required" + elif ret['lastUpdate'] > local_update_time: + upgradable = "yes" + else: + upgradable = "no" + + ret['upgradable'] = upgradable + return ret app_setting_path = APPS_SETTING_PATH + app @@ -425,16 +438,19 @@ def app_upgrade(auth, app=[], url=None, file=None): upgraded_apps = [] + apps = app + user_specified_list = True # If no app is specified, upgrade all apps - if not app: + if not apps: if not url and not file: - app = [app["id"] for app in app_list(installed=True)["apps"]] + apps = [app["id"] for app in app_list(installed=True)["apps"]] + user_specified_list = False elif not isinstance(app, list): - app = [app] + apps = [app] logger.info("Upgrading apps %s", ", ".join(app)) - for app_instance_name in app: + for app_instance_name in apps: installed = _is_installed(app_instance_name) if not installed: raise MoulinetteError(errno.ENOPKG, @@ -445,18 +461,18 @@ def app_upgrade(auth, app=[], url=None, file=None): app_dict = app_info(app_instance_name, raw=True) - locale_update_time = app_dict['settings'].get('update_time', app_dict['settings']['install_time']) - if file: manifest, extracted_app_folder = _extract_app_from_file(file) elif url: manifest, extracted_app_folder = _fetch_app_from_git(url) - elif 'lastUpdate' not in app_dict or 'git' not in app_dict: + elif app_dict["upgradable"] == "url_required": logger.warning(m18n.n('custom_app_url_required', app=app_instance_name)) continue - elif app_dict['lastUpdate'] > locale_update_time: + elif app_dict["upgradable"] == "yes": manifest, extracted_app_folder = _fetch_app_from_git(app_instance_name) else: + if user_specified_list: + logger.success(m18n.n('app_already_up_to_date', app=app_instance_name)) continue # Check requirements @@ -516,7 +532,6 @@ def app_upgrade(auth, app=[], url=None, file=None): logger.success(m18n.n('upgrade_complete')) - def app_install(auth, app, label=None, args=None, no_remove_on_failure=False): """ Install apps diff --git a/src/yunohost/tools.py b/src/yunohost/tools.py index 805eb2c45..f5fc2fc01 100644 --- a/src/yunohost/tools.py +++ b/src/yunohost/tools.py @@ -356,6 +356,7 @@ def tools_update(ignore_apps=False, ignore_packages=False): ignore_packages -- Ignore apt cache update and changelog """ + # "packages" will list upgradable packages packages = [] if not ignore_packages: cache = apt.Cache() @@ -365,8 +366,6 @@ def tools_update(ignore_apps=False, ignore_packages=False): if not cache.update(): raise MoulinetteError(errno.EPERM, m18n.n('update_cache_failed')) - logger.info(m18n.n('done')) - cache.open(None) cache.upgrade(True) @@ -377,37 +376,27 @@ def tools_update(ignore_apps=False, ignore_packages=False): 'fullname': pkg.fullname, 'changelog': pkg.get_changelog() }) + logger.info(m18n.n('done')) + # "apps" will list upgradable packages apps = [] if not ignore_apps: try: app_fetchlist() except MoulinetteError: + # FIXME : silent exception !? pass - app_list = os.listdir(APPS_SETTING_PATH) - if len(app_list) > 0: - for app_id in app_list: - if '__' in app_id: - original_app_id = app_id[:app_id.index('__')] - else: - original_app_id = app_id - current_app_dict = app_info(app_id, raw=True) - new_app_dict = app_info(original_app_id, raw=True) + app_list_installed = os.listdir(APPS_SETTING_PATH) + for app_id in app_list_installed: - # Custom app - if new_app_dict is None or 'lastUpdate' not in new_app_dict or 'git' not in new_app_dict: - continue + app_dict = app_info(app_id, raw=True) - if (new_app_dict['lastUpdate'] > current_app_dict['lastUpdate']) \ - or ('update_time' not in current_app_dict['settings'] \ - and (new_app_dict['lastUpdate'] > current_app_dict['settings']['install_time'])) \ - or ('update_time' in current_app_dict['settings'] \ - and (new_app_dict['lastUpdate'] > current_app_dict['settings']['update_time'])): - apps.append({ - 'id': app_id, - 'label': current_app_dict['settings']['label'] - }) + if app_dict["upgradable"] == "yes": + apps.append({ + 'id': app_id, + 'label': app_dict['settings']['label'] + }) if len(apps) == 0 and len(packages) == 0: logger.info(m18n.n('packages_no_upgrade'))