From 2ad1a32419d8d82a4068d85734e5dfc03158bae9 Mon Sep 17 00:00:00 2001 From: Kload Date: Mon, 23 Sep 2013 16:35:17 +0000 Subject: [PATCH] Fix win message issue --- yunohost | 8 ++++---- yunohost.py | 10 ++++++++++ yunohost.tac | 7 +++---- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/yunohost b/yunohost index cc86f78f..169f4e43 100755 --- a/yunohost +++ b/yunohost @@ -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, win, parse_dict + from yunohost import YunoHostError, YunoHostLDAP, str_to_func, colorize, pretty_print_dict, display_error, validate, win, reset_win_messages, parse_dict except ImportError: sys.stderr.write('Error: Yunohost CLI Require YunoHost lib\n') sys.exit(1) @@ -55,6 +55,8 @@ def main(): int -- 0 or error code """ + reset_win_messages() + if len(sys.argv) < 2: sys.argv.append('-h') @@ -107,9 +109,7 @@ def main(): if result is None: result = {} if len(win) > 0: - result['success'] = [] - for msg in win: - result['success'].append(msg) + result['success'] = win print(json.dumps(result)) elif result is not None: pretty_print_dict(result) diff --git a/yunohost.py b/yunohost.py index 6f72254e..5be80f05 100644 --- a/yunohost.py +++ b/yunohost.py @@ -124,6 +124,16 @@ def win_msg(astr): +def reset_win_messages(): + """ + Empty the win array + + """ + global win + + win = [] + + def str_to_func(astr): """ Call a function from a string name diff --git a/yunohost.tac b/yunohost.tac index 8ca7b9d1..dc2d7d38 100755 --- a/yunohost.tac +++ b/yunohost.tac @@ -14,7 +14,7 @@ from twisted.web.server import Site, http from twisted.internet import reactor from twisted.application import internet,service from txrestapi.resource import APIResource -from yunohost import YunoHostError, YunoHostLDAP, str_to_func, colorize, pretty_print_dict, display_error, validate, win, parse_dict +from yunohost import YunoHostError, YunoHostLDAP, str_to_func, colorize, pretty_print_dict, display_error, validate, win, parse_dict, reset_win_messages if not __debug__: import traceback @@ -27,7 +27,6 @@ action_dict = {} api = APIResource() def http_exec(request, **kwargs): - global win request.setHeader('Access-Control-Allow-Origin', '*') # Allow cross-domain requests request.setHeader('Content-Type', 'application/json') # Return JSON anyway @@ -115,9 +114,9 @@ def http_exec(request, **kwargs): result = func(**validated_args) if result is None: result = {} - if win: + if len(win) > 0: result['win'] = win - win = [] + reset_win_messages() # Build response if request.method == 'POST':