From 730156dd92bbd1b0c479821ffc829e8d4f3d2019 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Mon, 6 Feb 2017 12:54:32 -0500 Subject: [PATCH] Using request insteqd of urlretrieve, to have timeout --- src/yunohost/app.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/yunohost/app.py b/src/yunohost/app.py index d5874d1e4..3f2351318 100644 --- a/src/yunohost/app.py +++ b/src/yunohost/app.py @@ -35,8 +35,8 @@ import socket import urlparse import errno import subprocess +import requests from collections import OrderedDict -from urllib import urlretrieve from moulinette.core import MoulinetteError from moulinette.utils.log import getActionLogger @@ -100,12 +100,18 @@ def app_fetchlist(url=None, name=None): raise MoulinetteError(errno.EINVAL, m18n.n('custom_appslist_name_required')) + # Download file try: - logger.info("Fetching app list '%s' from %s ...", name, url) - urlretrieve(url, '%s/%s.json' % (repo_path, name)) + applist = requests.get(url, timeout=30).text except Exception as e: - raise MoulinetteError(errno.EBADR, m18n.n('appslist_retrieve_error'), error=str(e)) + raise MoulinetteError(errno.EBADR, m18n.n('appslist_retrieve_error', error=str(e))) + # Write app list to file + list_file = '%s/%s.json' % (repo_path, name) + with open(list_file, "w") as f: + f.write(applist) + + # Setup a cron job to re-fetch the list at midnight open("/etc/cron.d/yunohost-applist-%s" % name, "w").write('00 00 * * * root yunohost app fetchlist -u %s -n %s > /dev/null 2>&1\n' % (url, name)) logger.success(m18n.n('appslist_fetched'))