Allow regionsets to be named in a settings.py file
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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),
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user