Merge branch 'contribManager-management' into python3-fun-times
This commit is contained in:
@@ -2,7 +2,10 @@
|
|||||||
Very basic player.dat inspection script
|
Very basic player.dat inspection script
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sys, os
|
from __future__ import print_function
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
# incantation to be able to import overviewer_core
|
# incantation to be able to import overviewer_core
|
||||||
if not hasattr(sys, "frozen"):
|
if not hasattr(sys, "frozen"):
|
||||||
@@ -11,29 +14,34 @@ if not hasattr(sys, "frozen"):
|
|||||||
from overviewer_core.nbt import load
|
from overviewer_core.nbt import load
|
||||||
from overviewer_core import items
|
from overviewer_core import items
|
||||||
|
|
||||||
def print_player(data, sub_entry=False):
|
|
||||||
|
|
||||||
|
def print_player(data, sub_entry=False):
|
||||||
indent = ""
|
indent = ""
|
||||||
if sub_entry:
|
if sub_entry:
|
||||||
indent = "\t"
|
indent = "\t"
|
||||||
print "%sPosition:\t%i, %i, %i\t(dim: %i)" % (indent,
|
print("%sPosition:\t%i, %i, %i\t(dim: %i)"
|
||||||
data['Pos'][0], data['Pos'][1], data['Pos'][2], data['Dimension'])
|
% (indent, data['Pos'][0], data['Pos'][1], data['Pos'][2], data['Dimension']))
|
||||||
try:
|
try:
|
||||||
print "%sSpawn:\t\t%i, %i, %i" % (indent,
|
print("%sSpawn:\t\t%i, %i, %i"
|
||||||
data['SpawnX'], data['SpawnY'], data['SpawnZ'])
|
% (indent, data['SpawnX'], data['SpawnY'], data['SpawnZ']))
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
print "%sHealth:\t%i\tLevel:\t\t%i\t\tGameType:\t%i" % (indent,
|
print("%sHealth:\t%i\tLevel:\t\t%i\t\tGameType:\t%i"
|
||||||
data['Health'], data['XpLevel'], data['playerGameType'])
|
% (indent, data['Health'], data['XpLevel'], data['playerGameType']))
|
||||||
print "%sFood:\t%i\tTotal XP:\t%i" % (indent,
|
print("%sFood:\t%i\tTotal XP:\t%i"
|
||||||
data['foodLevel'], data['XpTotal'])
|
% (indent, data['foodLevel'], data['XpTotal']))
|
||||||
print "%sInventory: %d items" % (indent, len(data['Inventory']))
|
print("%sInventory: %d items" % (indent, len(data['Inventory'])))
|
||||||
if not sub_entry:
|
if not sub_entry:
|
||||||
for item in data['Inventory']:
|
for item in data['Inventory']:
|
||||||
print " %-3d %s" % (item['Count'], items.id2item(item['id']))
|
print(" %-3d %s" % (item['Count'], items.id2item(item['id'])))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
print "Inspecting %s" % sys.argv[1]
|
if len(sys.argv) < 2 or len(sys.argv) > 3:
|
||||||
|
print("Usage: {} <Player .dat or directory> [selected player]"
|
||||||
|
.format(sys.argv[0]), file=sys.stderr)
|
||||||
|
sys.exit(1)
|
||||||
|
print("Inspecting %s" % sys.argv[1])
|
||||||
|
|
||||||
if os.path.isdir(sys.argv[1]):
|
if os.path.isdir(sys.argv[1]):
|
||||||
directory = sys.argv[1]
|
directory = sys.argv[1]
|
||||||
@@ -44,11 +52,10 @@ if __name__ == '__main__':
|
|||||||
for player_file in os.listdir(directory):
|
for player_file in os.listdir(directory):
|
||||||
player = player_file.split(".")[0]
|
player = player_file.split(".")[0]
|
||||||
if selected_player in [None, player]:
|
if selected_player in [None, player]:
|
||||||
print
|
print("")
|
||||||
print player
|
print(player)
|
||||||
data = load(os.path.join(directory, player_file))[1]
|
data = load(os.path.join(directory, player_file))[1]
|
||||||
print_player(data, sub_entry=(selected_player is None))
|
print_player(data, sub_entry=(selected_player is None))
|
||||||
else:
|
else:
|
||||||
data = load(sys.argv[1])[1]
|
data = load(sys.argv[1])[1]
|
||||||
print_player(data)
|
print_player(data)
|
||||||
|
|
||||||
|
|||||||
@@ -1,29 +1,25 @@
|
|||||||
#!/usr/bin/env python2
|
#!/usr/bin/env python2
|
||||||
|
|
||||||
# The contrib manager is used to help control the contribs script
|
"""The contrib manager is used to help control the contrib scripts
|
||||||
# that are shipped with overviewer in Windows packages
|
that are shipped with overviewer in Windows packages."""
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
import sys
|
|
||||||
import os.path
|
|
||||||
import ast
|
import ast
|
||||||
|
import os.path
|
||||||
|
import sys
|
||||||
|
|
||||||
# incantation to be able to import overviewer_core
|
scripts = { # keys are names, values are scripts
|
||||||
if not hasattr(sys, "frozen"):
|
"convertCyrillic": "cyrillic_convert.py",
|
||||||
sys.path.insert(0, os.path.abspath(os.path.join(os.path.split(__file__)[0], '.')))
|
"playerInspect": "playerInspect.py",
|
||||||
|
"rerenderBlocks": "rerenderBlocks.py",
|
||||||
from overviewer_core import nbt
|
"testRender": "testRender.py",
|
||||||
|
"validate": "validateRegionFile.py",
|
||||||
scripts=dict( # keys are names, values are scripts
|
"pngit": "png-it.py",
|
||||||
convertCyrillic = "cyrillic_convert.py",
|
"gallery": "gallery.py",
|
||||||
playerInspect = "playerInspect.py",
|
"regionTrimmer": "regionTrimmer.py",
|
||||||
rerenderBlocks = "rerenderBlocks.py",
|
"contributors": "contributors.py"
|
||||||
testRender = "testRender.py",
|
}
|
||||||
validate = "validateRegionFile.py",
|
|
||||||
pngit = "png-it.py",
|
|
||||||
gallery = "gallery.py",
|
|
||||||
regionTrimmer = "regionTrimmer.py",
|
|
||||||
contributors = "contributors.py"
|
|
||||||
)
|
|
||||||
|
|
||||||
# you can symlink or hardlink contribManager.py to another name to have it
|
# you can symlink or hardlink contribManager.py to another name to have it
|
||||||
# automatically find the right script to run. For example:
|
# automatically find the right script to run. For example:
|
||||||
@@ -33,15 +29,15 @@ scripts=dict( # keys are names, values are scripts
|
|||||||
|
|
||||||
|
|
||||||
# figure out what script to execute
|
# figure out what script to execute
|
||||||
argv=os.path.basename(sys.argv[0])
|
argv = os.path.basename(sys.argv[0])
|
||||||
|
|
||||||
if argv[-4:] == ".exe":
|
if argv[-4:] == ".exe":
|
||||||
argv=argv[0:-4]
|
argv = argv[0:-4]
|
||||||
if argv[-3:] == ".py":
|
if argv[-3:] == ".py":
|
||||||
argv=argv[0:-3]
|
argv = argv[0:-3]
|
||||||
|
|
||||||
|
|
||||||
usage="""Usage:
|
usage = """Usage:
|
||||||
%s --list-contribs | <script name> <arguments>
|
%s --list-contribs | <script name> <arguments>
|
||||||
|
|
||||||
Executes a contrib script.
|
Executes a contrib script.
|
||||||
@@ -59,29 +55,28 @@ else:
|
|||||||
for contrib in scripts.keys():
|
for contrib in scripts.keys():
|
||||||
# use an AST to extract the docstring for this module
|
# use an AST to extract the docstring for this module
|
||||||
script = scripts[contrib]
|
script = scripts[contrib]
|
||||||
with open(os.path.join("contrib",script)) as f:
|
with open(os.path.join("contrib", script)) as f:
|
||||||
d = f.read()
|
d = f.read()
|
||||||
node=ast.parse(d, script);
|
node = ast.parse(d, script)
|
||||||
docstring = ast.get_docstring(node)
|
docstring = ast.get_docstring(node)
|
||||||
if docstring:
|
if docstring:
|
||||||
docstring = docstring.strip().splitlines()[0]
|
docstring = docstring.strip().splitlines()[0]
|
||||||
else:
|
else:
|
||||||
docstring="(no description found. add one by adding a docstring to %s)" % script
|
docstring = "(No description found. Add one by adding a docstring to %s.)" % script
|
||||||
print "%s : %s" % (contrib, docstring)
|
print("%s : %s" % (contrib, docstring))
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
if len(sys.argv) > 1 and sys.argv[1] in scripts.keys():
|
if len(sys.argv) > 1 and sys.argv[1] in scripts.keys():
|
||||||
script = scripts[sys.argv[1]]
|
script = scripts[sys.argv[1]]
|
||||||
sys.argv = [script] + sys.argv[2:]
|
sys.argv = [script] + sys.argv[2:]
|
||||||
else:
|
else:
|
||||||
print usage
|
print(usage, file=sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
torun = os.path.join("contrib", script)
|
torun = os.path.join("contrib", script)
|
||||||
|
|
||||||
if not os.path.exists(torun):
|
if not os.path.exists(torun):
|
||||||
print "Script '%s' is missing!" % script
|
print("Script '%s' is missing!" % script, file=sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
execfile(torun)
|
execfile(torun)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user