/
__init__.py
67 lines (46 loc) · 1.86 KB
/
__init__.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
""" cascadnik - cascading sheets of style for mapnik
http://mike.teczno.com/notes/cascadenik.html
http://code.google.com/p/mapnik-utils/wiki/Cascadenik
"""
from os import mkdir, chmod
from os.path import isdir, realpath, expanduser, dirname, exists
from urlparse import urlparse
from . import style
from .parse import stylesheet_declarations
# compile module -> "_compile"
from . import compile as _compile
# compile function -> "compile"
from .compile import compile, Directories
# define Cascadenik version
VERSION = '1.0.0'
CACHE_DIR = '~/.cascadenik'
__all__ = ['load_map', 'compile','_compile','style','stylesheet_declarations']
def load_map(map, src_file, output_dir, cache_dir=None, datasources_cfg=None, verbose=False):
""" Apply a stylesheet source file to a given mapnik Map instance, like mapnik.load_map().
Parameters:
map:
Instance of mapnik.Map.
src_file:
Location of stylesheet .mml file. Can be relative path, absolute path,
or fully-qualified URL of a remote stylesheet.
output_dir:
...
Keyword Parameters:
cache_dir:
...
datasources_cfg:
...
verbose:
...
"""
scheme, n, path, p, q, f = urlparse(src_file)
if scheme in ('file', ''):
assert exists(src_file), "We'd prefer an input file that exists to one that doesn't"
if cache_dir is None:
cache_dir = expanduser(CACHE_DIR)
# only make the cache dir if it wasn't user-provided
if not isdir(cache_dir):
mkdir(cache_dir)
chmod(cache_dir, 0755)
dirs = Directories(output_dir, realpath(cache_dir), dirname(src_file))
compile(src_file, dirs, verbose, datasources_cfg=datasources_cfg).to_mapnik(map, dirs)