-
Notifications
You must be signed in to change notification settings - Fork 84
/
_library_singleton.py
55 lines (42 loc) · 1.59 KB
/
_library_singleton.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
# -*- coding: utf-8 -*-
# This file was generated
import platform
import ctypes
import ctypes.util
import nimodinst._library as _library
import nimodinst.errors as errors
import threading
_instance = None
_instance_lock = threading.Lock()
_library_info = {'Linux': {'64bit': {'name': 'nimodinst', 'type': 'cdll'}},
'Windows': {'32bit': {'name': 'nimodinst.dll', 'type': 'windll'},
'64bit': {'name': 'nimodinst_64.dll', 'type': 'cdll'}}}
def _get_library_name():
try:
return ctypes.util.find_library(_library_info[platform.system()][platform.architecture()[0]]['name']) # We find and return full path to the DLL
except KeyError:
raise errors.UnsupportedConfigurationError
def _get_library_type():
try:
return _library_info[platform.system()][platform.architecture()[0]]['type']
except KeyError:
raise errors.UnsupportedConfigurationError
def get():
'''get
Returns the library.Library singleton for nimodinst.
'''
global _instance
global _instance_lock
with _instance_lock:
if _instance is None:
try:
library_type = _get_library_type()
if library_type == 'windll':
ctypes_library = ctypes.WinDLL(_get_library_name())
else:
assert library_type == 'cdll'
ctypes_library = ctypes.CDLL(_get_library_name())
except OSError:
raise errors.DriverNotInstalledError()
_instance = _library.Library(ctypes_library)
return _instance