diff --git a/yunohost_app.py b/yunohost_app.py index 1cbdd06d..8c98c1d4 100644 --- a/yunohost_app.py +++ b/yunohost_app.py @@ -4,7 +4,7 @@ import os import sys import json from urllib import urlopen, urlretrieve -from yunohost import YunoHostError, YunoHostLDAP +from yunohost import YunoHostError, YunoHostLDAP, win_msg def app_updatelist(url=None): """ @@ -23,19 +23,29 @@ def app_updatelist(url=None): try: os.listdir(app_path) except OSError: os.makedirs(app_path) - if url: list_url = url - else: list_url = 'http://fapp.yunohost.org/app/list/raw' + if not url: url = 'http://fapp.yunohost.org/app/list/raw' # Get list - try: info_fetch = urlopen(list_url) - except IOError: info_fetch = False + try: fetch = urlopen(url) + except IOError: fetch = False finally: - if info_fetch and (info_fetch.code == 200): urlretrieve(list_url, app_path + str(infos['lastUpdate']) + '.json') + if fetch and (fetch.code == 200): urlretrieve(url, app_path + 'list.json') else: raise YunoHostError(1, _("List server connection failed")) - return True + win_msg(_("List updated successfully")) -def app_list(args): - info_dict = json.loads(str(info_fetch.read())) - pass +def app_list(filter=None, fields=None, offset=None, limit=None): + with open('/var/cache/yunohost/apps/list.json') as json_list: + app_dict = json.loads(str(json_list.read())) + + list_dict = {} + + for app_id, app_info in app_dict.items(): + list_dict[app_id] = { + 'Name': app_info['manifest']['name'], + 'Version': app_info['manifest']['version'], + 'Description': app_info['manifest']['description'] + } + + return list_dict