0

Moved --check-terrain command from setup.py and overviewer.py

Also, let textures_path work for minecraft.jar files
This commit is contained in:
Andrew Chin
2011-09-05 22:35:13 -04:00
parent 1cdac6ccdf
commit f880f01b46
3 changed files with 28 additions and 26 deletions

View File

@@ -113,6 +113,7 @@ def main():
parser.add_option("--web-assets-hook", dest="web_assets_hook", helptext="If provided, run this function after the web assets have been copied, but before actual tile rendering begins. It should accept a QuadtreeGen object as its only argument.", action="store", metavar="SCRIPT", type="function", advanced=True) parser.add_option("--web-assets-hook", dest="web_assets_hook", helptext="If provided, run this function after the web assets have been copied, but before actual tile rendering begins. It should accept a QuadtreeGen object as its only argument.", action="store", metavar="SCRIPT", type="function", advanced=True)
parser.add_option("--web-assets-path", dest="web_assets_path", helptext="Specifies a non-standard web_assets directory to use. Files here will overwrite the default web assets.", metavar="PATH", type="string", advanced=True) parser.add_option("--web-assets-path", dest="web_assets_path", helptext="Specifies a non-standard web_assets directory to use. Files here will overwrite the default web assets.", metavar="PATH", type="string", advanced=True)
parser.add_option("--textures-path", dest="textures_path", helptext="Specifies a non-standard textures path, from which terrain.png and other textures are loaded.", metavar="PATH", type="string", advanced=True) parser.add_option("--textures-path", dest="textures_path", helptext="Specifies a non-standard textures path, from which terrain.png and other textures are loaded.", metavar="PATH", type="string", advanced=True)
parser.add_option("--check-terrain", dest="check_terrain", helptext="Prints the location and hash of terrain.png, useful for debugging terrain.png problems", action="store_true", advanced=False, commandLineOnly=True)
parser.add_option("-q", "--quiet", dest="quiet", action="count", default=0, helptext="Print less output. You can specify this option multiple times.") parser.add_option("-q", "--quiet", dest="quiet", action="count", default=0, helptext="Print less output. You can specify this option multiple times.")
parser.add_option("-v", "--verbose", dest="verbose", action="count", default=0, helptext="Print more output. You can specify this option multiple times.") parser.add_option("-v", "--verbose", dest="verbose", action="count", default=0, helptext="Print more output. You can specify this option multiple times.")
parser.add_option("--skip-js", dest="skipjs", action="store_true", helptext="Don't output marker.js or regions.js") parser.add_option("--skip-js", dest="skipjs", action="store_true", helptext="Don't output marker.js or regions.js")
@@ -143,6 +144,25 @@ def main():
print "{name:{0}} {description}".format(name_width, **info) print "{name:{0}} {description}".format(name_width, **info)
sys.exit(0) sys.exit(0)
if options.check_terrain:
import hashlib
from overviewer_core.textures import _find_file
from overviewer_core import textures
if options.textures_path:
textures._find_file_local_path = options.textures_path
try:
f = _find_file("terrain.png", verbose=True)
except IOError:
logging.error("Could not find the file terrain.png")
sys.exit(1)
h = hashlib.sha1()
h.update(f.read())
logging.info("Hash of terrain.png file is: %s", h.hexdigest())
sys.exit(0)
if options.advanced_help: if options.advanced_help:
parser.advanced_help() parser.advanced_help()
sys.exit(0) sys.exit(0)

View File

