0

Merge branch 'upstream' into biomesoverlay

This commit is contained in:
Thomas Lake
2012-08-30 10:16:37 +01:00
6 changed files with 70 additions and 16 deletions

View File

@@ -33,13 +33,14 @@ same time, controls the generated javascript files in the output directory.
There should only be one instances of these per execution.
"""
def __init__(self, outputdir):
def __init__(self, outputdir, custom_assets_dir=None):
"""\
Initializes the AssetManager with the top-level output directory.
It can read/parse and write/dump the overviewerConfig.js file into this top-level
directory.
"""
self.outputdir = outputdir
self.custom_assets_dir = custom_assets_dir
self.renders = dict()
# look for overviewerConfig in self.outputdir
@@ -134,6 +135,17 @@ directory.
blank = Image.new("RGBA", (1,1), tileset.options.get('bgcolor'))
blank.save(os.path.join(self.outputdir, tileset.options.get('name'), "blank." + tileset.options.get('imgformat')))
# write out config
jsondump = json.dumps(dump, indent=4)
with FileReplacer(os.path.join(self.outputdir, "overviewerConfig.js")) as tmpfile:
with codecs.open(tmpfile, 'w', encoding='UTF-8') as f:
f.write("var overviewerConfig = " + jsondump + ";\n")
#Copy assets, modify index.html
self.output_noconfig()
def output_noconfig(self):
# copy web assets into destdir:
global_assets = os.path.join(util.get_program_path(), "overviewer_core", "data", "web_assets")
@@ -141,7 +153,12 @@ directory.
global_assets = os.path.join(util.get_program_path(), "web_assets")
mirror_dir(global_assets, self.outputdir)
# write a dummy baseMarkers.js if none exists
if self.custom_assets_dir:
# Could have done something fancy here rather than just overwriting
# the global files, but apparently this what we used to do pre-rewrite.
mirror_dir(self.custom_assets_dir, self.outputdir)
# write a dummy baseMarkers.js if none exists
if not os.path.exists(os.path.join(self.outputdir, "baseMarkers.js")):
with open(os.path.join(self.outputdir, "baseMarkers.js"), "w") as f:
f.write("// if you wants signs, please see genPOI.py\n");
@@ -162,12 +179,6 @@ directory.
with open(os.path.join(js_src,js)) as f:
fout.write(f.read())
# write out config
jsondump = json.dumps(dump, indent=4)
with FileReplacer(os.path.join(self.outputdir, "overviewerConfig.js")) as tmpfile:
with codecs.open(tmpfile, 'w', encoding='UTF-8') as f:
f.write("var overviewerConfig = " + jsondump + ";\n")
# Add time and version in index.html
indexpath = os.path.join(self.outputdir, "index.html")

View File

@@ -84,7 +84,7 @@ renders = Setting(required=True, default=util.OrderedDict(),
"showspawn": Setting(required=False, validator=validateBool, default=True),
"base": Setting(required=False, validator=validateStr, default=""),
"poititle": Setting(required=False, validator=validateStr, default="Signs"),
"customwebassets": Setting(required=False, validator=validateWebAssetsPath, default=None),
# 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

@@ -214,6 +214,18 @@ def validateDefaultZoom(z):
else:
raise ValidationException("The default zoom is set below 1")
def validateWebAssetsPath(p):
try:
validatePath(p)
except ValidationException as e:
raise ValidationException("Bad custom web assets path: %s" % e.message)
def validatePath(p):
_, path = checkBadEscape(p)
abs_path = expand_path(path)
if not os.path.exists(abs_path):
raise ValidationException("'%s' does not exist. Path initially given as '%s'" % (abs_path,p))
def make_dictValidator(keyvalidator, valuevalidator):
"""Compose and return a dict validator -- a validator that validates each
key and value in a dictionary.