adding option to show result or return function, update comment
This commit is contained in:
parent
96469f775d
commit
ac8b1b30cd
1 changed files with 12 additions and 5 deletions
|
@ -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
|
||||
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,
|
||||
|
|
Loading…
Reference in a new issue