allow input plugins and fonts directories to be set by environment when auto-loaded from python - closes #1594 - refs #1004

This commit is contained in:
Dane Springmeyer 2012-11-26 17:44:58 -08:00
parent 37804ed0a5
commit bffabbf99d

View file

@ -67,7 +67,8 @@ def bootstrap_env():
bootstrap_env() bootstrap_env()
from _mapnik import * from _mapnik import *
from paths import inputpluginspath, fontscollectionpath from paths import inputpluginspath
from paths import fontscollectionpath
import printing import printing
printing.renderer = render printing.renderer = render
@ -996,20 +997,27 @@ class _TextSymbolizer(TextSymbolizer,_injector):
self.properties.wrap_width = wrap_width self.properties.wrap_width = wrap_width
def mapnik_version_from_string(version_string): def mapnik_version_from_string(version_string):
"""Return the Mapnik version from a string.""" """Return the Mapnik version from a string."""
n = version_string.split('.') n = version_string.split('.')
return (int(n[0]) * 100000) + (int(n[1]) * 100) + (int(n[2])); return (int(n[0]) * 100000) + (int(n[1]) * 100) + (int(n[2]));
def register_plugins(path=inputpluginspath): def register_plugins(path=None):
"""Register plugins located by specified path""" """Register plugins located by specified path"""
if not path:
if os.environ.has_key('MAPNIK_INPUT_PLUGINS_DIRECTORY'):
path = os.environ.get('MAPNIK_INPUT_PLUGINS_DIRECTORY')
else:
path = inputpluginspath
DatasourceCache.register_datasources(path) DatasourceCache.register_datasources(path)
def register_fonts(path=fontscollectionpath,valid_extensions=['.ttf','.otf','.ttc','.pfa','.pfb','.ttc','.dfont']): def register_fonts(path=None,valid_extensions=['.ttf','.otf','.ttc','.pfa','.pfb','.ttc','.dfont']):
"""Recursively register fonts using path argument as base directory""" """Recursively register fonts using path argument as base directory"""
if not path:
if os.environ.has_key('MAPNIK_FONT_DIRECTORY'):
path = os.environ.get('MAPNIK_FONT_DIRECTORY')
else:
path = fontscollectionpath
for dirpath, _, filenames in os.walk(path): for dirpath, _, filenames in os.walk(path):
for filename in filenames: for filename in filenames:
if os.path.splitext(filename.lower())[1] in valid_extensions: if os.path.splitext(filename.lower())[1] in valid_extensions: