0

updated contrib scripts to work with latest code

This commit is contained in:
Aaron Griffith
2011-09-16 15:59:00 -04:00
parent 8c4dd10824
commit b640b6dc2d
9 changed files with 44 additions and 130 deletions

View File

@@ -1,55 +0,0 @@
"""Simple Benchmarking script.
Usage and example:
$ python contrib/benchmark.py World4/
Rendering 50 chunks...
Took 20.290062 seconds or 0.405801 seconds per chunk, or 2.464261 chunks per second
"""
import chunk
import world
import tempfile
import glob
import time
import cProfile
import os
import sys
import shutil
# create a new, empty, cache dir
cachedir = tempfile.mkdtemp(prefix="benchmark_cache", dir=".")
if os.path.exists("benchmark.prof"): os.unlink("benchmark.prof")
w = world.WorldRenderer("World4", cachedir)
numchunks = 50
chunklist = w._find_chunkfiles()[:numchunks]
print "Rendering %d chunks..." % (numchunks)
def go():
for f in chunklist:
chunk.render_and_save(f[2], w.cachedir, w, (None,None), None)
start = time.time()
if "-profile" in sys.argv:
cProfile.run("go()", 'benchmark.prof')
else:
go()
stop = time.time()
delta = stop - start
print "Took %f seconds or %f seconds per chunk, or %f chunks per second" % (delta, delta/numchunks, numchunks/delta)
if "-profile" in sys.argv:
print "Profile is below:\n----\n"
import pstats
p = pstats.Stats('benchmark.prof')
p.strip_dirs().sort_stats("cumulative").print_stats(20)
shutil.rmtree(cachedir)

View File

@@ -1,47 +0,0 @@
"""Produces block counts
"""
import world, chunk
import sys
from numpy import *
def block_breakdown(worlddir):
"""Analyzes the given world dir and tallys up total block counts for each
type. Returns two arrays.
The first is a mapping from (blocktype, z-height) to count
The second is a mapping from blocktype to total count
"""
# Maps (blocktype, z-height) to count
heights = zeros((256,128), dtype=int)
# Maps (blocktype) to total
totals = zeros((256,), dtype=int)
all_chunks = world.find_chunkfiles(worlddir)
for i, (chunkx, chunky, chunkfile) in enumerate(all_chunks):
print "{0} / {1}".format(i, len(all_chunks))
sys.stdout.flush()
blockarr = chunk.get_blockarray_fromfile(chunkfile)
for coord, blocktype in ndenumerate(blockarr):
totals[blocktype] += 1
heights[blocktype, coord[2]] += 1
return heights, totals
# Some data from my world on iron
iron = array([ 0, 329, 1978, 4454, 6068, 7057, 7116, 7070, 7232, 7441, 7198,
7206, 7163, 6846, 6965, 7145, 7251, 7136, 6878, 7142, 7421, 7206,
7163, 7264, 7311, 7355, 7145, 7117, 7181, 7424, 7304, 7560, 7591,
7321, 7528, 7487, 7355, 7198, 7334, 7566, 7518, 7146, 7510, 7577,
7532, 7681, 7612, 7376, 7319, 7216, 7195, 6863, 6399, 6198, 5983,
5599, 5320, 4861, 4604, 4250, 3531, 3129, 3045, 2782, 2433, 1966,
891, 117, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0])
totaliron = 416159

View File

@@ -17,9 +17,8 @@ import sys
import re
import os.path
# sys.path wrangling, so we can access Overviewer code
overviewer_dir = os.path.split(os.path.split(os.path.abspath(__file__))[0])[0]
sys.path.insert(0, overviewer_dir)
# incantation to be able to import overviewer_core
sys.path.insert(0, os.path.abspath(os.path.join(os.path.split(__file__)[0], '..')))
from overviewer_core import world
from overviewer import list_worlds

0
contrib/cyrillic_convert.py Executable file → Normal file
View File

View File

