diff --git a/overviewer.py b/overviewer.py index 5206ef7..896e955 100755 --- a/overviewer.py +++ b/overviewer.py @@ -404,11 +404,12 @@ dir but you forgot to put quotes around the directory, since it contains spaces. render = render_things[render_name] logging.debug("Found the following render thing: %r", render) - w = world.World(render['worldpath']) + # XXX we now construct the regionset directly + #w = world.World(render['worldpath']) # if no dimension has been specified, just use the first one # TODO support the case where a different dimension is specified - rset = w.get_regionset(0) + rset = world.RegionSet(render['worldpath']) logging.debug("Using RegionSet %r", rset) # create our TileSet from this RegionSet diff --git a/overviewer_core/configParser.py b/overviewer_core/configParser.py index fe2bbfd..b60d091 100644 --- a/overviewer_core/configParser.py +++ b/overviewer_core/configParser.py @@ -221,7 +221,7 @@ class MultiWorldParser(object): self.settings_file = settings def parse(self): - glob = dict(render=dict(), custom_rendermodes=dict()) + glob = dict(render=dict(), custom_rendermodes=dict(), world=dict()) try: execfile(self.settings_file, glob, glob) @@ -243,10 +243,12 @@ class MultiWorldParser(object): self.render = glob['render'] self.custom_rendermodes = glob['custom_rendermodes'] + self.world = glob['world'] # anything that's not 'render' or 'custom_rendermode' is a default del glob['render'] del glob['custom_rendermodes'] + del glob['world'] # seed with the Overviewer defaults, then update with the user defaults self.defaults = dict() @@ -261,6 +263,11 @@ class MultiWorldParser(object): def validate(self): + # first validate the world dict + for worldname in self.world: + if not os.path.exists(self.world[worldname]): + raise Exception("%r does not exist for %s" % (self.world[worldname], worldname)) + for worldname in self.render: world = dict() @@ -274,10 +281,10 @@ class MultiWorldParser(object): definition = settingsDefinition.render[key] try: - val = definition['validator'](world[key]) + val = definition['validator'](world[key], world = self.world) world[key] = val except Exception as e: - #print "Error validating %s: %r" % (key, e) + print "Error validating %s: %r" % (key, e) raise e self.render[worldname] = world diff --git a/overviewer_core/settingsDefinition.py b/overviewer_core/settingsDefinition.py index b80f1aa..9a873c0 100644 --- a/overviewer_core/settingsDefinition.py +++ b/overviewer_core/settingsDefinition.py @@ -17,19 +17,19 @@ from settingsValidators import * # note that all defaults go thought the validator render = { - "worldpath": dict(required=True, validator=validateWorldPath), + "worldname": dict(required=True, validator=validateWorldPath), "rendermode": dict(required=False, validator=validateRenderMode), "northdirection": dict(required=False, validator=validateNorthDirection), "renderrange": dict(required=False, validator=validateRenderRange), - "forcerender": dict(required=False, validator=bool), + "forcerender": dict(required=False, validator=validateBool), "stochasticrender": dict(required=False, validator=validateStochastic), "imgformat": dict(required=False, validator=validateImgFormat, default="png"), "imgquality": dict(required=False, validator=validateImgQuality), "bgcolor": dict(required=False, validator=validateBGColor, default="1a1a1a"), "optimizeimg": dict(required=False, validator=validateOptImg, default=0), - "nomarkers": dict(required=False, validator=bool), + "nomarkers": dict(required=False, validator=validateBool), "texturepath": dict(required=False, validator=validateTexturePath), - "renderchecks": dict(required=False, validator=int, default=0), - "rerenderprob": dict(required=False, validator=float, default=0), + "renderchecks": dict(required=False, validator=validateInt, default=0), + "rerenderprob": dict(required=False, validator=validateFloat, default=0), } diff --git a/overviewer_core/settingsValidators.py b/overviewer_core/settingsValidators.py index 1fcf8ca..dd398d2 100644 --- a/overviewer_core/settingsValidators.py +++ b/overviewer_core/settingsValidators.py @@ -5,25 +5,19 @@ import os.path class ValidationException(Exception): pass -def validateWorldPath(path): - try: - if not os.path.exists(path): - raise ValidationException("%r does not exist" % path) - if not os.path.isdir(path): - raise ValidationException("%r is not a directory" % path) - except ValidationException, e: - # TODO assume this is the name of a world and try - # to find it - raise e - full_path = os.path.abspath(path) - return full_path +def validateWorldPath(name, **kwargs): + world = kwargs.get('world', dict()) + if name not in world.keys(): + raise ValidationException("bad world name") + return os.path.abspath(world[name]) -def validateRenderMode(mode): + +def validateRenderMode(mode, **kwargs): # TODO get list of valid rendermodes #raise NotImplementedError("validateRenderMode") return mode -def validateNorthDirection(direction): +def validateNorthDirection(direction, **kwargs): # normalize to integers intdir = 0 #default if type(direction) == int: @@ -37,28 +31,28 @@ def validateNorthDirection(direction): raise ValidationException("%r is not a valid north direction" % direction) return intdir -def validateRenderRange(r): +def validateRenderRange(r, **kwargs): raise NotImplementedError("render range") -def validateStochastic(s): +def validateStochastic(s, **kwargs): val = float(s) if val < 0 or val > 1: raise ValidationException("%r is not a valid stochastic value. Should be between 0.0 and 1.0" % s) return val -def validateImgFormat(fmt): +def validateImgFormat(fmt, **kwargs): if fmt not in ("png", "jpg", "jpeg"): raise ValidationException("%r is not a valid image format" % fmt) if fmt == "jpeg": fmt = "jpg" return fmt -def validateImgQuality(qual): +def validateImgQuality(qual, **kwargs): intqual = int(qual) if (intqual < 0 or intqual > 100): raise ValidationException("%r is not a valid image quality" % intqual) return intqual -def validateBGColor(color): +def validateBGColor(color, **kwargs): """BG color must be an HTML color, with an option leading # (hash symbol) returns an (r,b,g) 3-tuple """ @@ -80,11 +74,20 @@ def validateBGColor(color): return color -def validateOptImg(opt): +def validateOptImg(opt, **kwargs): return bool(opt) -def validateTexturePath(path): +def validateTexturePath(path, **kwargs): # Expand user dir in directories strings path = os.path.expanduser(path) # TODO assert this path exists? + +def validateBool(b, **kwargs): + return bool(b) + +def validateFloat(f, **kwargs): + return float(f) + +def validateInt(i, **kwargs): + return int(i) diff --git a/overviewer_core/world.py b/overviewer_core/world.py index ebe6485..56b552d 100644 --- a/overviewer_core/world.py +++ b/overviewer_core/world.py @@ -194,8 +194,8 @@ we're reading from. There is one of these per set of regions on the hard drive, but may be several per invocation of the Overviewer in the case of multi-world. """ - def __init__(self, worldobj, regiondir): - self.world = worldobj + def __init__(self, regiondir): + #self.world = worldobj self.regiondir = regiondir logging.info("Scanning regions") diff --git a/test/data/settings/settings_test_1.py b/test/data/settings/settings_test_1.py index 370e3d6..5aa7b77 100644 --- a/test/data/settings/settings_test_1.py +++ b/test/data/settings/settings_test_1.py @@ -1,4 +1,6 @@ -worldpath="test/data/settings/test_world" +world['test'] = "test/data/settings/test_world" +worldname = 'test' + rendermode = "normal" render["world"] = { diff --git a/test/data/settings/settings_test_bgcolor.py b/test/data/settings/settings_test_bgcolor.py index a14d5bc..08cc1d9 100644 --- a/test/data/settings/settings_test_bgcolor.py +++ b/test/data/settings/settings_test_bgcolor.py @@ -1,6 +1,8 @@ bgcolor="#000000" +world['test'] = "test/data/settings/test_world" + render["world"] = { - "worldpath": "test/data/settings/test_world", + "worldname": "test", "bgcolor":"ffff" } diff --git a/test/data/settings/settings_test_rendermode.py b/test/data/settings/settings_test_rendermode.py index 5c28040..b0d205a 100644 --- a/test/data/settings/settings_test_rendermode.py +++ b/test/data/settings/settings_test_rendermode.py @@ -1,5 +1,7 @@ +world['test'] = "test/data/settings/test_world" + render["world"] = { - "worldpath": "test/data/settings/test_world", + "worldname": "test", "rendermode": "bad_rendermode", "northdirection": ["upper-left"], }