From b640b6dc2df7aa8af0c97583262e6c18d1fa2023 Mon Sep 17 00:00:00 2001 From: Aaron Griffith Date: Fri, 16 Sep 2011 15:59:00 -0400 Subject: [PATCH] updated contrib scripts to work with latest code --- contrib/benchmark.py | 55 ----------------------------------- contrib/blockcounter.py | 47 ------------------------------ contrib/clearOldCache.py | 5 ++-- contrib/cyrillic_convert.py | 0 contrib/findSigns.py | 7 +++-- contrib/playerInspect.py | 7 +++-- contrib/rerenderBlocks.py | 23 +++++++++------ contrib/validateRegionFile.py | 15 ++++++---- contribManager.py | 15 ++++++---- 9 files changed, 44 insertions(+), 130 deletions(-) delete mode 100644 contrib/benchmark.py delete mode 100644 contrib/blockcounter.py mode change 100755 => 100644 contrib/cyrillic_convert.py diff --git a/contrib/benchmark.py b/contrib/benchmark.py deleted file mode 100644 index 6de19e1..0000000 --- a/contrib/benchmark.py +++ /dev/null @@ -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) diff --git a/contrib/blockcounter.py b/contrib/blockcounter.py deleted file mode 100644 index 6d69d55..0000000 --- a/contrib/blockcounter.py +++ /dev/null @@ -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 diff --git a/contrib/clearOldCache.py b/contrib/clearOldCache.py index 14316a4..a7000e1 100644 --- a/contrib/clearOldCache.py +++ b/contrib/clearOldCache.py @@ -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 diff --git a/contrib/cyrillic_convert.py b/contrib/cyrillic_convert.py old mode 100755 new mode 100644 diff --git a/contrib/findSigns.py b/contrib/findSigns.py index cab1617..2dbacd8 100644 --- a/contrib/findSigns.py +++ b/contrib/findSigns.py @@ -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() diff --git a/contrib/playerInspect.py b/contrib/playerInspect.py index d20d2ac..cf12ee3 100644 --- a/contrib/playerInspect.py +++ b/contrib/playerInspect.py @@ -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 diff --git a/contrib/rerenderBlocks.py b/contrib/rerenderBlocks.py index ff7b02a..7dde88d 100644 --- a/contrib/rerenderBlocks.py +++ b/contrib/rerenderBlocks.py @@ -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 diff --git a/contrib/validateRegionFile.py b/contrib/validateRegionFile.py index b9276f3..c723734 100644 --- a/contrib/validateRegionFile.py +++ b/contrib/validateRegionFile.py @@ -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: diff --git a/contribManager.py b/contribManager.py index 0f89d1b..29737eb 100755 --- a/contribManager.py +++ b/contribManager.py @@ -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