Browse Source

integrated minetestoffline with minetestinfo

and renamed minetestrecovery to minetestoffline
master
poikilos 9 years ago
committed by Jacob Gustafson
parent
commit
2ba34b81d8
  1. 15
      archivedebug.py
  2. 1
      expertmmregressionsuite.py
  3. 2
      install-chunkymap-on-windows.py
  4. 18
      minetestinfo.py
  5. 168
      minetestoffline.py

15
archivedebug.py

@ -1,12 +1,13 @@
import os import os
import datetime import datetime
os_name = "*x" from minetestinfo import *
debug_name = "debug.txt" #os_name = "*x"
debug_path = "/usr/share/minetest/worlds" #debug_name = "debug.txt"
world_name = None #debug_path = "/usr/share/minetest/worlds"
if os.sep=="\\": #world_name = None
os_name = "windows" #if os.sep=="\\":
# os_name = "windows"
print("os detected: "+os_name) #print("os detected: "+os_name)

1
expertmmregressionsuite.py

@ -18,6 +18,7 @@ from expertmm import *
# * check for redefining member variable (missing "self.") [since python does not throw NameError on definition, only if used and not defined] # * check for redefining member variable (missing "self.") [since python does not throw NameError on definition, only if used and not defined]
# * check for signs in len params (such as where str(len(part1+part2)) should be str(len(part1))+part2 # * check for signs in len params (such as where str(len(part1+part2)) should be str(len(part1))+part2
# * check for only variable name in quotes (maybe the programmer meant to use the value) # * check for only variable name in quotes (maybe the programmer meant to use the value)
# * check for use of os.dirname (should be os.path.dirname)
def view_traceback(): def view_traceback():
ex_type, ex, tb = sys.exc_info() ex_type, ex, tb = sys.exc_info()

2
install-chunkymap-on-windows.py

@ -24,7 +24,7 @@ def web_get(url, file_name):
#as per http://stackoverflow.com/questions/22676/how-do-i-download-a-file-over-http-using-python but FAILS (404 Error) since user agent is not recognized, and setting user agent string does not fix it. use web_get above instead. #as per http://stackoverflow.com/questions/22676/how-do-i-download-a-file-over-http-using-python but FAILS (404 Error) since user agent is not recognized, and setting user agent string does not fix it. use web_get above instead.
def web_get_BADUSERAGENT(url, file_name): def web_get_DEPRECATED(url, file_name):
print("This function probably will not work since settings user agent doesn't work with urllib2 request object (user agent is not recognized, and 404 error is usually the result). Try web_get instead.") print("This function probably will not work since settings user agent doesn't work with urllib2 request object (user agent is not recognized, and 404 error is usually the result). Try web_get instead.")
file_name = None file_name = None
try: try:

18
minetestinfo.py

@ -27,6 +27,24 @@ worldgen_mod_list.append("tsm_mines")
worldgen_mod_list.append("tsm_pyramids") worldgen_mod_list.append("tsm_pyramids")
worldgen_mod_list.append("tsm_railcorridors") worldgen_mod_list.append("tsm_railcorridors")
after_broken = {}
after_broken["default:stone"] = "default:cobble"
after_broken["default:stone_with_iron"] = "default:iron_lump"
after_broken["default:stone_with_copper"] = "default:copper_lump"
after_broken["default:stone_with_coal"] = "default:coal_lump"
after_broken["default:dirt_with_grass"] = "default:dirt"
after_broken["moreores:mineral_tin"] = "moreores:tin_lump"
after_broken["default:stone_with_mese"] = "default:mese_crystal"
after_broken["moreores:mineral_silver"] = "moreores:silver_lump"
after_broken["default:stone_with_gold"] = "default:gold_lump"
after_broken["default:stone_with_diamond"] = "default:diamond"
#after_broken[""] = ""
#after_broken[""] = ""
#after_broken[""] = ""
#after_broken[""] = ""
#after_broken[""] = ""
loaded_mod_list = list() loaded_mod_list = list()
prepackaged_game_mod_list = list() prepackaged_game_mod_list = list()

168
minetestrecovery.py → minetestoffline.py

