0

Added new check_terrain command

This commit is contained in:
Andrew Chin
2011-07-10 19:40:05 -04:00
parent 482ccd3dd8
commit f4636520dd
2 changed files with 28 additions and 1 deletions

View File

@@ -28,7 +28,7 @@ import util
import composite import composite
_find_file_local_path = None _find_file_local_path = None
def _find_file(filename, mode="rb"): def _find_file(filename, mode="rb", verbose=False):
"""Searches for the given file and returns an open handle to it. """Searches for the given file and returns an open handle to it.
This searches the following locations in this order: This searches the following locations in this order:
@@ -47,11 +47,13 @@ def _find_file(filename, mode="rb"):
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)
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)
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)
@@ -61,11 +63,13 @@ def _find_file(filename, mode="rb"):
# 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)
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)
return open(path, mode) return open(path, mode)
# Find minecraft.jar. # Find minecraft.jar.
@@ -85,6 +89,7 @@ def _find_file(filename, mode="rb"):
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)
return jar.open(filename) return jar.open(filename)
except (KeyError, IOError): except (KeyError, IOError):
pass pass

View File

@@ -6,6 +6,7 @@ from distutils.command.build import build
from distutils.command.clean import clean from distutils.command.clean import clean
from distutils.command.build_ext import build_ext from distutils.command.build_ext import build_ext
from distutils.command.sdist import sdist from distutils.command.sdist import sdist
from distutils.cmd import Command
from distutils.dir_util import remove_tree from distutils.dir_util import remove_tree
from distutils.sysconfig import get_python_inc from distutils.sysconfig import get_python_inc
from distutils import log from distutils import log
@@ -232,11 +233,32 @@ 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)