adding option to show result or return function, update comment

This commit is contained in:
AleaJactaEst 2018-02-13 20:40:48 +01:00
parent 96469f775d
commit ac8b1b30cd

View file

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