[mod] directly use python to retreive json list

This commit is contained in:
Laurent Peuch 2016-06-12 00:41:32 +02:00
parent c4cecfcea5
commit d9081bddef

View file

@ -36,6 +36,7 @@ import urlparse
import errno import errno
import subprocess import subprocess
from collections import OrderedDict from collections import OrderedDict
from urllib import urlretrieve
from moulinette.core import MoulinetteError from moulinette.core import MoulinetteError
from moulinette.utils.log import getActionLogger from moulinette.utils.log import getActionLogger
@ -100,14 +101,13 @@ def app_fetchlist(url=None, name=None):
raise MoulinetteError(errno.EINVAL, raise MoulinetteError(errno.EINVAL,
m18n.n('custom_appslist_name_required')) m18n.n('custom_appslist_name_required'))
list_file = '%s/%s.json' % (repo_path, name) try:
if os.system('wget "%s" -O "%s.tmp"' % (url, list_file)) != 0: urlretrieve(url, '%s/%s.json' % (repo_path, name))
os.remove('%s.tmp' % list_file) except Exception as e:
# I don't know how to put e into the MoulinetteError stuff
print e
raise MoulinetteError(errno.EBADR, m18n.n('appslist_retrieve_error')) raise MoulinetteError(errno.EBADR, m18n.n('appslist_retrieve_error'))
# Rename fetched temp list
os.rename('%s.tmp' % list_file, list_file)
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)) 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')) logger.success(m18n.n('appslist_fetched'))