From c57ca2356185628f8450dc95c1c0eed88f752b6c Mon Sep 17 00:00:00 2001 From: Kload Date: Wed, 27 Feb 2013 20:06:17 +0100 Subject: [PATCH] Implement sorted dict (list of tuples) --- yunohost.py | 5 ++++- yunohost_app.py | 12 ++++++------ yunohost_domain.py | 16 ++++++++-------- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/yunohost.py b/yunohost.py index 33c97a60..c01ac94e 100644 --- a/yunohost.py +++ b/yunohost.py @@ -50,7 +50,10 @@ def pretty_print_dict(d, depth=0): elif isinstance(v, list): print((" ") * depth + ("%s: " % str(k))) 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: print((" ") * depth + "%s: %s" % (str(k), str(v))) diff --git a/yunohost_app.py b/yunohost_app.py index d094a000..ae778d07 100644 --- a/yunohost_app.py +++ b/yunohost_app.py @@ -134,12 +134,12 @@ def app_list(offset=None, limit=None, filter=None, raw=False): if raw: list_dict[app_id] = app_info else: - list_dict[app_id] = { - 'Name': app_info['manifest']['name'], - 'Version': app_info['manifest']['version'], - 'Description': app_info['manifest']['description'], - 'Installed': installed_txt - } + list_dict[app_id] = [ + ('Name', app_info['manifest']['name']), + ('Version', app_info['manifest']['version']), + ('Description', app_info['manifest']['description']), + ('Installed', installed_txt) + ] return list_dict diff --git a/yunohost_domain.py b/yunohost_domain.py index 8954c790..de122b6e 100644 --- a/yunohost_domain.py +++ b/yunohost_domain.py @@ -20,7 +20,7 @@ def domain_list(filter=None, limit=None, offset=None): Dict """ with YunoHostLDAP() as yldap: - result_dict = {} + result_list = [] if offset: offset = int(offset) else: offset = 0 if limit: limit = int(limit) @@ -28,17 +28,17 @@ def domain_list(filter=None, limit=None, offset=None): if not filter: filter = 'virtualdomain=*' result = yldap.search('ou=domains,dc=yunohost,dc=org', filter, attrs=['virtualdomain']) - + if result and len(result) > (0 + offset) and limit > 0: i = 0 + offset for domain in result[i:]: if i <= limit: - result_dict[str(i)] = domain['virtualdomain'][0] + result_list.append(domain['virtualdomain'][0]) i += 1 else: raise YunoHostError(167, _("No domain found")) - return result_dict + return { 'Domains': result_list } def domain_add(domains): @@ -55,13 +55,13 @@ def domain_add(domains): attr_dict = { 'objectClass' : ['mailDomain', 'top'] } ip = str(urlopen('http://ip.yunohost.org').read()) now = datetime.datetime.now() - timestamp = str(now.year) + str(now.month) + str(now.day) + timestamp = str(now.year) + str(now.month) + str(now.day) result = [] if not isinstance(domains, list): domains = [ domains ] - - for domain in domains: + + for domain in domains: yldap.validate_uniqueness({ 'virtualdomain' : domain }) attr_dict['virtualdomain'] = domain @@ -107,7 +107,7 @@ def domain_add(domains): win_msg(_("Domain(s) successfully created")) - return { 'Domains' : result } + return { 'Domains' : result } def domain_remove(domains):