0

Changed "worldname" to "world" in configfile

Also brought tests up to date. All tests pass now.
This commit is contained in:
Andrew Brown
2012-02-14 20:39:05 -05:00
parent f3b434a327
commit aaf8e1d7cb
10 changed files with 81 additions and 57 deletions

View File

@@ -22,7 +22,7 @@ A Simple Example
worlds["My world"] = "/home/username/server/world" worlds["My world"] = "/home/username/server/world"
render["normalrender"] = { render["normalrender"] = {
"worldname": "My world", "world": "My world",
"title": "Normal Render of My World", "title": "Normal Render of My World",
} }
@@ -60,28 +60,28 @@ A more complicated example
worlds["creative"] = "/home/username/server/creativeworld" worlds["creative"] = "/home/username/server/creativeworld"
renders["survivalday"] = { renders["survivalday"] = {
"worldname": "survival", "world": "survival",
"title": "Survival Daytime", "title": "Survival Daytime",
"rendermode": smooth_lighting, "rendermode": smooth_lighting,
"dimension": "overworld", "dimension": "overworld",
} }
renders["survivalnight"] = { renders["survivalnight"] = {
"worldname": "survival", "world": "survival",
"title": "Survival Daytime", "title": "Survival Daytime",
"rendermode": smooth_night, "rendermode": smooth_night,
"dimension": "overworld", "dimension": "overworld",
} }
renders["survivalnether"] = { renders["survivalnether"] = {
"worldname": "survival", "world": "survival",
"title": "Survival Nether", "title": "Survival Nether",
"rendermode": nether_smooth_lighting, "rendermode": nether_smooth_lighting,
"dimension": "nether", "dimension": "nether",
} }
renders["survivalspawnoverlay"] = { renders["survivalspawnoverlay"] = {
"worldname": "survival", "world": "survival",
"title": "Spawn Overlay", "title": "Spawn Overlay",
"rendermode": spawn_overlay, "rendermode": spawn_overlay,
"dimension": "overworld", "dimension": "overworld",
@@ -89,7 +89,7 @@ A more complicated example
} }
renders["creative"] = { renders["creative"] = {
"worldname": "creative", "world": "creative",
"title": "Creative", "title": "Creative",
"rendermode": smooth_lighting, "rendermode": smooth_lighting,
"dimension": "overworld", "dimension": "overworld",
@@ -152,7 +152,7 @@ Overviewer's rendering.
Render Dictonary Keys Render Dictonary Keys
--------------------- ---------------------
``worldname`` ``world``
Specifies which world this render corresponds to. Its value should be a Specifies which world this render corresponds to. Its value should be a
string from the appropriate key in the worlds dictionary. string from the appropriate key in the worlds dictionary.
@@ -363,7 +363,7 @@ primitive object's constructor::
Then you can use your new rendermode in your render definitions:: Then you can use your new rendermode in your render definitions::
render["survivalday"] = { render["survivalday"] = {
"worldname": "survival", "world": "survival",
"title": "Survival Daytime", "title": "Survival Daytime",
"rendermode": my_rendermode, "rendermode": my_rendermode,
"dimension": "overworld", "dimension": "overworld",

View File

@@ -194,7 +194,7 @@ def main():
print "worlds['myworld'] = %r" % args[0] print "worlds['myworld'] = %r" % args[0]
print "outputdir = %r" % (args[1] if len(args) > 1 else "/path/to/output") print "outputdir = %r" % (args[1] if len(args) > 1 else "/path/to/output")
print print
logging.error("Cannot specify both --config and worldname / output directory") logging.error("Cannot specify both --config AND a world + output directory on the command line.")
parser.print_help() parser.print_help()
return 1 return 1
@@ -238,7 +238,7 @@ dir but you forgot to put quotes around the directory, since it contains spaces.
renders = {} renders = {}
for rm in rendermodes: for rm in rendermodes:
renders["world-" + rm] = { renders["world-" + rm] = {
"worldname": "world", "world": "world",
"title": "Overviewer Render (%s)" % rm, "title": "Overviewer Render (%s)" % rm,
"rendermode": rm, "rendermode": rm,
} }
@@ -274,16 +274,16 @@ dir but you forgot to put quotes around the directory, since it contains spaces.
return 1 return 1
for rname, render in config['renders'].iteritems(): for rname, render in config['renders'].iteritems():
# Convert render['worldname'] to the world path, and store the original # Convert render['world'] to the world path, and store the original
# in render['worldname_orig'] # in render['worldname_orig']
try: try:
worldpath = config['worlds'][render['worldname']] worldpath = config['worlds'][render['world']]
except KeyError: except KeyError:
logging.error("Render %s's world is '%s', but I could not find a corresponding entry in the worlds dictionary.", logging.error("Render %s's world is '%s', but I could not find a corresponding entry in the worlds dictionary.",
rname, render['worldname']) rname, render['world'])
return 1 return 1
render['worldname_orig'] = render['worldname'] render['worldname_orig'] = render['world']
render['worldname'] = worldpath render['world'] = worldpath
destdir = config['outputdir'] destdir = config['outputdir']
if not destdir: if not destdir:
@@ -319,11 +319,11 @@ dir but you forgot to put quotes around the directory, since it contains spaces.
logging.debug("Found the following render thing: %r", render) logging.debug("Found the following render thing: %r", render)
# find or create the world object # find or create the world object
if (render['worldname'] not in worldcache): if (render['world'] not in worldcache):
w = world.World(render['worldname']) w = world.World(render['world'])
worldcache[render['worldname']] = w worldcache[render['world']] = w
else: else:
w = worldcache[render['worldname']] w = worldcache[render['world']]
# find or create the textures object # find or create the textures object
texopts = util.dict_subset(render, ["texturepath", "bgcolor", "northdirection"]) texopts = util.dict_subset(render, ["texturepath", "bgcolor", "northdirection"])

View File

@@ -58,7 +58,7 @@ from settingsValidators import *
renders = Setting(required=True, default={}, renders = Setting(required=True, default={},
validator=make_dictValidator(validateStr, make_configDictValidator( validator=make_dictValidator(validateStr, make_configDictValidator(
{ {
"worldname": Setting(required=True, validator=validateStr, default=None), "world": Setting(required=True, validator=validateStr, default=None),
"dimension": Setting(required=True, validator=validateDimension, default="default"), "dimension": Setting(required=True, validator=validateDimension, default="default"),
"title": Setting(required=True, validator=validateStr, default=None), "title": Setting(required=True, validator=validateStr, default=None),
"rendermode": Setting(required=True, validator=validateRenderMode, default='normal'), "rendermode": Setting(required=True, validator=validateRenderMode, default='normal'),
@@ -74,6 +74,10 @@ renders = Setting(required=True, default={},
"texturepath": Setting(required=False, validator=validateTexturePath, default=None), "texturepath": Setting(required=False, validator=validateTexturePath, default=None),
"renderchecks": Setting(required=True, validator=validateInt, default=0), "renderchecks": Setting(required=True, validator=validateInt, default=0),
"rerenderprob": Setting(required=True, validator=validateFloat, default=0), "rerenderprob": Setting(required=True, validator=validateFloat, default=0),
# Remove this eventually (once people update their configs)
"worldname": Setting(required=False, default=None,
validator=error("The option 'worldname' is now called 'world'. Please update your config files")),
} }
))) )))

View File

@@ -188,3 +188,8 @@ def make_configDictValidator(config, ignore_undefined=False):
return newdict return newdict
return configDictValidator return configDictValidator
def error(errstr):
def validator(_):
raise ValidationException(errstr)
return validator

View File

@@ -244,6 +244,13 @@ class TileSet(object):
that a tile which is not marked for render by any mtime checks will that a tile which is not marked for render by any mtime checks will
be rendered anyways. 0 disables this option. be rendered anyways. 0 disables this option.
Other options that must be specified but aren't really documented
(oops. consider it a TODO):
* worldname_orig
* dimension
* title
* name
""" """
self.options = options self.options = options
self.regionset = regionsetobj self.regionset = regionsetobj

View File

@@ -1,15 +1,15 @@
world['test'] = "test/data/settings/test_world" worlds['test'] = "test/data/settings/test_world"
render["myworld"] = { renders["myworld"] = {
"title": "myworld title", "title": "myworld title",
"worldname": "test", "world": "test",
"rendermode": normal, "rendermode": normal,
"northdirection": "upper-left", "northdirection": "upper-left",
} }
render["otherworld"] = { renders["otherworld"] = {
"title": "otherworld title", "title": "otherworld title",
"worldname": "test", "world": "test",
"rendermode": normal, "rendermode": normal,
"bgcolor": "#ffffff" "bgcolor": "#ffffff"
} }

View File

@@ -1,7 +1,7 @@
world['test'] = "test/data/settings/test_world" worlds['test'] = "test/data/settings/test_world"
render["world"] = { renders["world"] = {
"worldname": "test", "world": "test",
"title": "myworld title", "title": "myworld title",
"rendermode": "bad_rendermode", "rendermode": "bad_rendermode",
"northdirection": "upper-left", "northdirection": "upper-left",

View File

@@ -12,5 +12,23 @@ from test_rendertileset import RendertileSetTest
from test_settings import SettingsTest from test_settings import SettingsTest
from test_tileset import TilesetTest from test_tileset import TilesetTest
# DISABLE THIS BLOCK TO GET LOG OUTPUT FROM TILESET FOR DEBUGGING
if 0:
import logging
root = logging.getLogger()
class NullHandler(logging.Handler):
def handle(self, record):
pass
def emit(self, record):
pass
def createLock(self):
self.lock = None
root.addHandler(NullHandler())
else:
import overviewer
import logging
overviewer.configure_logger(logging.DEBUG, True)
if __name__ == "__main__": if __name__ == "__main__":
unittest.main() unittest.main()

View File

@@ -21,12 +21,12 @@ class SettingsTest(unittest.TestCase):
# no exceptions so far. that's a good thing # no exceptions so far. that's a good thing
# Test the default # Test the default
self.assertEquals(things['render']['myworld']['bgcolor'], (26,26,26,0)) self.assertEquals(things['renders']['myworld']['bgcolor'], (26,26,26,0))
# Test a non-default # Test a non-default
self.assertEquals(things['render']['otherworld']['bgcolor'], (255,255,255,0)) self.assertEquals(things['renders']['otherworld']['bgcolor'], (255,255,255,0))
self.assertEquals(things['render']['myworld']['northdirection'], self.assertEquals(things['renders']['myworld']['northdirection'],
world.UPPER_LEFT) world.UPPER_LEFT)
def test_rendermode_validation(self): def test_rendermode_validation(self):
@@ -42,20 +42,20 @@ class SettingsTest(unittest.TestCase):
fromfile = configParser.MultiWorldParser() fromfile = configParser.MultiWorldParser()
fromfile.parse("test/data/settings/settings_test_1.py") fromfile.parse("test/data/settings/settings_test_1.py")
self.s.set_config_item("world", { self.s.set_config_item("worlds", {
'test': "test/data/settings/test_world", 'test': "test/data/settings/test_world",
}) })
self.s.set_config_item("render", { self.s.set_config_item("renders", {
"myworld": { "myworld": {
"title": "myworld title", "title": "myworld title",
"worldname": "test", "world": "test",
"rendermode": rendermodes.normal, "rendermode": rendermodes.normal,
"northdirection": "upper-left", "northdirection": "upper-left",
}, },
"otherworld": { "otherworld": {
"title": "otherworld title", "title": "otherworld title",
"worldname": "test", "world": "test",
"rendermode": rendermodes.normal, "rendermode": rendermodes.normal,
"bgcolor": "#ffffff" "bgcolor": "#ffffff"
}, },
@@ -64,20 +64,20 @@ class SettingsTest(unittest.TestCase):
self.assertEquals(fromfile.get_validated_config(), self.s.get_validated_config()) self.assertEquals(fromfile.get_validated_config(), self.s.get_validated_config())
def test_rendermode_string(self): def test_rendermode_string(self):
self.s.set_config_item("world", { self.s.set_config_item("worlds", {
'test': "test/data/settings/test_world", 'test': "test/data/settings/test_world",
}) })
self.s.set_config_item("outputdir", "/tmp/fictional/outputdir") self.s.set_config_item("outputdir", "/tmp/fictional/outputdir")
self.s.set_config_item("render", { self.s.set_config_item("renders", {
"myworld": { "myworld": {
"title": "myworld title", "title": "myworld title",
"worldname": "test", "world": "test",
"rendermode": "normal", "rendermode": "normal",
"northdirection": "upper-left", "northdirection": "upper-left",
}, },
}) })
p = self.s.get_validated_config() p = self.s.get_validated_config()
self.assertEquals(p['render']['myworld']['rendermode'], rendermodes.normal) self.assertEquals(p['renders']['myworld']['rendermode'], rendermodes.normal)
if __name__ == "__main__": if __name__ == "__main__":
unittest.main() unittest.main()

View File

@@ -8,23 +8,6 @@ import random
from overviewer_core import tileset, util from overviewer_core import tileset, util
# DISABLE THIS BLOCK TO GET LOG OUTPUT FROM TILESET FOR DEBUGGING
if 1:
import logging
root = logging.getLogger()
class NullHandler(logging.Handler):
def handle(self, record):
pass
def emit(self, record):
pass
def createLock(self):
self.lock = None
root.addHandler(NullHandler())
else:
import overviewer
import logging
overviewer.configure_logger(logging.DEBUG, True)
# Supporing data # Supporing data
# chunks list: chunkx, chunkz mapping to chunkmtime # chunks list: chunkx, chunkz mapping to chunkmtime
# In comments: col, row # In comments: col, row
@@ -121,6 +104,13 @@ class FakeRegionset(object):
except KeyError: except KeyError:
return None return None
class FakeAssetmanager(object):
def __init__(self, lastrendertime):
self.lrm = lastrendertime
def get_tileset_config(self, _):
return {'lastrendertime': self.lrm}
def get_tile_set(chunks): def get_tile_set(chunks):
"""Given the dictionary mapping chunk coordinates their mtimes, returns a """Given the dictionary mapping chunk coordinates their mtimes, returns a
dict mapping the tiles that are to be rendered to their mtimes that are dict mapping the tiles that are to be rendered to their mtimes that are
@@ -201,7 +191,7 @@ class TilesetTest(unittest.TestCase):
'rerenderprob': 0 'rerenderprob': 0
} }
defoptions.update(options) defoptions.update(options)
ts = tileset.TileSet(self.rs, None, None, defoptions, outputdir) ts = tileset.TileSet(self.rs, FakeAssetmanager(0), None, defoptions, outputdir)
if preprocess: if preprocess:
preprocess(ts) preprocess(ts)
ts.do_preprocessing() ts.do_preprocessing()