mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
[mod] try to clean a bit app_list code
This commit is contained in:
parent
cc44512539
commit
db601a412d
1 changed files with 65 additions and 61 deletions
|
@ -157,17 +157,12 @@ def app_list(offset=None, limit=None, filter=None, raw=False, installed=False, w
|
||||||
with_backup -- Return only apps with backup feature (force --installed filter)
|
with_backup -- Return only apps with backup feature (force --installed filter)
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if offset: offset = int(offset)
|
offset = int(offset) if offset else 0
|
||||||
else: offset = 0
|
limit = int(limit) if limit else 1000
|
||||||
if limit: limit = int(limit)
|
|
||||||
else: limit = 1000
|
|
||||||
installed = with_backup or installed
|
installed = with_backup or installed
|
||||||
|
|
||||||
app_dict = {}
|
app_dict = {}
|
||||||
if raw:
|
list_dict = {} if raw else []
|
||||||
list_dict = {}
|
|
||||||
else:
|
|
||||||
list_dict = []
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
applists = app_listlists()['lists']
|
applists = app_listlists()['lists']
|
||||||
|
@ -178,10 +173,12 @@ def app_list(offset=None, limit=None, filter=None, raw=False, installed=False, w
|
||||||
|
|
||||||
for applist in applists:
|
for applist in applists:
|
||||||
with open(os.path.join(REPO_PATH, applist + '.json')) as json_list:
|
with open(os.path.join(REPO_PATH, applist + '.json')) as json_list:
|
||||||
for app, info in json.loads(str(json_list.read())).items():
|
for app, info in json.load(json_list).items():
|
||||||
if app not in app_dict:
|
if app in app_dict:
|
||||||
info['repository'] = applist
|
continue
|
||||||
app_dict[app] = info
|
|
||||||
|
info['repository'] = applist
|
||||||
|
app_dict[app] = info
|
||||||
|
|
||||||
for app in os.listdir(APPS_SETTING_PATH):
|
for app in os.listdir(APPS_SETTING_PATH):
|
||||||
if app not in app_dict:
|
if app not in app_dict:
|
||||||
|
@ -192,63 +189,70 @@ def app_list(offset=None, limit=None, filter=None, raw=False, installed=False, w
|
||||||
app_dict[app] = app_dict[original_app]
|
app_dict[app] = app_dict[original_app]
|
||||||
continue
|
continue
|
||||||
with open( APPS_SETTING_PATH + app +'/manifest.json') as json_manifest:
|
with open( APPS_SETTING_PATH + app +'/manifest.json') as json_manifest:
|
||||||
app_dict[app] = {"manifest":json.loads(str(json_manifest.read()))}
|
app_dict[app] = {"manifest": json.loads(json_manifest)}
|
||||||
|
|
||||||
|
|
||||||
app_dict[app]['repository'] = None
|
app_dict[app]['repository'] = None
|
||||||
|
|
||||||
if len(app_dict) > (0 + offset) and limit > 0:
|
if not (len(app_dict) > (0 + offset) and limit > 0):
|
||||||
sorted_app_dict = {}
|
return {'apps': list_dict} if not raw else list_dict
|
||||||
for sorted_keys in sorted(app_dict.keys())[offset:]:
|
|
||||||
sorted_app_dict[sorted_keys] = app_dict[sorted_keys]
|
|
||||||
|
|
||||||
i = 0
|
sorted_app_dict = {}
|
||||||
for app_id, app_info_dict in sorted_app_dict.items():
|
for sorted_keys in sorted(app_dict.keys())[offset:]:
|
||||||
if i < limit:
|
sorted_app_dict[sorted_keys] = app_dict[sorted_keys]
|
||||||
if (filter and ((filter in app_id) or (filter in app_info_dict['manifest']['name']))) or not filter:
|
|
||||||
app_installed = _is_installed(app_id)
|
|
||||||
|
|
||||||
# Only installed apps filter
|
i = 0
|
||||||
if installed and not app_installed:
|
for app_id, app_info_dict in sorted_app_dict.items():
|
||||||
continue
|
if i >= limit:
|
||||||
|
break
|
||||||
|
|
||||||
# Filter only apps with backup and restore scripts
|
if not ((filter and ((filter in app_id) or (filter in app_info_dict['manifest']['name']))) or not filter):
|
||||||
if with_backup and (
|
continue
|
||||||
not os.path.isfile(APPS_SETTING_PATH + app_id + '/scripts/backup') or
|
|
||||||
not os.path.isfile(APPS_SETTING_PATH + app_id + '/scripts/restore')
|
|
||||||
):
|
|
||||||
continue
|
|
||||||
|
|
||||||
if raw:
|
app_installed = _is_installed(app_id)
|
||||||
app_info_dict['installed'] = app_installed
|
|
||||||
if app_installed:
|
|
||||||
app_info_dict['status'] = _get_app_status(app_id)
|
|
||||||
|
|
||||||
# dirty: we used to have manifest containing multi_instance value in form of a string
|
# Only installed apps filter
|
||||||
# but we've switched to bool, this line ensure retrocompatibility
|
if installed and not app_installed:
|
||||||
app_info_dict["manifest"]["multi_instance"] = is_true(app_info_dict["manifest"].get("multi_instance", False))
|
continue
|
||||||
|
|
||||||
list_dict[app_id] = app_info_dict
|
# Filter only apps with backup and restore scripts
|
||||||
else:
|
if with_backup and (
|
||||||
label = None
|
not os.path.isfile(APPS_SETTING_PATH + app_id + '/scripts/backup') or
|
||||||
if app_installed:
|
not os.path.isfile(APPS_SETTING_PATH + app_id + '/scripts/restore')
|
||||||
app_info_dict_raw = app_info(app=app_id, raw=True)
|
):
|
||||||
label = app_info_dict_raw['settings']['label']
|
continue
|
||||||
list_dict.append({
|
|
||||||
'id': app_id,
|
if raw:
|
||||||
'name': app_info_dict['manifest']['name'],
|
app_info_dict['installed'] = app_installed
|
||||||
'label': label,
|
if app_installed:
|
||||||
'description': _value_for_locale(
|
app_info_dict['status'] = _get_app_status(app_id)
|
||||||
app_info_dict['manifest']['description']),
|
|
||||||
# FIXME: Temporarly allow undefined license
|
# dirty: we used to have manifest containing multi_instance value in form of a string
|
||||||
'license': app_info_dict['manifest'].get('license',
|
# but we've switched to bool, this line ensure retrocompatibility
|
||||||
m18n.n('license_undefined')),
|
app_info_dict["manifest"]["multi_instance"] = is_true(app_info_dict["manifest"].get("multi_instance", False))
|
||||||
'installed': app_installed
|
|
||||||
})
|
list_dict[app_id] = app_info_dict
|
||||||
i += 1
|
|
||||||
else:
|
else:
|
||||||
break
|
label = None
|
||||||
if not raw:
|
if app_installed:
|
||||||
list_dict = { 'apps': list_dict }
|
app_info_dict_raw = app_info(app=app_id, raw=True)
|
||||||
return list_dict
|
label = app_info_dict_raw['settings']['label']
|
||||||
|
|
||||||
|
list_dict.append({
|
||||||
|
'id': app_id,
|
||||||
|
'name': app_info_dict['manifest']['name'],
|
||||||
|
'label': label,
|
||||||
|
'description': _value_for_locale(app_info_dict['manifest']['description']),
|
||||||
|
# FIXME: Temporarly allow undefined license
|
||||||
|
'license': app_info_dict['manifest'].get('license', m18n.n('license_undefined')),
|
||||||
|
'installed': app_installed
|
||||||
|
})
|
||||||
|
|
||||||
|
i += 1
|
||||||
|
|
||||||
|
|
||||||
|
return {'apps': list_dict} if not raw else list_dict
|
||||||
|
|
||||||
|
|
||||||
def app_info(app, show_status=False, raw=False):
|
def app_info(app, show_status=False, raw=False):
|
||||||
|
|
Loading…
Add table
Reference in a new issue