From 53b31fa9f103d8262b7c1d28c5714238902e5081 Mon Sep 17 00:00:00 2001 From: jwijenbergh Date: Thu, 10 Feb 2022 13:36:09 +0100 Subject: Move python library load to init and fix build Signed-off-by: jwijenbergh --- wrappers/python/eduvpncommon/__init__.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'wrappers/python/eduvpncommon/__init__.py') diff --git a/wrappers/python/eduvpncommon/__init__.py b/wrappers/python/eduvpncommon/__init__.py index e69de29..e9d0284 100644 --- a/wrappers/python/eduvpncommon/__init__.py +++ b/wrappers/python/eduvpncommon/__init__.py @@ -0,0 +1,30 @@ +from ctypes import * +from collections import defaultdict +import pathlib +import platform + +_lib_prefixes = defaultdict(lambda: "lib", { + "windows": "", +}) + +_lib_suffixes = defaultdict(lambda: ".so", { + "windows": ".dll", + "darwin": ".dylib", +}) + +_os = platform.system().lower() + +_libname = "eduvpn_common" +_libfile = f"{_lib_prefixes[_os]}{_libname}{_lib_suffixes[_os]}" +# Library should have been copied to the lib/ folder +lib = cdll.LoadLibrary(str(pathlib.Path(__file__).parent / "lib" / _libfile)) + + +class GoSlice(Structure): + _fields_ = [("data", POINTER(c_char)), ("len", c_int64), ("cap", c_int64)] + + @staticmethod + def make(bs: bytes) -> "GoSlice": + return GoSlice((c_char * len(bs))(*bs), len(bs), len(bs)) + + -- cgit v1.2.3