ResourceLoader raises ResourceNotFound, log more info about resource loaders

This commit is contained in:
David Vierra 2015-02-02 17:07:48 -10:00
parent 98999645af
commit 091a86931b
4 changed files with 22 additions and 6 deletions

View File

@ -13,6 +13,7 @@ cimport numpy
from cpython cimport array
from array import array
from mcedit2.resourceloader import ResourceNotFound
from mceditlib import faces
from mceditlib.blocktypes import BlockType
@ -104,8 +105,8 @@ cdef class BlockModels(object):
nameAndState = block.internalName + block.blockState
try:
statesJson = self._getBlockState(block.resourcePath)
except KeyError:
log.warn("Could not get blockstates resource for %s, skipping...", block)
except ResourceNotFound as e:
log.warn("Could not get blockstates resource for %s, skipping... (%r)", block, e)
continue
variants = statesJson['variants']
# variants is a dict with each key a resourceVariant value (from the block's ModelResourceLocation)
@ -139,6 +140,9 @@ cdef class BlockModels(object):
modelName = variantDict['model']
try:
modelDict = self._getBlockModel("block/" + modelName)
except ResourceNotFound as e:
log.exception("Could not get model resource %s for block %s, skipping... (%r)", modelName, block, e)
continue
except ValueError as e:
log.exception("Error parsing json for block/%s: %s", modelName, e)
continue

View File

@ -10,7 +10,7 @@ import numpy
from mcedit2.util.load_png import loadPNGData
from mcedit2.rendering.lightmap import generateLightmap
from mcedit2.resourceloader import ResourceLoader
from mcedit2.resourceloader import ResourceLoader, ResourceNotFound
from mcedit2.util import glutils
from mcedit2.util.resources import resourcePath
from mceditlib import util
@ -100,8 +100,8 @@ class TextureAtlas(object):
rawTextures.append((filename,) + loadPNGData(f.read()))
names.add(filename)
log.debug("Loaded texture %s", filename)
except KeyError as e:
log.error("Could not load texture %s: %s", filename, e)
except ResourceNotFound as e:
log.error("Could not load texture %s: %r", filename, e)
except Exception as e:
log.exception("%s while loading texture '%s', skipping...", e, filename)

View File

@ -7,6 +7,8 @@ import zipfile
log = logging.getLogger(__name__)
class ResourceNotFound(KeyError):
pass
class ResourceLoader(object):
def __init__(self):
@ -26,6 +28,6 @@ class ResourceLoader(object):
except KeyError: # Not found in zip file
continue
else:
raise KeyError("Resource %s not found in search path", path)
raise ResourceNotFound("Resource %s not found in search path" % path)
return stream

View File

@ -2,6 +2,7 @@
minecraftinstall
"""
from __future__ import absolute_import, division, print_function
import hashlib
import re
from PySide import QtGui
import logging
@ -29,12 +30,14 @@ class MCInstall(object):
:return:
:rtype:
"""
log.info("Checking install at %s", self.path)
if not os.path.exists(self.path):
raise MCInstallError("Minecraft folder does not exist.")
if not os.path.exists(self.versionsDir):
raise MCInstallError("Minecraft versions folder does not exist.")
if not len(self.versions):
raise MCInstallError("Minecraft folder has no minecraft versions")
log.info("Found versions:\n%s", self.versions)
requiredVersions = [v for v in self.versions if v.startswith("1.8")]
if not len(requiredVersions):
raise MCInstallError("Minecraft version 1.8 and up is required. Use the Minecraft Launcher to download it.")
@ -79,6 +82,13 @@ class MCInstall(object):
v1_8 = self.findVersion1_8()
loader.addZipFile(self.getVersionJarPath(v1_8))
def md5hash(filename):
md5 = hashlib.md5()
with file(filename, "rb") as f:
md5.update(f.read())
return md5.hexdigest()
info = ["%s (%s)" % (z.filename, md5hash(z.filename)) for z in loader.zipFiles]
log.info("Created ResourceLoader with search path:\n%s", ",\n".join(info))
return loader
def findVersion1_8(self):