@@ -23,6 +23,7 @@ import math
from random import randint from random import randint
import numpy import numpy
from PIL import Image, ImageEnhance, ImageOps, ImageDraw from PIL import Image, ImageEnhance, ImageOps, ImageDraw
import logging
import util import util
import composite import composite
@@ -47,13 +48,13 @@ def _find_file(filename, mode="rb", verbose=False):
if _find_file_local_path: if _find_file_local_path:
path = os.path.join(_find_file_local_path, filename) path = os.path.join(_find_file_local_path, filename)
if os.path.exists(path): if os.path.exists(path):
if verbose: print "Found %s in '%s'" % (filename, path) if verbose: logging.info("Found %s in '%s'", filename, path)
return open(path, mode) return open(path, mode)
programdir = util.get_program_path() programdir = util.get_program_path()
path = os.path.join(programdir, filename) path = os.path.join(programdir, filename)
if os.path.exists(path): if os.path.exists(path):
if verbose: print "Found %s in '%s'" % (filename, path) if verbose: logging.info("Found %s in '%s'", filename, path)
return open(path, mode) return open(path, mode)
path = os.path.join(programdir, "overviewer_core", "data", "textures", filename) path = os.path.join(programdir, "overviewer_core", "data", "textures", filename)
@@ -63,13 +64,13 @@ def _find_file(filename, mode="rb", verbose=False):
# windows special case, when the package dir doesn't exist # windows special case, when the package dir doesn't exist
path = os.path.join(programdir, "textures", filename) path = os.path.join(programdir, "textures", filename)
if os.path.exists(path): if os.path.exists(path):
if verbose: print "Found %s in '%s'" % (filename, path) if verbose: logging.info("Found %s in '%s'", filename, path)
return open(path, mode) return open(path, mode)
if sys.platform == "darwin": if sys.platform == "darwin":
path = os.path.join("/Applications/Minecraft", filename) path = os.path.join("/Applications/Minecraft", filename)
if os.path.exists(path): if os.path.exists(path):
if verbose: print "Found %s in '%s'" % (filename, path) if verbose: logging.info("Found %s in '%s'", filename, path)
return open(path, mode) return open(path, mode)
# Find minecraft.jar. # Find minecraft.jar.
@@ -84,12 +85,14 @@ def _find_file(filename, mode="rb", verbose=False):
"minecraft.jar")) "minecraft.jar"))
jarpaths.append(os.path.join(programdir,"minecraft.jar")) jarpaths.append(os.path.join(programdir,"minecraft.jar"))
jarpaths.append(os.path.join(os.getcwd(), "minecraft.jar")) jarpaths.append(os.path.join(os.getcwd(), "minecraft.jar"))
if _find_file_local_path:
jarpaths.append(os.path.join(_find_file_local_path, "minecraft.jar"))
for jarpath in jarpaths: for jarpath in jarpaths:
if os.path.exists(jarpath): if os.path.exists(jarpath):
try: try:
jar = zipfile.ZipFile(jarpath) jar = zipfile.ZipFile(jarpath)
if verbose: print "Found %s in '%s'" % (filename, jarpath) if verbose: logging.info("Found %s in '%s'", filename, jarpath)
return jar.open(filename) return jar.open(filename)
except (KeyError, IOError): except (KeyError, IOError):
pass pass

View File

@@ -251,32 +251,11 @@ class CustomBuildExt(build_ext):
self.inplace = True self.inplace = True
build_ext.build_extensions(self) build_ext.build_extensions(self)
class CheckTerrain(Command):
user_options=[]
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
from overviewer_core.textures import _find_file
import hashlib
import zipfile
print "checking..."
try:
f = _find_file("terrain.png", verbose=True)
except IOError:
log.error("Could not find the file terrain.png")
return
h = hashlib.sha1()
h.update(f.read())
log.info("Hash of terrain.png file is: %s", h.hexdigest())
setup_kwargs['cmdclass']['clean'] = CustomClean setup_kwargs['cmdclass']['clean'] = CustomClean
setup_kwargs['cmdclass']['sdist'] = CustomSDist setup_kwargs['cmdclass']['sdist'] = CustomSDist
setup_kwargs['cmdclass']['build'] = CustomBuild setup_kwargs['cmdclass']['build'] = CustomBuild
setup_kwargs['cmdclass']['build_ext'] = CustomBuildExt setup_kwargs['cmdclass']['build_ext'] = CustomBuildExt
setup_kwargs['cmdclass']['check_terrain'] = CheckTerrain
### ###
setup(**setup_kwargs) setup(**setup_kwargs)