From 4fd41a47071fbc03e7d845f05a8633fc1dc272f0 Mon Sep 17 00:00:00 2001 From: Massimo DiPierro Date: Fri, 4 May 2012 10:47:24 -0500 Subject: [PATCH] portable spatialite import, issue 774, thanks TheBigBamboozle and Denes --- VERSION | 2 +- gluon/dal.py | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/VERSION b/VERSION index 224f867e..49dcae34 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -Version 1.99.7 (2012-05-04 10:27:00) dev +Version 1.99.7 (2012-05-04 10:47:21) dev diff --git a/gluon/dal.py b/gluon/dal.py index 9561380d..c88fc43a 100644 --- a/gluon/dal.py +++ b/gluon/dal.py @@ -134,6 +134,11 @@ DEFAULTLENGTH = {'string':512, 'text':2**15, 'blob':2**31} TIMINGSSIZE = 100 +SPATIALLIBS = { + 'Windows':'libspatialite', + 'Linux':'libspatialite.so', + 'Darwin':'libspatialite.dylib' + } import re import sys @@ -161,6 +166,7 @@ import hashlib import uuid import glob import traceback +import platform CALLABLETYPES = (types.LambdaType, types.FunctionType, types.BuiltinFunctionType, types.MethodType, types.BuiltinMethodType) @@ -1875,8 +1881,9 @@ class SpatiaLiteAdapter(SQLiteAdapter): self.connection.enable_load_extension(True) # for Windows, rename libspatialite-2.dll as libspatialite.dll # Linux uses libspatialite.so - # Mac OS X uses libspatialite.dylib - self.execute(r'SELECT load_extension("libspatialite");') + # Mac OS X uses libspatialite.dylib + libspatialite = SPATIALLIBS[platform.system()] + self.execute(r'SELECT load_extension("%s");') % libspatialite self.connection.create_function('web2py_extract', 2, SQLiteAdapter.web2py_extract)