Moved --check-terrain command from setup.py and overviewer.py
Also, let textures_path work for minecraft.jar files
This commit is contained in:
@@ -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-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("--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("-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")
|
||||
@@ -143,6 +144,25 @@ def main():
|
||||
print "{name:{0}} {description}".format(name_width, **info)
|
||||
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:
|
||||
parser.advanced_help()
|
||||
sys.exit(0)
|
||||
|
||||
@@ -23,6 +23,7 @@ import math
|
||||
from random import randint
|
||||
import numpy
|
||||
from PIL import Image, ImageEnhance, ImageOps, ImageDraw
|
||||
import logging
|
||||
|
||||
import util
|
||||
import composite
|
||||
@@ -47,13 +48,13 @@ def _find_file(filename, mode="rb", verbose=False):
|
||||
if _find_file_local_path:
|
||||
path = os.path.join(_find_file_local_path, filename)
|
||||
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)
|
||||
|
||||
programdir = util.get_program_path()
|
||||
path = os.path.join(programdir, filename)
|
||||
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)
|
||||
|
||||
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
|
||||
path = os.path.join(programdir, "textures", filename)
|
||||
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)
|
||||
|
||||
if sys.platform == "darwin":
|
||||
path = os.path.join("/Applications/Minecraft", filename)
|
||||
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)
|
||||
|
||||
# Find minecraft.jar.
|
||||
@@ -84,12 +85,14 @@ def _find_file(filename, mode="rb", verbose=False):
|
||||
"minecraft.jar"))
|
||||
jarpaths.append(os.path.join(programdir,"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:
|
||||
if os.path.exists(jarpath):
|
||||
try:
|
||||
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)
|
||||
except (KeyError, IOError):
|
||||
pass
|
||||
|
||||
21
setup.py
21
setup.py
@@ -251,32 +251,11 @@ class CustomBuildExt(build_ext):
|
||||
self.inplace = True
|
||||
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']['sdist'] = CustomSDist
|
||||
setup_kwargs['cmdclass']['build'] = CustomBuild
|
||||
setup_kwargs['cmdclass']['build_ext'] = CustomBuildExt
|
||||
setup_kwargs['cmdclass']['check_terrain'] = CheckTerrain
|
||||
###
|
||||
|
||||
setup(**setup_kwargs)
|
||||
|
||||
Reference in New Issue
Block a user