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