mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
Printer & Nonefunc handle
This commit is contained in:
parent
f0d4b918b9
commit
4854365576
2 changed files with 21 additions and 11 deletions
|
@ -29,11 +29,16 @@ def colorize(astr, color):
|
||||||
|
|
||||||
def pretty_print_dict(d, depth=0):
|
def pretty_print_dict(d, depth=0):
|
||||||
for k,v in sorted(d.items(), key=lambda x: x[0]):
|
for k,v in sorted(d.items(), key=lambda x: x[0]):
|
||||||
|
k = colorize(k, 'purple')
|
||||||
if isinstance(v, dict):
|
if isinstance(v, dict):
|
||||||
print (" ")*depth + ("%s: " % k)
|
print((" ")*depth + ("%s: " % k))
|
||||||
pretty_print_dict(v, depth+1)
|
pretty_print_dict(v, depth+1)
|
||||||
|
if isinstance(v, list):
|
||||||
|
print((" ")*depth + ("%s: " % k))
|
||||||
|
for value in v:
|
||||||
|
print((" ")*(depth+1) + "- " + value)
|
||||||
else:
|
else:
|
||||||
print (" ")*depth + "%s: %s" % (colorize(k, 'purple'), v)
|
print((" ")*depth + "%s: %s" % (k, v))
|
||||||
|
|
||||||
def win_msg(astr):
|
def win_msg(astr):
|
||||||
"""
|
"""
|
||||||
|
@ -68,7 +73,8 @@ def str_to_func(astr):
|
||||||
try:
|
try:
|
||||||
func = getattr(mod, function)
|
func = getattr(mod, function)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
raise YunoHostError(168, _('Function is not defined'))
|
#raise YunoHostError(168, _('Function is not defined'))
|
||||||
|
return None
|
||||||
else:
|
else:
|
||||||
return func
|
return func
|
||||||
|
|
||||||
|
|
20
yunohost
20
yunohost
|
@ -73,7 +73,7 @@ action_dict = {
|
||||||
'action' : 'version',
|
'action' : 'version',
|
||||||
'version' : '%(prog)s ' + __version__,
|
'version' : '%(prog)s ' + __version__,
|
||||||
},
|
},
|
||||||
}
|
},
|
||||||
#############################
|
#############################
|
||||||
# User #
|
# User #
|
||||||
#############################
|
#############################
|
||||||
|
@ -112,6 +112,9 @@ action_dict = {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
'info' : {
|
||||||
|
'help' : 'Get user informations',
|
||||||
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'domain' : {
|
'domain' : {
|
||||||
|
@ -171,13 +174,14 @@ def dict_to_args(action_dict):
|
||||||
func=str_to_func('yunohost_' + category + '.'
|
func=str_to_func('yunohost_' + category + '.'
|
||||||
+ category + '_' + action))
|
+ category + '_' + action))
|
||||||
# Add arguments
|
# Add arguments
|
||||||
for arg_name, arg_params in action_params['arguments'].items():
|
if 'arguments' in action_params:
|
||||||
if arg_params['full']:
|
for arg_name, arg_params in action_params['arguments'].items():
|
||||||
arg_fullname = arg_params['full']
|
if arg_params['full']:
|
||||||
del arg_params['full']
|
arg_fullname = arg_params['full']
|
||||||
parsers[category + '_' + action].add_argument(arg_name, arg_fullname, **arg_params)
|
del arg_params['full']
|
||||||
else:
|
parsers[category + '_' + action].add_argument(arg_name, arg_fullname, **arg_params)
|
||||||
parsers[category + '_' + action].add_argument(arg_name, **arg_params)
|
else:
|
||||||
|
parsers[category + '_' + action].add_argument(arg_name, **arg_params)
|
||||||
|
|
||||||
args = parsers['general'].parse_args()
|
args = parsers['general'].parse_args()
|
||||||
return args
|
return args
|
||||||
|
|
Loading…
Reference in a new issue