Skip to content

Commit 444e905

Browse files
committed
adding support on windows for changing geosupport version at runtime
1 parent 805b530 commit 444e905

2 files changed

Lines changed: 44 additions & 7 deletions

File tree

geosupport/config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,5 @@
1717
'STATEN ISLAND': 5, 'SI': 5, 'STATEN IS': 5, 'RICHMOND': 5,
1818
'': '',
1919
}
20+
21+
USER_CONFIG = '~/.python-geosupport.cfg'

geosupport/geosupport.py

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,68 @@
11
from functools import partial
2+
import os
23
import sys
34

5+
try:
6+
from configparser import ConfigParser # Python 3
7+
except:
8+
from ConfigParser import ConfigParser # Python 2
9+
10+
from .config import USER_CONFIG
411
from .error import GeosupportError
512
from .function_info import FUNCTIONS, function_help, list_functions, input_help
613
from .io import format_input, parse_output, set_mode
714

15+
GEOLIB = None
16+
817
class Geosupport(object):
9-
def __init__(self):
18+
def __init__(self, geosupport_path=None, geosupport_version=None):
19+
global GEOLIB
1020
self.py_version = sys.version_info[0]
1121
self.platform = sys.platform
1222
self.py_bit = '64' if (sys.maxsize > 2 ** 32) else '32'
1323

24+
if geosupport_version is not None:
25+
config = ConfigParser()
26+
config.read(os.path.expanduser(USER_CONFIG))
27+
versions = dict(config['versions'].items())
28+
geosupport_path = versions[geosupport_version.lower()]
29+
30+
if geosupport_path is not None:
31+
os.environ['GEOFILES'] = os.path.join(geosupport_path, 'Fls\\')
32+
os.environ['PATH'] = ';'.join([
33+
i for i in os.environ['PATH'].split(';') if
34+
'GEOSUPPORT' not in i.upper()
35+
])
36+
os.environ['PATH'] += ';' + os.path.join(geosupport_path, 'bin')
37+
1438
try:
1539
if self.platform == 'win32':
40+
from ctypes import windll, cdll, WinDLL, wintypes
41+
42+
if GEOLIB is not None:
43+
kernel32 = WinDLL('kernel32')
44+
kernel32.FreeLibrary.argtypes = [wintypes.HMODULE]
45+
kernel32.FreeLibrary(GEOLIB._handle)
46+
1647
if self.py_bit == '64':
17-
from ctypes import cdll
1848
self.geolib = cdll.LoadLibrary("NYCGEO.dll")
1949
else:
20-
# must use windll for 32-bit Windows binaries
21-
from ctypes import windll
2250
self.geolib = windll.LoadLibrary("NYCGEO.dll")
2351
elif self.platform.startswith('linux'):
24-
import os
2552
from ctypes import cdll
53+
54+
if GEOLIB is not None:
55+
cdll.LoadLibrary('libdl.so').dlclose(GEOLIB._handle)
56+
2657
self.geolib = cdll.LoadLibrary("libgeo.so")
2758
else:
28-
raise Exception('This Operating System is currently not supported.')
59+
raise GeosupportError(
60+
'This Operating System is currently not supported.'
61+
)
62+
63+
GEOLIB = self.geolib
2964
except OSError as e:
30-
sys.exit(
65+
raise GeosupportError(
3166
'%s\n'
3267
'You are currently using a %s-bit Python interpreter. '
3368
'Is the installed version of Geosupport %s-bit?' % (

0 commit comments

Comments
 (0)