Implement sorted dict (list of tuples)

This commit is contained in:
Kload 2013-02-27 20:06:17 +01:00
parent c1431900b4
commit c57ca23561
3 changed files with 18 additions and 15 deletions

View file

@ -50,7 +50,10 @@ def pretty_print_dict(d, depth=0):
elif isinstance(v, list): elif isinstance(v, list):
print((" ") * depth + ("%s: " % str(k))) print((" ") * depth + ("%s: " % str(k)))
for value in v: for value in v:
print((" ") * (depth+1) + "- " +str(value)) if isinstance(value, tuple):
pretty_print_dict({value[0]: value[1]}, depth+1)
else:
print((" ") * (depth+1) + "- " +str(value))
else: else:
print((" ") * depth + "%s: %s" % (str(k), str(v))) print((" ") * depth + "%s: %s" % (str(k), str(v)))

View file

@ -134,12 +134,12 @@ def app_list(offset=None, limit=None, filter=None, raw=False):
if raw: if raw:
list_dict[app_id] = app_info list_dict[app_id] = app_info
else: else:
list_dict[app_id] = { list_dict[app_id] = [
'Name': app_info['manifest']['name'], ('Name', app_info['manifest']['name']),
'Version': app_info['manifest']['version'], ('Version', app_info['manifest']['version']),
'Description': app_info['manifest']['description'], ('Description', app_info['manifest']['description']),
'Installed': installed_txt ('Installed', installed_txt)
} ]
return list_dict return list_dict

View file

@ -20,7 +20,7 @@ def domain_list(filter=None, limit=None, offset=None):
Dict Dict
""" """
with YunoHostLDAP() as yldap: with YunoHostLDAP() as yldap:
result_dict = {} result_list = []
if offset: offset = int(offset) if offset: offset = int(offset)
else: offset = 0 else: offset = 0
if limit: limit = int(limit) if limit: limit = int(limit)
@ -33,12 +33,12 @@ def domain_list(filter=None, limit=None, offset=None):
i = 0 + offset i = 0 + offset
for domain in result[i:]: for domain in result[i:]:
if i <= limit: if i <= limit:
result_dict[str(i)] = domain['virtualdomain'][0] result_list.append(domain['virtualdomain'][0])
i += 1 i += 1
else: else:
raise YunoHostError(167, _("No domain found")) raise YunoHostError(167, _("No domain found"))
return result_dict return { 'Domains': result_list }
def domain_add(domains): def domain_add(domains):