forked from mapnik/node-mapnik
-
Notifications
You must be signed in to change notification settings - Fork 2
/
gen_settings.py
39 lines (31 loc) · 1.24 KB
/
gen_settings.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import os
import sys
settings = os.path.abspath(sys.argv[1])
# this goes into a mapnik_settings.js file beside the C++ _mapnik.node
settings_template = """
module.exports.paths = {
'fonts': %s,
'input_plugins': %s
};
"""
def write_mapnik_settings(fonts='undefined',input_plugins='undefined'):
global settings_template
if '__dirname' in fonts or '__dirname' in input_plugins:
settings_template = "var path = require('path');\n" + settings_template
open(settings,'w').write(settings_template % (fonts,input_plugins))
if __name__ == '__main__':
settings_dict = {}
# settings for fonts and input plugins
# environment settings are for windows tilemill packaging:
# https://github.com/mapbox/tilemill/blob/master/platforms/windows/package.bat#L37
ip = os.environ.get('MAPNIK_INPUT_PLUGINS')
if ip:
settings_dict['input_plugins'] = ip
else:
settings_dict['input_plugins'] = '\'%s\'' % os.popen("mapnik-config --input-plugins").readline().strip()
mf = os.environ.get('MAPNIK_FONTS')
if mf:
settings_dict['fonts'] = mf
else:
settings_dict['fonts'] = '\'%s\'' % os.popen("mapnik-config --fonts").readline().strip()
write_mapnik_settings(**settings_dict)