@@ -29,7 +29,9 @@ import re
import os
import cPickle
sys.path.append(".")
# incantation to be able to import overviewer_core
sys.path.insert(0, os.path.abspath(os.path.join(os.path.split(__file__)[0], '..')))
from overviewer_core import nbt
from pprint import pprint
@@ -69,7 +71,8 @@ for dirpath, dirnames, filenames in os.walk(worlddir):
if matcher.match(f):
print f
full = os.path.join(dirpath, f)
r = nbt.load_region(full,north_direction)
# force lower-left so chunks are loaded in correct positions
r = nbt.load_region(full, 'lower-left')
chunks = r.get_chunks()
for x,y in chunks:
chunk = r.load_chunk(x,y).read_all()

View File

@@ -1,10 +1,11 @@
import sys
"""
Very basic player.dat inspection script
"""
sys.path.append(".")
import sys, os
# incantation to be able to import overviewer_core
sys.path.insert(0, os.path.abspath(os.path.join(os.path.split(__file__)[0], '..')))
from overviewer_core.nbt import load
from overviewer_core import items

View File

@@ -17,15 +17,16 @@ a Jack-O-Lantern (91)
'''
from optparse import OptionParser
import sys
sys.path.insert(0,".")
import nbt
from chunk import get_blockarray_fromfile, get_blockarray
import os
import sys,os
import re
# incantation to be able to import overviewer_core
sys.path.insert(0, os.path.abspath(os.path.join(os.path.split(__file__)[0], '..')))
from overviewer_core import nbt
from overviewer_core import world
from overviewer_core.chunk import get_blockarray_fromfile, get_blockarray
parser = OptionParser()
parser.add_option("--ids", dest="ids", type="string")
parser.add_option("--world", dest="world", type="string")
@@ -50,14 +51,18 @@ for dirpath, dirnames, filenames in os.walk(options.world):
for f in filenames:
if matcher.match(f):
full = os.path.join(dirpath, f)
r = nbt.load_region(full)
r = nbt.load_region(full, 'lower-left')
chunks = r.get_chunks()
found = False
for x,y in chunks:
chunk = r.load_chunk(x,y).read_all()
blocks = get_blockarray(chunk[1]['Level'])
for i in ids:
if i in blocks:
if chr(i) in blocks:
print full
found = True
break
if found:
break

View File

@@ -5,22 +5,25 @@ Validate a region file
TODO description here'''
import os.path
import os
import sys
overviewer_dir = os.path.split(os.path.split(os.path.abspath(__file__))[0])[0]
sys.path.insert(0, overviewer_dir)
import nbt
# incantation to be able to import overviewer_core
sys.path.insert(0, os.path.abspath(os.path.join(os.path.split(__file__)[0], '..')))
from overviewer_core import nbt
def check_region(region_filename):
chunk_errors = []
if not os.path.exists(region_filename):
raise Exception('Region file not found: %s' % region_filename)
try:
region = nbt.load_region(region_filename)
region = nbt.load_region(region_filename, 'lower-left')
except IOError, e:
raise Exception('Error loading region (%s): %s' % (region_filename, e))
try:
chunks = region.get_chunk_info(False)
region.get_chunk_info(False)
chunks = region.get_chunks()
except IOError, e:
raise Exception('Error reading region header (%s): %s' % (region_filename, e))
except Exception, e:

View File

@@ -5,16 +5,21 @@
import sys
import os.path
sys.path.append("overviewer_core")
import nbt
import ast
# incantation to be able to import overviewer_core
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
benchmark = "benchmark.py",
clearOldCache = "clearOldCache.py",
convertCyrillic = "cyrillic_convert.py",
findSigns = "findSigns.py",
validate = "validateRegionFile.py",
playerInspect = "playerInspect.py",
convertCyrillic = "cyrillic_convert.py"
rerenderBlocks = "rerenderBlocks.py",
testRender = "testRender.py",
validate = "validateRegionFile.py",
)
# you can symlink or hardlink contribManager.py to another name to have it