Browse Source

working on piped messages

master
poikilos 7 years ago
committed by Jacob Gustafson
parent
commit
8a99a928de
  1. 81
      mtsenliven.py

81
mtsenliven.py

@ -27,47 +27,68 @@ print("Using minetestserver: " + mts)
print("Using primary_world_path: " + wp) print("Using primary_world_path: " + wp)
print("Using world_name: " + wn) print("Using world_name: " + wn)
print() print()
process = subprocess.Popen( process = None
[mts, '--gameid', game_id, '--worldname', wn], try:
stdout=subprocess.PIPE process = subprocess.Popen(
) [mts, '--gameid', game_id, '--worldname', wn],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
)
except:
print(mts + " could not be executed. Try installing the "
" minetest-server package or compiling from git instructions"
" on minetest.net")
exit(1)
msg_flags = ["WARNING[Server]: ", "ACTION[Server]: "] msg_flags = ["WARNING[Server]: ", "ACTION[Server]: "]
msg_lists = {} # where flag is key msg_lists = {} # where flag is key
for flag in msg_flags: for flag in msg_flags:
msg_lists[flag] = [] msg_lists[flag] = []
# see https://www.endpoint.com/blog/2015/01/28/getting-realtime-output- # see https://www.endpoint.com/blog/2015/01/28/getting-realtime-output-
# using-python # using-python
def print_unique_only(output):
output_strip = output.strip()
# (output_original is bytes)
show_enable = True
found_flag = None
f_i = None
for flag in msg_flags:
# such as '2018-02-06 21:08:06: WARNING[Server]: Deprecated call to get_look_yaw, use get_look_horizontal instead'
# or 2018-02-06 21:08:05: ACTION[Server]: [playereffects] Wrote playereffects data into /home/owner/.minetest/worlds/FCAGameAWorld/playereffects.mt.
f_i = output.find(flag)
if f_i >= 0:
found_flag = flag
break
if found_flag:
sub_msg = output[f_i+len(flag):].strip()
if sub_msg in msg_lists[found_flag]:
show_enable = False
else:
msg_lists[found_flag].append(sub_msg)
if show_enable:
print(output_strip)
if found_flag is not None:
print("[ mtsenliven.py ] INFO: this is the last"
" time the message above will be shown")
def process_msg(bstring):
output = output_original.decode("utf-8")
# works on python2 or 3
print_unique_only(output)
while True: while True:
try: try:
output_original = process.stdout.readline() output_original = process.stdout.readline()
if output_original == '' and process.poll() is not None: err_original = process.stderr.readline()
if (output_original == '') and \
(err_original == '') and \
(process.poll() is not None):
break break
if output_original: if output_original:
output = output_original.decode("utf-8") process_msg(output_original)
# works on python2 or 3 if err_original:
output_strip = output.strip() process_msg(err_original)
# (output_original is bytes)
show_enable = True
found_flag = None
f_i = None
for flag in msg_flags:
# such as '2018-02-06 21:08:06: WARNING[Server]: Deprecated call to get_look_yaw, use get_look_horizontal instead'
# or 2018-02-06 21:08:05: ACTION[Server]: [playereffects] Wrote playereffects data into /home/owner/.minetest/worlds/FCAGameAWorld/playereffects.mt.
f_i = output.find(flag)
if f_i >= 0:
found_flag = flag
break
if found_flag:
sub_msg = output[f_i+len(flag):].strip()
if sub_msg in msg_lists[found_flag]:
show_enable = False
else:
msg_lists[found_flag].append(sub_msg)
if show_enable:
print(output_strip)
if found_flag is not None:
print("[ mtsenliven.py ] INFO: this is the last"
" time the message above will be shown")
rc = process.poll() rc = process.poll()
except KeyboardInterrupt: except KeyboardInterrupt:
break break

Loading…
Cancel
Save