Skip to content

Commit

Permalink
separating make from configure
Browse files Browse the repository at this point in the history
Also adding a build dir so we don't change the files in osm-bright,
making it much easier to work on the code and commit it to source
control
  • Loading branch information
llimllib committed Feb 2, 2012
1 parent 2707dbf commit d969e34
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 31 deletions.
31 changes: 0 additions & 31 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,34 +31,3 @@
# - http://tile.openstreetmap.org/shoreline_300.tar.bz2
processed_p = "http://tilemill-data.s3.amazonaws.com/osm/coastline-good.zip"
shoreline_300 = "http://tilemill-data.s3.amazonaws.com/osm/shoreline_300.zip"

################################################################################

import json
from sys import path
from os.path import join

template = join(path[0], 'osm-bright.' + config["importer"] + '.mml')
output = join(path[0], 'osm-bright', 'project.mml')

with open(template, 'r') as f:
newf = json.loads(f.read())
f.closed

with open(output, 'w') as f:
for layer in newf["Layer"]:
if layer["id"] == "shoreline_300":
layer["Datasource"]["file"] = shoreline_300
elif (layer["id"] == "processed_p") or (layer["id"] == "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
f.write(json.dumps(newf, sort_keys=True, indent=2))
f.closed

51 changes: 51 additions & 0 deletions make.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env python

import json
from os import unlink, mkdir, listdir, chdir, getcwd
from sys import path
from glob import glob
from shutil import copytree, rmtree
from os.path import join, isdir, split

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()
File renamed without changes.
File renamed without changes.

0 comments on commit d969e34

Please sign in to comment.