Browse Source

working on parsing server output

master
poikilos 7 years ago
committed by Jacob Gustafson
parent
commit
31df31f739
  1. 11
      etc/change_hardcoded_world_name_first/game-install-ENLIVEN
  2. 41
      mtsenliven.py

11
etc/change_hardcoded_world_name_first/game-install-ENLIVEN

@ -1936,7 +1936,7 @@ if [ -d "$PATCHES_PATH" ]; then
if [ -z "$TRY_DIFF" ]; then if [ -z "$TRY_DIFF" ]; then
sudo cp -f $MODIFIED_PATH "$MT_MYGAME_DIR/mods/bones/" sudo cp -f $MODIFIED_PATH "$MT_MYGAME_DIR/mods/bones/"
else else
echo "FAILED to patch $MTMOD_DEST_NAME since $TARGET_PATH differs from known" echo "FAILED to patch $MTMOD_DEST_NAME since $TARGET_PATH differs from known version (this is not a problem if you ran the patcher more than once)."
fi fi
BASIS_PATH=$PATCHES_PATH/subgame-basis/mods/homedecor_modpack/homedecor/gastronomy.lua BASIS_PATH=$PATCHES_PATH/subgame-basis/mods/homedecor_modpack/homedecor/gastronomy.lua
MODIFIED_PATH=$PATCHES_PATH/subgame/mods/homedecor_modpack/homedecor/gastronomy.lua MODIFIED_PATH=$PATCHES_PATH/subgame/mods/homedecor_modpack/homedecor/gastronomy.lua
@ -1947,7 +1947,7 @@ if [ -d "$PATCHES_PATH" ]; then
if [ -z "$TRY_DIFF" ]; then if [ -z "$TRY_DIFF" ]; then
sudo cp -f $MODIFIED_PATH "$MTMOD_DEST_PATH/" sudo cp -f $MODIFIED_PATH "$MTMOD_DEST_PATH/"
else else
echo "FAILED to patch $MTMOD_DEST_NAME since $TARGET_PATH differs from known" echo "FAILED to patch $MTMOD_DEST_NAME since $TARGET_PATH differs from known version (this is not a problem if you ran the patcher more than once)."
fi fi
BASIS_PATH=$PATCHES_PATH/subgame-basis/mods/homedecor_modpack/homedecor/crafts.lua BASIS_PATH=$PATCHES_PATH/subgame-basis/mods/homedecor_modpack/homedecor/crafts.lua
MODIFIED_PATH=$PATCHES_PATH/subgame/mods/homedecor_modpack/homedecor/crafts.lua MODIFIED_PATH=$PATCHES_PATH/subgame/mods/homedecor_modpack/homedecor/crafts.lua
@ -1957,13 +1957,14 @@ if [ -d "$PATCHES_PATH" ]; then
if [ -z "$TRY_DIFF" ]; then if [ -z "$TRY_DIFF" ]; then
sudo cp -f $MODIFIED_PATH "$MTMOD_DEST_PATH/" sudo cp -f $MODIFIED_PATH "$MTMOD_DEST_PATH/"
else else
echo "FAILED to patch $MTMOD_DEST_NAME since $TARGET_PATH differs from known" echo "FAILED to patch $MTMOD_DEST_NAME since $TARGET_PATH differs from known version (this is not a problem if you ran the patcher more than once)."
fi fi
if [ -d "$PATCHES_PATH/subgame/mods/homedecor_modpack/homedecor/models" ]; then if [ -d "$PATCHES_PATH/subgame/mods/homedecor_modpack/homedecor/models" ]; then
# deprecated, but copy in case gets un-deprecated # deprecated, but copy in case gets un-deprecated
cp -f "$PATCHES_PATH/subgame/mods/homedecor_modpack/homedecor/models/*" "$MTMOD_DEST_PATH/models/" cp -f $PATCHES_PATH/subgame/mods/homedecor_modpack/homedecor/models/* "$MTMOD_DEST_PATH/models/"
fi fi
cp -f "$PATCHES_PATH/subgame/mods/homedecor_modpack/homedecor/textures/*" "$MTMOD_DEST_PATH/textures/" # NOTE: quotes don't work with wildcard
cp -f $PATCHES_PATH/subgame/mods/homedecor_modpack/homedecor/textures/* "$MTMOD_DEST_PATH/textures/"
else else
echo "did not find $PATCHES_PATH, so skipped automatic patching which is partially implemented" echo "did not find $PATCHES_PATH, so skipped automatic patching which is partially implemented"
fi fi

41
mtsenliven.py

@ -31,14 +31,43 @@ process = subprocess.Popen(
[mts, '--gameid', game_id, '--worldname', wn], [mts, '--gameid', game_id, '--worldname', wn],
stdout=subprocess.PIPE stdout=subprocess.PIPE
) )
msg_flags = ["WARNING[Server]: ", "ACTION[Server]: "]
msg_lists = {} # where flag is key
for flag in msg_flags:
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
while True: while True:
output = process.stdout.readline() try:
if output == '' and process.poll() is not None: output_original = process.stdout.readline()
if output_original == '' and process.poll() is not None:
break
if output_original:
output = output_original.decode("utf-8")
# works on python2 or 3
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 break
if output: if found_flag:
# output is bytes sub_msg = output[f_i+len(flag):].strip()
print(output.decode("utf-8").strip()) # works on python2 or 3 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:
break

Loading…
Cancel
Save