diff options
author | Stany MARCEL <stanypub@gmail.com> | 2015-12-08 23:23:24 +0300 |
---|---|---|
committer | Stany MARCEL <stanypub@gmail.com> | 2015-12-08 23:23:24 +0300 |
commit | 973db31eb95c635ac070052614d4c4b52ba40ee9 (patch) | |
tree | f064e73a4128cf692c08f625151bdbc67ae911b7 /src | |
parent | 054e35d619b07cb6f166f267addd2e56a554a78d (diff) | |
parent | db7b12a765bb6ffc07ae83d447b0bd85d888d676 (diff) |
Merge pull request #9 from syr1us/get_so_extensions
Change get_so_extension in tools.py to get_so_extensions to yield all possible extensions.
Refactor uinput.py to take first valid so extension.
Diffstat (limited to 'src')
-rw-r--r-- | src/tools.py | 4 | ||||
-rw-r--r-- | src/uinput.py | 33 |
2 files changed, 26 insertions, 11 deletions
diff --git a/src/tools.py b/src/tools.py index fd2197b..be9b0ff 100644 --- a/src/tools.py +++ b/src/tools.py @@ -36,8 +36,8 @@ def static_vars(**kwargs): return func return decorate -def get_so_extension(): +def get_so_extensions(): """Return so file extenstion compatible with python and pypy""" for ext, _, typ in imp.get_suffixes(): if typ == imp.C_EXTENSION: - return ext + yield ext diff --git a/src/uinput.py b/src/uinput.py index 80a5050..6a92ba6 100644 --- a/src/uinput.py +++ b/src/uinput.py @@ -29,7 +29,7 @@ from math import pi, copysign, sqrt from enum import IntEnum from steamcontroller.cheader import defines -from steamcontroller.tools import get_so_extension +from steamcontroller.tools import get_so_extensions from collections import deque @@ -183,7 +183,6 @@ class UInput(object): def __init__(self, vendor, product, name, keys, axes, rels, keyboard=False): - self._lib = None self._k = keys if not axes or len(axes) == 0: @@ -192,13 +191,29 @@ class UInput(object): self._a, self._amin, self._amax, self._afuzz, self._aflat = zip(*axes) self._r = rels - - lib = os.path.abspath( - os.path.normpath( - os.path.join( - os.path.dirname(__file__), - '..', - 'libuinput' + get_so_extension()))) + possible_paths = [] + for extension in get_so_extensions(): + possible_paths.append( + os.path.abspath( + os.path.normpath( + os.path.join( + os.path.dirname(__file__), + '..', + 'libuinput' + extension + ) + ) + ) + ) + lib = None + for path in possible_paths: + if os.path.exists(path): + lib = path + break + if not lib: + raise OSError('Cant find linuinput. searched at:\n {}'.format( + '\n'.join(possible_paths) + ) + ) self._lib = ctypes.CDLL(lib) c_k = (ctypes.c_uint16 * len(self._k))(*self._k) |