@ -7,36 +7,91 @@ import os
from datetime import datetime from datetime import datetime
from expertmm import * from expertmm import *
from minetestinfo import *
#C:\Users\jgustafson\Desktop\Backup\fcalocal\home\owner\.minetest\worlds\FCAGameAWorld\players #C:\Users\jgustafson\Desktop\Backup\fcalocal\home\owner\.minetest\worlds\FCAGameAWorld\players
minetest_players_path = "C:\\Users\\jgustafson\\Desktop\\Backup\\fcalocal\\home\\owner\\.minetest\\worlds\\FCAGameAWorld\\players" #minetest_players_path = "C:\\Users\\jgustafson\\Desktop\\Backup\\fcalocal\\home\\owner\\.minetest\\worlds\\FCAGameAWorld\\players"
players_path = os.path.join(minetestinfo.get_var("primary_world_path"), "players")
_MAX_STACK_QTY = 99 _MAX_STACK_QTY = 99
PLAYER_STORAGE_FILE_DOT_THEN_EXT = ".conf" PLAYER_STORAGE_FILE_DOT_THEN_EXT = ".conf"
debugs_list = list() #debugs_list = list()
debugs_list.append("C:\\Users\\jgustafson\\Desktop\\Backup\\fcalocal\\home\\owner\\.minetest\\debug_archived\\2016\\03\\16.txt") #debugs_list.append("C:\\Users\\jgustafson\\Desktop\\Backup\\fcalocal\\home\\owner\\.minetest\\debug_archived\\2016\\03\\16.txt")
debugs_list.append("C:\\Users\\jgustafson\\Desktop\\Backup\\fcalocal\\home\\owner\\.minetest\\debug_archived\\2016\\03\\17.txt") #debugs_list.append("C:\\Users\\jgustafson\\Desktop\\Backup\\fcalocal\\home\\owner\\.minetest\\debug_archived\\2016\\03\\17.txt")
min_date_string = "2016-03-15 12:12:00" debug_txt_path = os.path.join(minetestinfo.get_var("profile_minetest_path"), "debug.txt")
global_player_storage_path = "C:\\Users\\jgustafson\\Desktop\\Backup\\fcalocal\\home\\owner\\.minetest\\worlds\\FCAGameAWorld\\player_storage" min_date_string = None
real_names_path = "H:\\Minetest\\FCAGameAWorld - Minetest Users - Real Names.txt" #min_date_string = "2016-03-15 12:12:00"
after_broken = {} DEBUG_TXT_TIME_FORMAT_STRING="%Y-%m-%d %H:%M:%S"
after_broken["default:stone"] = "default:cobble" is_start_now = False
after_broken["default:stone_with_iron"] = "default:iron_lump" while min_date_string is None:
after_broken["default:stone_with_copper"] = "default:copper_lump" default_min_date_string = datetime.strftime(datetime.now(), DEBUG_TXT_TIME_FORMAT_STRING)
after_broken["default:stone_with_coal"] = "default:coal_lump" print("")
after_broken["default:dirt_with_grass"] = "default:dirt" print("Please enter starting date for player locations and block obtaining to be replayed (only used for inventory recovery feature).")
after_broken["moreores:mineral_tin"] = "moreores:tin_lump" answer = raw_input("Replay Start [YYYY-MM-DD HH-mm-SS format] (blank for "+default_min_date_string+"): ")
after_broken["default:stone_with_mese"] = "default:mese_crystal" if len(answer.strip())>0:
after_broken["moreores:mineral_silver"] = "moreores:silver_lump" try:
after_broken["default:stone_with_gold"] = "default:gold_lump" min_date = datetime.strptime(answer, DEBUG_TXT_TIME_FORMAT_STRING)
after_broken["default:stone_with_diamond"] = "default:diamond" tmp_string = datetime.strftime(min_date, DEBUG_TXT_TIME_FORMAT_STRING)
#after_broken[""] = "" confirm = raw_input(tmp_string+" ok [Y/n]? ")
#after_broken[""] = "" if confirm.strip().lower()=="y" or confirm.strip().lower()=="yes":
#after_broken[""] = "" min_date_string = tmp_string
#after_broken[""] = "" except:
#after_broken[""] = "" print("Bad date format. Please try again.")
else:
is_start_now = True
min_date_string = default_min_date_string
print("Using start "+min_date_string)
if is_start_now:
print(" (which is the current time, so nothing will be replayed [this is the default just be extra careful, because if you run the replay function on the same part of the log more than once, that will double #of each item each player digs and double the quantity of those items in players offline storage folder])")
print("")
players_offline_storage_name = "players_offline_storage"
deprecated_players_offline_storage_name = "player_storage"
#H:\Minetest\player_storage
players_offline_storage_path = os.path.join(minetestinfo.get_var("primary_world_path"), players_offline_storage_name)
deprecated_players_offline_storage_path = os.path.join(minetestinfo.get_var("primary_world_path"),deprecated_players_offline_storage_name)
if os.path.isdir(deprecated_players_offline_storage_path):
print("moving \""+deprecated_players_offline_storage_path+"\" to")
print(" "+players_offline_storage_path)
shutil.move(deprecated_players_offline_storage_path, players_offline_storage_path)
print("Using offline players_offline_storage_path:")
print(" "+players_offline_storage_path)
print(" (used for inventory recovery and other offline storage features)")
#players_offline_storage_path = os.path.join("C:\\Users\\jgustafson\\Desktop\\Backup\\fcalocal\\home\\owner\\.minetest\\worlds\\FCAGameAWorld", players_offline_storage_name)
irl_person_csv_name = None
irl_person_csv_path = None
world_name = None
try:
world_name = os.path.basename(os.path.abspath(minetestinfo.get_var("primary_world_path")))
print("")
print("Using world_name '"+str(world_name)+"'")
except:
print("Could not finish getting world folder name.")
view_traceback()
try:
deprecated_irl_person_csv_name = world_name + " - Minetest Users - Real Names.txt"
irl_person_csv_name = "irl_person_info.csv"
print("")
if os.path.isdir(minetestinfo.get_var("primary_world_path")):
irl_person_csv_path = os.path.join(minetestinfo.get_var("primary_world_path"), irl_person_csv_name)
if os.sep=="\\":
deprecated_irl_person_csv_path = os.path.join("H:\\Minetest", deprecated_irl_person_csv_name)
if os.path.isfile(deprecated_irl_person_csv_name):
print("moving \""+deprecated_irl_person_csv_path+"\" to")
print(" "+irl_person_csv_path)
os.rename(deprecated_irl_person_csv_path, irl_person_csv_path)
print("Using irl_person_csv_path:")
print(" "+str(irl_person_csv_path))
print("")
else:
print("No world folder found, so leaving irl_person_csv_path as None")
except:
print("Could not finish building irl_person_csv_path.")
view_traceback()
print("")
class MinetestInventoryItem: class MinetestInventoryItem:
owner = None # optional, only used for debug output owner = None # optional, only used for debug output
name = None name = None
qty = None qty = None
param = None param = None
@ -211,7 +266,7 @@ class MinetestPlayer:
def save(self): def save(self):
if "name" in self.player_args: if "name" in self.player_args:
player_path = os.path.join(minetest_players_path, self.playerid) player_path = os.path.join(players_path, self.playerid)
self.save_as(player_path) self.save_as(player_path)
def save_as(self, player_path): def save_as(self, player_path):
@ -235,7 +290,7 @@ class MinetestPlayer:
def load(self): def load(self):
if self.playerid is not None and len(self.playerid.strip())>0: if self.playerid is not None and len(self.playerid.strip())>0:
player_path = os.path.join(minetest_players_path, self.playerid) player_path = os.path.join(players_path, self.playerid)
self.load_from_file(player_path) self.load_from_file(player_path)
else: else:
print("ERROR in minetestplayer.load: 'playerid' member was not set (unique filename for players folder)") print("ERROR in minetestplayer.load: 'playerid' member was not set (unique filename for players folder)")
@ -318,7 +373,7 @@ class MinetestPlayer:
except: except:
pass pass
DEBUG_TXT_TIME_FORMAT_STRING="%Y-%m-%d %H:%M:%S"
player_file_indicator_string = "PlayerArgsEnd" player_file_indicator_string = "PlayerArgsEnd"
player_file_extension = "" # player files have no extension in minetest player_file_extension = "" # player files have no extension in minetest
replay_file_ao = "=" replay_file_ao = "="
@ -364,13 +419,13 @@ def recover_player_files_by_content(recovery_source_path, dest_players_path):
shutil.copyfile(sub_path, dest_path) shutil.copyfile(sub_path, dest_path)
print(" recovered to '"+dest_path+"'") print(" recovered to '"+dest_path+"'")
players = None players = None
def load_player_storage(player_storage_path): def load_players_offline_storage(this_players_offline_storage_path):
global players global players
players = {} players = {}
if not os.path.exists(player_storage_path): if not os.path.exists(this_players_offline_storage_path):
os.makedirs(player_storage_path) os.makedirs(this_players_offline_storage_path)
else: else:
folder_path = player_storage_path folder_path = this_players_offline_storage_path
for sub_name in os.listdir(folder_path): for sub_name in os.listdir(folder_path):
sub_path = os.path.join(folder_path,sub_name) sub_path = os.path.join(folder_path,sub_name)
if os.path.isfile(sub_path): if os.path.isfile(sub_path):
@ -380,17 +435,17 @@ def load_player_storage(player_storage_path):
players[playerid] = get_dict_from_conf_file(sub_path, replay_file_ao) players[playerid] = get_dict_from_conf_file(sub_path, replay_file_ao)
#returns list of give commands if has problem #returns list of give commands if has problem
def move_storage_to_players(storage_path, output_players_folder_path, leftover_give_commands_folder_path, change_player_position_enable=True): def move_storage_to_players(this_players_offline_storage_path, output_players_folder_path, leftover_give_commands_folder_path, change_player_position_enable=True):
give_commands_by_playerid = {} give_commands_by_playerid = {}
if os.path.isdir(storage_path): if os.path.isdir(this_players_offline_storage_path):
folder_path = storage_path folder_path = this_players_offline_storage_path
for sub_name in os.listdir(folder_path): for sub_name in os.listdir(folder_path):
sub_path = os.path.join(folder_path,sub_name) sub_path = os.path.join(folder_path,sub_name)
if os.path.isfile(sub_path): if os.path.isfile(sub_path):
if (sub_name[:1]!="."): if (sub_name[:1]!="."):
if len(sub_name) > len(PLAYER_STORAGE_FILE_DOT_THEN_EXT): if len(sub_name) > len(PLAYER_STORAGE_FILE_DOT_THEN_EXT):
playerid = sub_name[:-len(PLAYER_STORAGE_FILE_DOT_THEN_EXT)] playerid = sub_name[:-len(PLAYER_STORAGE_FILE_DOT_THEN_EXT)]
player_path = os.path.join(minetest_players_path, playerid) player_path = os.path.join(players_path, playerid)
if os.path.isfile(player_path): if os.path.isfile(player_path):
this_storage = get_dict_from_conf_file(sub_path, "=") this_storage = get_dict_from_conf_file(sub_path, "=")
minetestplayer = MinetestPlayer(playerid) minetestplayer = MinetestPlayer(playerid)
@ -432,13 +487,13 @@ def move_storage_to_players(storage_path, output_players_folder_path, leftover_g
else: else:
print("WARNING: no playerid '"+playerid+"', so keeping storage file") print("WARNING: no playerid '"+playerid+"', so keeping storage file")
else: else:
print("ERROR: missing storage folder '"+storage_path+"'") print("ERROR: missing players' offline storage folder '"+this_players_offline_storage_path+"'")
def convert_storage_to_give_commands_DEPRECATED(storage_path, output_folder_path, real_names_path): def convert_storage_to_give_commands_DEPRECATED(this_players_offline_storage_path, output_folder_path, irl_person_csv_path):
global players global players
#if players is None: #if players is None:
# load_player_storage(player_storage_path) # load_players_offline_storage(this_players_offline_storage_path)
while True: while True:
print("") print("")
playerid = raw_input("Minetest Username: ") playerid = raw_input("Minetest Username: ")
@ -446,12 +501,12 @@ def convert_storage_to_give_commands_DEPRECATED(storage_path, output_folder_path
identifiable_user_description = "first initial + last name + grad year" identifiable_user_description = "first initial + last name + grad year"
identifiable_user_string = raw_input(identifiable_user_description+": ") identifiable_user_string = raw_input(identifiable_user_description+": ")
if len(playerid)>0: if len(playerid)>0:
player_storage_path = os.path.join(storage_path,playerid) player_storage_path = os.path.join(this_players_offline_storage_path, playerid)
if os.path.isfile(player_storage_path): if os.path.isfile(player_storage_path):
#if len(real_name_string)>0: #if len(real_name_string)>0:
identifiable_user_string_strip = identifiable_user_string.strip() identifiable_user_string_strip = identifiable_user_string.strip()
if len(identifiable_user_string_strip)>0: if len(identifiable_user_string_strip)>0:
appends = open(real_names_path, 'a') appends = open(irl_person_csv_path, 'a')
#line = playerid.strip().replace(","," ")+","+real_name_string.replace(","," ")+"," #line = playerid.strip().replace(","," ")+","+real_name_string.replace(","," ")+","
line = playerid.strip().replace(","," ")+","+real_name_string+","+identifiable_user_string_strip.replace(","," ") line = playerid.strip().replace(","," ")+","+real_name_string+","+identifiable_user_string_strip.replace(","," ")
appends.append(line+"\n") appends.append(line+"\n")
@ -481,15 +536,16 @@ def convert_storage_to_give_commands_DEPRECATED(storage_path, output_folder_path
else: else:
break break
def modify_player_storage_from_debug(debug_txt_path, player_storage_path, min_date_string): def debug_log_replay_to_offline_player_storage(debug_txt_path, this_players_offline_storage_path, min_date_string):
global players global players
min_date = None min_date = None
if min_date_string is not None: if min_date_string is not None:
min_date = datetime.strptime(min_date_string, DEBUG_TXT_TIME_FORMAT_STRING) min_date = datetime.strptime(min_date_string, DEBUG_TXT_TIME_FORMAT_STRING)
print("Using min date "+str(min_date)) print("This will only work if server is offline.")
raw_input("press enter to continue...") print(" (Using min date "+str(min_date)+")")
raw_input(" press enter to continue, otherwise exit this Window or Ctrl-C to terminate script in GNU/Linux systems...")
if players is None: if players is None:
load_player_storage(global_player_storage_path) load_players_offline_storage(this_players_offline_storage_path)
ins = open(debug_txt_path, 'r') ins = open(debug_txt_path, 'r')
line = True line = True
@ -576,7 +632,7 @@ def modify_player_storage_from_debug(debug_txt_path, player_storage_path, min_da
print(" block: "+position_one_to_one_string) print(" block: "+position_one_to_one_string)
for playerid in players.keys(): for playerid in players.keys():
player_replay_path = os.path.join(player_storage_path, playerid+PLAYER_STORAGE_FILE_DOT_THEN_EXT) player_replay_path = os.path.join(this_players_offline_storage_path, playerid+PLAYER_STORAGE_FILE_DOT_THEN_EXT)
save_conf_from_dict(player_replay_path, players[playerid], replay_file_ao) save_conf_from_dict(player_replay_path, players[playerid], replay_file_ao)
#ins.close() #ins.close()
@ -589,17 +645,18 @@ def modify_player_storage_from_debug(debug_txt_path, player_storage_path, min_da
### RESTORE ITEMS FROM DEBUG.TXT: ### RESTORE ITEMS FROM DEBUG.TXT:
#"C:\Users\jgustafson\Desktop\Backup\fcalocal\home\owner\.minetest\debug_archived\2016\03\" #"C:\Users\jgustafson\Desktop\Backup\fcalocal\home\owner\.minetest\debug_archived\2016\03\"
##modify_player_storage_from_debug("C:\\Users\\jgustafson\\Desktop\\Backup\\fcalocal\\home\\owner\\.minetest\\debug.txt", global_player_storage_path, min_date_string) ##debug_log_replay_to_offline_player_storage("C:\\Users\\jgustafson\\Desktop\\Backup\\fcalocal\\home\\owner\\.minetest\\debug.txt", players_offline_storage_path, min_date_string)
##for debug_path in debugs_list:
## debug_log_replay_to_offline_player_storage(debug_path, players_offline_storage_path, min_date_string)
#debug_log_replay_to_offline_player_storage(debug_txt_path, players_offline_storage_path, min_date_string)
#for debug_path in debugs_list:
# modify_player_storage_from_debug(debug_path, global_player_storage_path, min_date_string)
#C:\Users\jgustafson\ownCloud\FCA\player_storage
give_path = os.path.join(global_player_storage_path, "give") give_path = os.path.join(players_offline_storage_path, "give")
#convert_storage_to_give_commands(global_player_storage_path, give_path, real_names_path) #convert_storage_to_give_commands_DEPRECATED(players_offline_storage_path, give_path, irl_person_csv_path)
#move_storage_to_players(global_player_storage_path, minetest_players_path, give_path, change_player_position_enable=True) #move_storage_to_players(players_offline_storage_path, players_path, give_path, change_player_position_enable=True)
@ -613,4 +670,9 @@ give_path = os.path.join(global_player_storage_path, "give")
#minetestplayer.playerid = "mrg-try1" #minetestplayer.playerid = "mrg-try1"
#minetestplayer.save() #minetestplayer.save()
if os.sep == "\\": if os.sep == "\\":
print("REMEMBER if you plan on using these player files on a 'nix-like system, run dos2unix * on your world's players folder after copying from this Windows machine to convert line endings, otherwise inventory will be blanked out!") print("# REMEMBER If you later copy player files to a GNU/Linux machine cd to your world's players folder then run dos2unix such as:")
print(" sudo apt-get update")
print(" sudo apt-get install dos2unix")
print(" cd "+os.path.join(minetestinfo.get_var("primary_world_path"), "players"))
print(" dos2unix *")
print("# to convert line endings, otherwise inventory and all PlayerArgs will be loaded as blank (if using player files with Windows line endings on GNU/Linux copy of minetest).")
Loading…
Cancel
Save