Allow regionsets to be named in a settings.py file
This commit is contained in:
@@ -404,11 +404,12 @@ dir but you forgot to put quotes around the directory, since it contains spaces.
|
|||||||
render = render_things[render_name]
|
render = render_things[render_name]
|
||||||
logging.debug("Found the following render thing: %r", render)
|
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
|
# if no dimension has been specified, just use the first one
|
||||||
# TODO support the case where a different dimension is specified
|
# 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)
|
logging.debug("Using RegionSet %r", rset)
|
||||||
|
|
||||||
# create our TileSet from this RegionSet
|
# create our TileSet from this RegionSet
|
||||||
|
|||||||
@@ -221,7 +221,7 @@ class MultiWorldParser(object):
|
|||||||
self.settings_file = settings
|
self.settings_file = settings
|
||||||
|
|
||||||
def parse(self):
|
def parse(self):
|
||||||
glob = dict(render=dict(), custom_rendermodes=dict())
|
glob = dict(render=dict(), custom_rendermodes=dict(), world=dict())
|
||||||
|
|
||||||
try:
|
try:
|
||||||
execfile(self.settings_file, glob, glob)
|
execfile(self.settings_file, glob, glob)
|
||||||
@@ -243,10 +243,12 @@ class MultiWorldParser(object):
|
|||||||
|
|
||||||
self.render = glob['render']
|
self.render = glob['render']
|
||||||
self.custom_rendermodes = glob['custom_rendermodes']
|
self.custom_rendermodes = glob['custom_rendermodes']
|
||||||
|
self.world = glob['world']
|
||||||
|
|
||||||
# anything that's not 'render' or 'custom_rendermode' is a default
|
# anything that's not 'render' or 'custom_rendermode' is a default
|
||||||
del glob['render']
|
del glob['render']
|
||||||
del glob['custom_rendermodes']
|
del glob['custom_rendermodes']
|
||||||
|
del glob['world']
|
||||||
|
|
||||||
# seed with the Overviewer defaults, then update with the user defaults
|
# seed with the Overviewer defaults, then update with the user defaults
|
||||||
self.defaults = dict()
|
self.defaults = dict()
|
||||||
@@ -261,6 +263,11 @@ class MultiWorldParser(object):
|
|||||||
|
|
||||||
def validate(self):
|
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:
|
for worldname in self.render:
|
||||||
world = dict()
|
world = dict()
|
||||||
@@ -274,10 +281,10 @@ class MultiWorldParser(object):
|
|||||||
|
|
||||||
definition = settingsDefinition.render[key]
|
definition = settingsDefinition.render[key]
|
||||||
try:
|
try:
|
||||||
val = definition['validator'](world[key])
|
val = definition['validator'](world[key], world = self.world)
|
||||||
world[key] = val
|
world[key] = val
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
#print "Error validating %s: %r" % (key, e)
|
print "Error validating %s: %r" % (key, e)
|
||||||
raise e
|
raise e
|
||||||
self.render[worldname] = world
|
self.render[worldname] = world
|
||||||
|
|
||||||
|
|||||||
@@ -17,19 +17,19 @@ from settingsValidators import *
|
|||||||
# note that all defaults go thought the validator
|
# note that all defaults go thought the validator
|
||||||
|
|
||||||
render = {
|
render = {
|
||||||
"worldpath": dict(required=True, validator=validateWorldPath),
|
"worldname": dict(required=True, validator=validateWorldPath),
|
||||||
"rendermode": dict(required=False, validator=validateRenderMode),
|
"rendermode": dict(required=False, validator=validateRenderMode),
|
||||||
"northdirection": dict(required=False, validator=validateNorthDirection),
|
"northdirection": dict(required=False, validator=validateNorthDirection),
|
||||||
"renderrange": dict(required=False, validator=validateRenderRange),
|
"renderrange": dict(required=False, validator=validateRenderRange),
|
||||||
"forcerender": dict(required=False, validator=bool),
|
"forcerender": dict(required=False, validator=validateBool),
|
||||||
"stochasticrender": dict(required=False, validator=validateStochastic),
|
"stochasticrender": dict(required=False, validator=validateStochastic),
|
||||||
"imgformat": dict(required=False, validator=validateImgFormat, default="png"),
|
"imgformat": dict(required=False, validator=validateImgFormat, default="png"),
|
||||||
"imgquality": dict(required=False, validator=validateImgQuality),
|
"imgquality": dict(required=False, validator=validateImgQuality),
|
||||||
"bgcolor": dict(required=False, validator=validateBGColor, default="1a1a1a"),
|
"bgcolor": dict(required=False, validator=validateBGColor, default="1a1a1a"),
|
||||||
"optimizeimg": dict(required=False, validator=validateOptImg, default=0),
|
"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),
|
"texturepath": dict(required=False, validator=validateTexturePath),
|
||||||
"renderchecks": dict(required=False, validator=int, default=0),
|
"renderchecks": dict(required=False, validator=validateInt, default=0),
|
||||||
"rerenderprob": dict(required=False, validator=float, default=0),
|
"rerenderprob": dict(required=False, validator=validateFloat, default=0),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,25 +5,19 @@ import os.path
|
|||||||
class ValidationException(Exception):
|
class ValidationException(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def validateWorldPath(path):
|
def validateWorldPath(name, **kwargs):
|
||||||
try:
|
world = kwargs.get('world', dict())
|
||||||
if not os.path.exists(path):
|
if name not in world.keys():
|
||||||
raise ValidationException("%r does not exist" % path)
|
raise ValidationException("bad world name")
|
||||||
if not os.path.isdir(path):
|
return os.path.abspath(world[name])
|
||||||
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 validateRenderMode(mode):
|
|
||||||
|
def validateRenderMode(mode, **kwargs):
|
||||||
# TODO get list of valid rendermodes
|
# TODO get list of valid rendermodes
|
||||||
#raise NotImplementedError("validateRenderMode")
|
#raise NotImplementedError("validateRenderMode")
|
||||||
return mode
|
return mode
|
||||||
|
|
||||||
def validateNorthDirection(direction):
|
def validateNorthDirection(direction, **kwargs):
|
||||||
# normalize to integers
|
# normalize to integers
|
||||||
intdir = 0 #default
|
intdir = 0 #default
|
||||||
if type(direction) == int:
|
if type(direction) == int:
|
||||||
@@ -37,28 +31,28 @@ def validateNorthDirection(direction):
|
|||||||
raise ValidationException("%r is not a valid north direction" % direction)
|
raise ValidationException("%r is not a valid north direction" % direction)
|
||||||
return intdir
|
return intdir
|
||||||
|
|
||||||
def validateRenderRange(r):
|
def validateRenderRange(r, **kwargs):
|
||||||
raise NotImplementedError("render range")
|
raise NotImplementedError("render range")
|
||||||
|
|
||||||
def validateStochastic(s):
|
def validateStochastic(s, **kwargs):
|
||||||
val = float(s)
|
val = float(s)
|
||||||
if val < 0 or val > 1:
|
if val < 0 or val > 1:
|
||||||
raise ValidationException("%r is not a valid stochastic value. Should be between 0.0 and 1.0" % s)
|
raise ValidationException("%r is not a valid stochastic value. Should be between 0.0 and 1.0" % s)
|
||||||
return val
|
return val
|
||||||
|
|
||||||
def validateImgFormat(fmt):
|
def validateImgFormat(fmt, **kwargs):
|
||||||
if fmt not in ("png", "jpg", "jpeg"):
|
if fmt not in ("png", "jpg", "jpeg"):
|
||||||
raise ValidationException("%r is not a valid image format" % fmt)
|
raise ValidationException("%r is not a valid image format" % fmt)
|
||||||
if fmt == "jpeg": fmt = "jpg"
|
if fmt == "jpeg": fmt = "jpg"
|
||||||
return fmt
|
return fmt
|
||||||
|
|
||||||
def validateImgQuality(qual):
|
def validateImgQuality(qual, **kwargs):
|
||||||
intqual = int(qual)
|
intqual = int(qual)
|
||||||
if (intqual < 0 or intqual > 100):
|
if (intqual < 0 or intqual > 100):
|
||||||
raise ValidationException("%r is not a valid image quality" % intqual)
|
raise ValidationException("%r is not a valid image quality" % intqual)
|
||||||
return intqual
|
return intqual
|
||||||
|
|
||||||
def validateBGColor(color):
|
def validateBGColor(color, **kwargs):
|
||||||
"""BG color must be an HTML color, with an option leading # (hash symbol)
|
"""BG color must be an HTML color, with an option leading # (hash symbol)
|
||||||
returns an (r,b,g) 3-tuple
|
returns an (r,b,g) 3-tuple
|
||||||
"""
|
"""
|
||||||
@@ -80,11 +74,20 @@ def validateBGColor(color):
|
|||||||
return color
|
return color
|
||||||
|
|
||||||
|
|
||||||
def validateOptImg(opt):
|
def validateOptImg(opt, **kwargs):
|
||||||
return bool(opt)
|
return bool(opt)
|
||||||
|
|
||||||
def validateTexturePath(path):
|
def validateTexturePath(path, **kwargs):
|
||||||
# Expand user dir in directories strings
|
# Expand user dir in directories strings
|
||||||
path = os.path.expanduser(path)
|
path = os.path.expanduser(path)
|
||||||
# TODO assert this path exists?
|
# 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.
|
but may be several per invocation of the Overviewer in the case of multi-world.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, worldobj, regiondir):
|
def __init__(self, regiondir):
|
||||||
self.world = worldobj
|
#self.world = worldobj
|
||||||
self.regiondir = regiondir
|
self.regiondir = regiondir
|
||||||
|
|
||||||
logging.info("Scanning regions")
|
logging.info("Scanning regions")
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
worldpath="test/data/settings/test_world"
|
world['test'] = "test/data/settings/test_world"
|
||||||
|
worldname = 'test'
|
||||||
|
|
||||||
rendermode = "normal"
|
rendermode = "normal"
|
||||||
|
|
||||||
render["world"] = {
|
render["world"] = {
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
bgcolor="#000000"
|
bgcolor="#000000"
|
||||||
|
|
||||||
|
world['test'] = "test/data/settings/test_world"
|
||||||
|
|
||||||
render["world"] = {
|
render["world"] = {
|
||||||
"worldpath": "test/data/settings/test_world",
|
"worldname": "test",
|
||||||
"bgcolor":"ffff"
|
"bgcolor":"ffff"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
|
world['test'] = "test/data/settings/test_world"
|
||||||
|
|
||||||
render["world"] = {
|
render["world"] = {
|
||||||
"worldpath": "test/data/settings/test_world",
|
"worldname": "test",
|
||||||
"rendermode": "bad_rendermode",
|
"rendermode": "bad_rendermode",
|
||||||
"northdirection": ["upper-left"],
|
"northdirection": ["upper-left"],
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user