1
0
Fork 0
mirror of https://github.com/YunoHost/moulinette.git synced 2024-09-03 20:06:31 +02:00

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):
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)))

View file

@ -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

View file

@ -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):