mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
Win messages in json
This commit is contained in:
parent
fee3c7c47c
commit
4b12b7a4c4
2 changed files with 20 additions and 9 deletions
18
parse_args
18
parse_args
|
@ -38,7 +38,7 @@ if not __debug__:
|
|||
gettext.install('YunoHost')
|
||||
|
||||
try:
|
||||
from yunohost import YunoHostError, YunoHostLDAP, str_to_func, colorize, pretty_print_dict, display_error, validate
|
||||
from yunohost import YunoHostError, YunoHostLDAP, str_to_func, colorize, pretty_print_dict, display_error, validate, win
|
||||
except ImportError:
|
||||
sys.stderr.write('Error: Yunohost CLI Require YunoHost lib\n')
|
||||
sys.exit(1)
|
||||
|
@ -200,15 +200,21 @@ def main():
|
|||
#print(_("Not (yet) implemented function"))
|
||||
#return 1
|
||||
except YunoHostError, error:
|
||||
display_error(error)
|
||||
display_error(error, json_print)
|
||||
return error.code
|
||||
else:
|
||||
if result is None:
|
||||
pass
|
||||
elif os.isatty(1) and not json_print:
|
||||
if json_print or not os.isatty(1):
|
||||
if result is None:
|
||||
result = {}
|
||||
if len(win) > 0:
|
||||
result['success'] = []
|
||||
for msg in win:
|
||||
result['success'].append(msg)
|
||||
print(json.dumps(result))
|
||||
elif result is not None:
|
||||
pretty_print_dict(result)
|
||||
else:
|
||||
print(json.dumps(result))
|
||||
pass
|
||||
|
||||
return 0
|
||||
|
||||
|
|
11
yunohost.py
11
yunohost.py
|
@ -17,6 +17,7 @@ import string
|
|||
if not __debug__:
|
||||
import traceback
|
||||
|
||||
win = []
|
||||
lemon_tmp_conf = '/tmp/tmplemonconf'
|
||||
|
||||
def random_password(length=8):
|
||||
|
@ -87,8 +88,12 @@ def win_msg(astr):
|
|||
astr -- Win message to display
|
||||
|
||||
"""
|
||||
global win
|
||||
if os.isatty(1):
|
||||
print('\n' + colorize(_("Success: "), 'green') + astr + '\n')
|
||||
else:
|
||||
win.append(astr)
|
||||
|
||||
|
||||
|
||||
def str_to_func(astr):
|
||||
|
@ -175,17 +180,17 @@ def get_required_args(args, required_args, password=False):
|
|||
return args
|
||||
|
||||
|
||||
def display_error(error):
|
||||
def display_error(error, json_print=False):
|
||||
"""
|
||||
Nice error displaying
|
||||
|
||||
"""
|
||||
if not __debug__ :
|
||||
traceback.print_exc()
|
||||
if os.isatty(1):
|
||||
if os.isatty(1) and not json_print:
|
||||
print('\n' + colorize(_("Error: "), 'red') + error.message)
|
||||
else:
|
||||
print(json.dumps({ 'error' : error.message }))
|
||||
print(json.dumps({ error.code : error.message }))
|
||||
|
||||
|
||||
def lemon_configuration(conf_dict):
|
||||
|
|
Loading…
Reference in a new issue