moulinette/yunohost_app.py

52 lines
1.3 KiB
Python
Raw Normal View History

2012-11-17 16:29:06 +01:00
# -*- coding: utf-8 -*-
import os
import sys
import json
from urllib import urlopen, urlretrieve
2013-02-10 21:04:15 +01:00
from yunohost import YunoHostError, YunoHostLDAP, win_msg
2012-11-17 16:29:06 +01:00
def app_updatelist(url=None):
2012-11-17 16:29:06 +01:00
"""
Fetch application list
Keyword arguments:
url -- Custom list URL
2012-11-17 16:29:06 +01:00
Returns:
True | YunoHostError
"""
app_path = '/var/cache/yunohost/apps/'
# Create app path if not exists
try: os.listdir(app_path)
except OSError: os.makedirs(app_path)
2013-02-10 21:04:15 +01:00
if not url: url = 'http://fapp.yunohost.org/app/list/raw'
2012-11-17 16:29:06 +01:00
# Get list
2013-02-10 21:04:15 +01:00
try: fetch = urlopen(url)
except IOError: fetch = False
2012-11-17 16:29:06 +01:00
finally:
2013-02-10 21:04:15 +01:00
if fetch and (fetch.code == 200): urlretrieve(url, app_path + 'list.json')
2012-11-17 16:29:06 +01:00
else: raise YunoHostError(1, _("List server connection failed"))
2013-02-10 21:04:15 +01:00
win_msg(_("List updated successfully"))
2012-11-17 16:29:06 +01:00
2013-02-10 21:04:15 +01:00
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