From ac8b1b30cd35da66fd8dc0d4e36c322a5fad5637 Mon Sep 17 00:00:00 2001 From: AleaJactaEst Date: Tue, 13 Feb 2018 20:40:48 +0100 Subject: [PATCH] adding option to show result or return function, update comment --- pymanager/client.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/pymanager/client.py b/pymanager/client.py index c190fa2..4e6a39a 100755 --- a/pymanager/client.py +++ b/pymanager/client.py @@ -68,7 +68,7 @@ Example :: pyclient --command="START" --program="aes" -c /home/gameserver/cfg/khaganat.cfg --log="info" --show-log-console pyclient --command="STATUS" --program="aes" -c /home/gameserver/cfg/khaganat.cfg --log="debug" --show-log-console - pyclient --command="STDIN" --program="aes" --action="help all" -c /home/gameserver/cfg/khaganat.cfg --log="debug" --show-log-console + pyclient --command="STDIN" --program="aes" --stdin="help all" -c /home/gameserver/cfg/khaganat.cfg --log="debug" --show-log-console pyclient --command="STDOUT" --program="aes" --firstline=0 -c /home/gameserver/cfg/khaganat.cfg --log="debug" --show-log-console pyclient --command="STOP" --program="aes" -c /home/gameserver/cfg/khaganat.cfg --log="debug" --show-log-console pyclient --command="LIST" -c /home/gameserver/cfg/khaganat.cfg --log="debug" --show-log-console @@ -255,7 +255,8 @@ class Client(): command='GET', path='/', raw_data=False, - remove_color=False): + remove_color=False, + show_result=True): """ send command with https & json format :param str jsonin: json input (send in data on http request) @@ -281,7 +282,10 @@ class Client(): conn.send(bytes(out, "utf-8")) response = conn.getresponse() if raw_data: - print(response.read()) + ret = response.read() + if show_result: + print(ret) + return ret else: if remove_color: endText = '\x1b[0m' @@ -292,14 +296,17 @@ class Client(): print(response.read()) return ret = response.read().decode() + msgjson = None try: msgjson = json.loads(ret) except json.JSONDecodeError: logging.error("Impossible to decode Json output") print(ret) return - for key in sorted(msgjson, key=cmp_to_key()): - print("%s: %s %s" % (key, msgjson[key], endText)) + if show_result: + for key in sorted(msgjson, key=cmp_to_key()): + print("%s: %s %s" % (key, msgjson[key], endText)) + return msgjson def root(command,