Fix win message issue

This commit is contained in:
Kload 2013-09-23 16:35:17 +00:00
parent 5c7f66eb3c
commit 2ad1a32419
3 changed files with 17 additions and 8 deletions

View file

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

View file

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

View file

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