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="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="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="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="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 pyclient --command="LIST" -c /home/gameserver/cfg/khaganat.cfg --log="debug" --show-log-console
@ -255,7 +255,8 @@ class Client():
command='GET', command='GET',
path='/', path='/',
raw_data=False, raw_data=False,
remove_color=False): remove_color=False,
show_result=True):
""" """
send command with https & json format send command with https & json format
:param str jsonin: json input (send in data on http request) :param str jsonin: json input (send in data on http request)
@ -281,7 +282,10 @@ class Client():
conn.send(bytes(out, "utf-8")) conn.send(bytes(out, "utf-8"))
response = conn.getresponse() response = conn.getresponse()
if raw_data: if raw_data:
print(response.read()) ret = response.read()
if show_result:
print(ret)
return ret
else: else:
if remove_color: if remove_color:
endText = '\x1b[0m' endText = '\x1b[0m'
@ -292,14 +296,17 @@ class Client():
print(response.read()) print(response.read())
return return
ret = response.read().decode() ret = response.read().decode()
msgjson = None
try: try:
msgjson = json.loads(ret) msgjson = json.loads(ret)
except json.JSONDecodeError: except json.JSONDecodeError:
logging.error("Impossible to decode Json output") logging.error("Impossible to decode Json output")
print(ret) print(ret)
return return
for key in sorted(msgjson, key=cmp_to_key()): if show_result:
print("%s: %s %s" % (key, msgjson[key], endText)) for key in sorted(msgjson, key=cmp_to_key()):
print("%s: %s %s" % (key, msgjson[key], endText))
return msgjson
def root(command, def root(command,