From cd2a2bdf2c6df551359087766d07b5d7ddc8d6d5 Mon Sep 17 00:00:00 2001 From: Andrew Chin Date: Tue, 16 Aug 2011 20:52:43 -0400 Subject: [PATCH 1/4] initial version of the contribManager --- contribManager.py | 38 ++++++++++++++++++++++++++++++++++++++ setup.py | 3 ++- 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100755 contribManager.py diff --git a/contribManager.py b/contribManager.py new file mode 100755 index 0000000..7f1ab3f --- /dev/null +++ b/contribManager.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python + +# The contrib manager is used to help control the contribs script +# that are shipped with overviewer in Windows packages + +import sys +import os.path + +scripts=dict( # keys are names, values are scripts + benchmark="benchmark.py", + findSigns="findSigns.py", + validate="validateRegionFile.py" + ) + + +# figure out what script to execute +argv=os.path.basename(sys.argv[0]) + +if argv[-4:] == ".exe": + argv=argv[0:-4] +if argv[-3:] == ".py": + argv=argv[0:-3] + +print "argv is ", argv + +if argv in scripts.keys(): + script = scripts[argv] +else: + if sys.argv[1] in scripts.keys(): + script = scripts[sys.argv[1]] + else: + print "what do you want to run?" + sys.exit(1) + + +print "running", script + +execfile(os.path.join("contrib", script)) diff --git a/setup.py b/setup.py index e105bf6..a52880c 100755 --- a/setup.py +++ b/setup.py @@ -91,10 +91,11 @@ def recursive_package_data(src, package_dir='overviewer_core'): # if py2exe is not None: - setup_kwargs['console'] = ['overviewer.py'] + setup_kwargs['console'] = ['overviewer.py', 'contribManager.py'] setup_kwargs['data_files'] = [('', doc_files)] setup_kwargs['data_files'] += recursive_data_files('overviewer_core/data/textures', 'textures') setup_kwargs['data_files'] += recursive_data_files('overviewer_core/data/web_assets', 'web_assets') + setup_kwargs['data_files'] += recursive_data_files('contrib', 'contrib') setup_kwargs['zipfile'] = None if platform.system() == 'Windows' and '64bit' in platform.architecture(): b = 3 From 99932f35a3eb67b7c434602b7b0d2fe7855e4cf7 Mon Sep 17 00:00:00 2001 From: Andrew Chin Date: Wed, 17 Aug 2011 09:16:39 -0400 Subject: [PATCH 2/4] Minor changes to the contrib manager add --list-contribs option construct sys.argv correctly for the contrib scripts --- contribManager.py | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/contribManager.py b/contribManager.py index 7f1ab3f..f750b90 100755 --- a/contribManager.py +++ b/contribManager.py @@ -5,6 +5,8 @@ import sys import os.path +sys.path.append("overviewer_core") +import nbt scripts=dict( # keys are names, values are scripts benchmark="benchmark.py", @@ -12,6 +14,12 @@ scripts=dict( # keys are names, values are scripts validate="validateRegionFile.py" ) +# you can symlink or hardlink contribManager.py to another name to have it +# automatically find the right script to run. For example: +# > ln -s contribManager.py validate.exe +# > chmod +x validate.exe +# > ./validate.exe -h + # figure out what script to execute argv=os.path.basename(sys.argv[0]) @@ -21,18 +29,26 @@ if argv[-4:] == ".exe": if argv[-3:] == ".py": argv=argv[0:-3] -print "argv is ", argv - if argv in scripts.keys(): script = scripts[argv] + sys.argv[0] = script else: - if sys.argv[1] in scripts.keys(): + if "--list-contribs" in sys.argv: + print scripts.keys() + 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 "what do you want to run?" sys.exit(1) -print "running", script +torun = os.path.join("contrib", script) + +if not os.path.exists(torun): + print "Script '%s' is missing!" % script + sys.exit(1) + +execfile(torun) -execfile(os.path.join("contrib", script)) From 22f40a9075d1b94d06e5066e8f0f756cd747047b Mon Sep 17 00:00:00 2001 From: Andrew Chin Date: Thu, 25 Aug 2011 21:57:08 -0400 Subject: [PATCH 3/4] Added docstrings to all contrib scripts --- contrib/benchmark.py | 16 ++++++++++------ contrib/blockcounter.py | 4 ++++ contrib/clearOldCache.py | 3 +++ contrib/findSigns.py | 2 ++ contrib/playerInspect.py | 4 ++++ contrib/rerenderBlocks.py | 2 ++ contrib/testRender.py | 2 ++ contrib/validateRegionFile.py | 5 +++++ 8 files changed, 32 insertions(+), 6 deletions(-) diff --git a/contrib/benchmark.py b/contrib/benchmark.py index 145654e..6de19e1 100644 --- a/contrib/benchmark.py +++ b/contrib/benchmark.py @@ -1,3 +1,13 @@ +"""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 @@ -8,12 +18,6 @@ import os import sys import shutil -# 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 - # create a new, empty, cache dir cachedir = tempfile.mkdtemp(prefix="benchmark_cache", dir=".") diff --git a/contrib/blockcounter.py b/contrib/blockcounter.py index b3603d3..6d69d55 100644 --- a/contrib/blockcounter.py +++ b/contrib/blockcounter.py @@ -1,3 +1,7 @@ +"""Produces block counts + +""" + import world, chunk import sys diff --git a/contrib/clearOldCache.py b/contrib/clearOldCache.py index 01b604d..45f8b0a 100644 --- a/contrib/clearOldCache.py +++ b/contrib/clearOldCache.py @@ -1,5 +1,8 @@ #!/usr/bin/python +"""Deletes files from the old chunk-based cache""" + + usage = "python contrib/%prog [OPTIONS] " description = """ diff --git a/contrib/findSigns.py b/contrib/findSigns.py index 3213b35..a344c71 100644 --- a/contrib/findSigns.py +++ b/contrib/findSigns.py @@ -1,6 +1,8 @@ #!/usr/bin/python ''' +Updates overviewer.dat file sign info + This script will scan through every chunk looking for signs and write out an updated overviewer.dat file. This can be useful if your overviewer.dat file is either out-of-date or non-existant. diff --git a/contrib/playerInspect.py b/contrib/playerInspect.py index c520788..d20d2ac 100644 --- a/contrib/playerInspect.py +++ b/contrib/playerInspect.py @@ -1,5 +1,9 @@ import sys +""" +Very basic player.dat inspection script +""" + sys.path.append(".") from overviewer_core.nbt import load diff --git a/contrib/rerenderBlocks.py b/contrib/rerenderBlocks.py index eb93871..ff7b02a 100644 --- a/contrib/rerenderBlocks.py +++ b/contrib/rerenderBlocks.py @@ -1,6 +1,8 @@ #!/usr/bin/python ''' +Generate a region list to rerender certain chunks + This is used to force the regeneration of any chunks that contain a certain blockID. The output is a chunklist file that is suitable to use with the --chunklist option to overviewer.py. diff --git a/contrib/testRender.py b/contrib/testRender.py index c4de264..4fa9e7e 100644 --- a/contrib/testRender.py +++ b/contrib/testRender.py @@ -1,5 +1,7 @@ #!/usr/bin/python +"Test Render Script" + import os, shutil, tempfile, time, sys, math, re from subprocess import Popen, PIPE, STDOUT, CalledProcessError from optparse import OptionParser diff --git a/contrib/validateRegionFile.py b/contrib/validateRegionFile.py index 7dd2763..b9276f3 100644 --- a/contrib/validateRegionFile.py +++ b/contrib/validateRegionFile.py @@ -1,5 +1,10 @@ #!/usr/bin/env python +''' +Validate a region file + +TODO description here''' + import os.path import sys overviewer_dir = os.path.split(os.path.split(os.path.abspath(__file__))[0])[0] From 3377be6b37a4514cc285c1c47cf0802d0c768019 Mon Sep 17 00:00:00 2001 From: Andrew Chin Date: Thu, 25 Aug 2011 22:00:36 -0400 Subject: [PATCH 4/4] Updated contrib manager print out description for each script based on docstrings added usage info --- contribManager.py | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/contribManager.py b/contribManager.py index f750b90..58fa920 100755 --- a/contribManager.py +++ b/contribManager.py @@ -7,11 +7,13 @@ import sys import os.path sys.path.append("overviewer_core") import nbt +import ast scripts=dict( # keys are names, values are scripts - benchmark="benchmark.py", - findSigns="findSigns.py", - validate="validateRegionFile.py" + benchmark = "benchmark.py", + findSigns = "findSigns.py", + validate = "validateRegionFile.py", + playerInspect = "playerInspect.py" ) # you can symlink or hardlink contribManager.py to another name to have it @@ -29,18 +31,40 @@ if argv[-4:] == ".exe": if argv[-3:] == ".py": argv=argv[0:-3] + +usage="""Usage: +%s --list-contribs |