1.changed python mapnik.python module name to _mapnik

2.more 'pythonic' module tree
3.moved datasource init into __init__.py
(no more 'ugly' setdlflags) - needs testing
4.datasources dir is now set by the build process (require 2.4)
5.methods (e.g __repr__) can be 'injected' from python (see mapnik/__init__.py)
This commit is contained in:
Artem Pavlenko 2005-09-01 19:20:37 +00:00
parent e01a831850
commit 9f32454ae9
4 changed files with 101 additions and 4 deletions

View file

@ -52,7 +52,7 @@ freetype2_root = env['FREETYPE2_ROOT']
def createPythonExtBuilder(env): def createPythonExtBuilder(env):
"""This is a utility function that creates boost-python """This is a utility function that creates boost-python
etxension Builder in an Environment if it is not there already. extension Builder in an Environment if it is not there already.
If it is already there, we return the existing one. If it is already there, we return the existing one.
""" """
@ -96,6 +96,27 @@ headers =[ '#include',boost_root,freetype2_root,agg_headers,python_headers]
libraries=['mapnik','agg','boost-filesystem','boost-regex','boost-python'] libraries=['mapnik','agg','boost-filesystem','boost-regex','boost-python']
libpaths = [prefix+"/lib",'#agg'] libpaths = [prefix+"/lib",'#agg']
mapnik_python = env.PythonExtension(target='mapnik',source=mapnik_python_src,CPPPATH=headers,LIBS=libraries,LIBPATH=libpaths) _mapnik_python = env.PythonExtension(target='_mapnik',\
source=mapnik_python_src,\
CPPPATH=headers,\
LIBS=libraries,\
LIBPATH=libpaths)
env.Alias(target="install",source=env.Install(prefix+'/lib',mapnik_python)) def substitute_prefix(target,source,env):
from string import Template
s = Template(source[0].get_contents())
str = s.substitute(PREFIX=prefix)
_out = file(target[0].abspath,'w')
_out.write(str)
_out.close()
return None
env.Command('mapnik/__init__.py','mapnik/__init__.py.in', substitute_prefix)
__init1__ = env.Install(prefix+'/lib','__init__.py')
__init2__ = env.Install(prefix+'/lib/mapnik','mapnik/__init__.py')
_source=env.Install(prefix+'/lib/mapnik',_mapnik_python)
_source.append(__init1__)
_source.append(__init2__)
env.Alias(target="install",source=_source)

20
python/__init__.py Normal file
View file

@ -0,0 +1,20 @@
#
# This file is part of Mapnik (C++/Python mapping toolkit)
# Copyright (C) 2005 Artem Pavlenko
#
# Mapnik is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
#$Id$
#

View file

@ -0,0 +1,56 @@
#
# This file is part of Mapnik (C++/Python mapping toolkit)
# Copyright (C) 2005 Artem Pavlenko
#
# Mapnik is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
#
#
#
from sys import getdlopenflags,setdlopenflags
from dl import RTLD_NOW,RTLD_GLOBAL
flags = getdlopenflags()
setdlopenflags(RTLD_NOW | RTLD_GLOBAL)
from _mapnik import *
# The base Boost.Python class
BoostPythonMetaclass = coord.__class__
class _injector(object):
class __metaclass__(BoostPythonMetaclass):
def __init__(self, name, bases, dict):
for b in bases:
if type(b) not in (self, type):
for k,v in dict.items():
setattr(b,k,v)
return type.__init__(self, name, bases, dict)
class _coord(coord,_injector):
def __repr__(self):
return 'coord(%s,%s)' % (self.x, self.y)
class _envelope(envelope,_injector):
def __repr__(self):
return 'envelope(%s,%s,%s,%s)' % \
(self.minx,self.miny,self.maxx,self.maxy)
#register datasources
from mapnik import datasource_cache
datasource_cache.instance().register_datasources("${PREFIX}/datasources")
#set dlopen flags back to the original
setdlopenflags(flags)

View file

@ -103,7 +103,7 @@ ref_ptr<symbolizer> create_polygon_symbolizer2(std::string const& file,unsigned
return ref_ptr<symbolizer>(new pattern_symbolizer(file,"png",w,h)); return ref_ptr<symbolizer>(new pattern_symbolizer(file,"png",w,h));
} }
BOOST_PYTHON_MODULE(mapnik) BOOST_PYTHON_MODULE(_mapnik)
{ {
using namespace boost::python; using namespace boost::python;