From f4636520dd04548d7a583b6577bb4d24785ec70a Mon Sep 17 00:00:00 2001 From: Andrew Chin Date: Sun, 10 Jul 2011 19:40:05 -0400 Subject: [PATCH] Added new check_terrain command --- overviewer_core/textures.py | 7 ++++++- setup.py | 22 ++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/overviewer_core/textures.py b/overviewer_core/textures.py index f1da1b2..4a1f407 100644 --- a/overviewer_core/textures.py +++ b/overviewer_core/textures.py @@ -28,7 +28,7 @@ import util import composite _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. This searches the following locations in this order: @@ -47,11 +47,13 @@ def _find_file(filename, mode="rb"): 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) 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) return open(path, mode) 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 path = os.path.join(programdir, "textures", filename) if os.path.exists(path): + if verbose: print "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) return open(path, mode) # Find minecraft.jar. @@ -85,6 +89,7 @@ def _find_file(filename, mode="rb"): if os.path.exists(jarpath): try: jar = zipfile.ZipFile(jarpath) + if verbose: print "Found %s in '%s'" % (filename, jarpath) return jar.open(filename) except (KeyError, IOError): pass diff --git a/setup.py b/setup.py index d21e1be..52d7a50 100755 --- a/setup.py +++ b/setup.py @@ -6,6 +6,7 @@ from distutils.command.build import build from distutils.command.clean import clean from distutils.command.build_ext import build_ext from distutils.command.sdist import sdist +from distutils.cmd import Command from distutils.dir_util import remove_tree from distutils.sysconfig import get_python_inc from distutils import log @@ -232,11 +233,32 @@ 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)