0

Add custom web assets support

This commit is contained in:
Thomas Lake
2012-08-12 15:27:07 +01:00
parent 5ff9c507b7
commit fcfe3063c3
4 changed files with 22 additions and 4 deletions

View File

@@ -352,7 +352,7 @@ dir but you forgot to put quotes around the directory, since it contains spaces.
# Now we start the actual processing, now that all the configuration has
# been gathered and validated
# create our asset manager... ASSMAN
assetMrg = assetmanager.AssetManager(destdir)
assetMrg = assetmanager.AssetManager(destdir, config.get('customwebassets', None))
tilesets = []

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
@@ -141,7 +142,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");

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.