-
Notifications
You must be signed in to change notification settings - Fork 225
/
Copy pathmake.py
executable file
·50 lines (40 loc) · 1.37 KB
/
make.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
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python
import json
from os import unlink
from glob import glob
from shutil import copytree, rmtree
from os.path import join, isdir
from configure import config, processed_p, shoreline_300
def clean():
if isdir("build"):
rmtree("build")
for f in glob("build/*.html"): unlink(f)
def build():
#copy the osm-bright tree to a build dir
copytree("osm-bright", "build")
#remove the mml templates
for f in glob("build/*.mml"):
unlink(f)
#load the project template
templatefile = open(join('osm-bright', 'osm-bright.%s.mml' % config["importer"]))
template = json.loads(templatefile.read())
#fill in the project template
for layer in template["Layer"]:
if layer["id"] == "shoreline_300":
layer["Datasource"]["file"] = shoreline_300
elif layer["id"] in ("processed_p", "processed_p_outline"):
layer["Datasource"]["file"] = processed_p
else:
# Assume all other layers are PostGIS layers
for opt, val in config["postgis"].iteritems():
if (val == ""):
if (opt in layer["Datasource"]):
del layer["Datasource"][opt]
else:
layer["Datasource"][opt] = val
#dump the filled-in project template to the build dir
with open(join('build', 'project.mml'), 'w') as output:
output.write(json.dumps(template, sort_keys=True, indent=2))
if __name__ == "__main__":
clean()
build()