overhaul to configParser. Parsing config works now.
This commit is contained in:
@@ -1,54 +1,73 @@
|
||||
# This file defines all of the things than can
|
||||
# appear in a settings.py file, as well as the
|
||||
# function that can validate them
|
||||
# This file describes the format of the config file. Each item defined in this
|
||||
# module is expected to appear in the same format in a settings file. The only
|
||||
# difference is, instead of actual values for the settings, one is to use a
|
||||
# Setting object. Here is its signature:
|
||||
|
||||
# the validator should raise an exception if there
|
||||
# is a problem parsing or validating the value.
|
||||
# it should return the value to use (which gives
|
||||
# the validator an oppertunity to cleanup/normalize/
|
||||
# whaterver)
|
||||
# Setting(required, validator, default)
|
||||
|
||||
# if a setting is not required, the validator is
|
||||
# expected to return the default option
|
||||
# required is a boolean indicating the user is required to provide this
|
||||
# setting. In this case, default is unused and can be set to anything (None is
|
||||
# a good choice).
|
||||
|
||||
# validator is a callable that takes the provided value and returns a
|
||||
# cleaned/normalized value to use. It should raise an exception if there is a
|
||||
# problem parsing or validating the value given.
|
||||
|
||||
# default is used instead of the user-provided value in the event that required
|
||||
# is false. It is passed into the validator just the same. If default is None
|
||||
# and required is False, then that value is skipped entirely and will not
|
||||
# appear in the resulting parsed options.
|
||||
|
||||
# The signature for validators is validator(value_given). Remember that the
|
||||
# default is passed in as value_given in the event that required is False and
|
||||
# default is not None.
|
||||
|
||||
# This file doesn't specify the format or even the type of the setting values,
|
||||
# that is up to the validators used.
|
||||
|
||||
from settingsValidators import *
|
||||
|
||||
# note that all defaults go thought the validator
|
||||
render = {
|
||||
"type": dict,
|
||||
"valuetype": dict,
|
||||
"values": {
|
||||
"worldname": dict(required=True, validator=validateWorldPath, save_orig=True),
|
||||
"dimension": dict(required=False, validator=validateDimension, default="default"),
|
||||
"title": dict(required=True, validator=validateStr),
|
||||
"rendermode": dict(required=False, validator=validateRenderMode),
|
||||
"northdirection": dict(required=False, validator=validateNorthDirection, default=0),
|
||||
"renderrange": dict(required=False, validator=validateRenderRange),
|
||||
"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=validateBool),
|
||||
"texturepath": dict(required=False, validator=validateTexturePath),
|
||||
"renderchecks": dict(required=False, validator=validateInt, default=0),
|
||||
"rerenderprob": dict(required=False, validator=validateFloat, default=0),
|
||||
}
|
||||
# This is the export list for this module. It defines which items defined in
|
||||
# this module are recognized by the config parser. Don't forget to update this
|
||||
# if you add new items!
|
||||
__all__ = ['render', 'world', 'outputdir']
|
||||
|
||||
# render is a dictionary mapping names to dicts describing the configuration
|
||||
# for that render. It is therefore set to a settings object with a dict
|
||||
# validator configured to validate keys as strings and values as... values are
|
||||
# set to validate as a "configdict", which is a dict mapping a set of strings
|
||||
# to some value. the make_configdictvalidator function creates a validator to
|
||||
# use here configured with the given set of keys and Setting objects with their
|
||||
# respective validators.
|
||||
|
||||
# Perhaps unintuitively, this is set to required=False. Of course, if no
|
||||
# renders are specified, this is an error. However, this is caught later on in
|
||||
# the code, and it also lets an empty dict get defined beforehand for the
|
||||
# config file.
|
||||
render = Setting(required=False, default={},
|
||||
validator=dictValidator(validateStr, make_configdictvalidator(
|
||||
{
|
||||
"worldname": Setting(required=True, validator=validateStr, default=None),
|
||||
"dimension": Setting(required=False, validator=validateDimension, default="default"),
|
||||
"title": Setting(required=True, validator=validateStr, default=None),
|
||||
"rendermode": Setting(required=False, validator=validateRenderMode, default=None),
|
||||
"northdirection": Setting(required=False, validator=validateNorthDirection, default=0),
|
||||
"renderrange": Setting(required=False, validator=validateRenderRange, default=None),
|
||||
"forcerender": Setting(required=False, validator=validateBool, default=None),
|
||||
"stochasticrender": Setting(required=False, validator=validateStochastic, default=None),
|
||||
"imgformat": Setting(required=False, validator=validateImgFormat, default="png"),
|
||||
"imgquality": Setting(required=False, validator=validateImgQuality, default=None),
|
||||
"bgcolor": Setting(required=False, validator=validateBGColor, default="1a1a1a"),
|
||||
"optimizeimg": Setting(required=False, validator=validateOptImg, default=0),
|
||||
"nomarkers": Setting(required=False, validator=validateBool, default=None),
|
||||
"texturepath": Setting(required=False, validator=validateTexturePath, default=None),
|
||||
"renderchecks": Setting(required=False, validator=validateInt, default=0),
|
||||
"rerenderprob": Setting(required=False, validator=validateFloat, default=0),
|
||||
}
|
||||
)))
|
||||
|
||||
world = {
|
||||
"type": dict,
|
||||
"valuetype": str,
|
||||
"value": dict(validator=validateStr)
|
||||
}
|
||||
|
||||
outputdir = {
|
||||
"type": str,
|
||||
"value": dict(validator=validateOutputDir)
|
||||
}
|
||||
|
||||
#defines the values for each member of the world dict
|
||||
#world = dict(require
|
||||
# The world dict, mapping world names to world paths
|
||||
world = Setting(required=False, validator=dictValidator(validateStr, validateWorldPath), default={})
|
||||
|
||||
outputdir = Setting(required=True, validator=validateOutputDir, default=None)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user