libwconr 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- libwconr-0.1.0.dist-info/METADATA +70 -0
- libwconr-0.1.0.dist-info/RECORD +8 -0
- libwconr-0.1.0.dist-info/WHEEL +4 -0
- wrappers/__init__.py +2 -0
- wrappers/dllloader.py +70 -0
- wrappers/libwconr/__init__.py +1 -0
- wrappers/libwconr/_libwconr.py +174 -0
- wrappers/libwconr/libwconr.py +205 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: libwconr
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python ctypes wrapper for the native libwconr package-manager library.
|
|
5
|
+
Project-URL: Homepage, https://github.com/OWNER/REPO
|
|
6
|
+
Project-URL: Source, https://github.com/OWNER/REPO/tree/main/lib/wrappers/python
|
|
7
|
+
Project-URL: Issues, https://github.com/OWNER/REPO/issues
|
|
8
|
+
Keywords: ctypes,libwconr,package-manager,wconr,wrapper
|
|
9
|
+
Classifier: Development Status :: 3 - Alpha
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
20
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
21
|
+
Requires-Python: >=3.9
|
|
22
|
+
Provides-Extra: test
|
|
23
|
+
Requires-Dist: pytest>=7; extra == 'test'
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
|
|
26
|
+
# libwconr (Python wrapper)
|
|
27
|
+
|
|
28
|
+
`ctypes` bindings for the native **libwconr** shared library.
|
|
29
|
+
|
|
30
|
+
> **This package contains only the Python wrapper.** The native library
|
|
31
|
+
> (`libwconr.so` / `libwconr.dylib` / `libwconr.dll`) must be installed
|
|
32
|
+
> separately and be discoverable (see below).
|
|
33
|
+
|
|
34
|
+
## Install
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
pip install libwconr
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
The distribution is named `libwconr`, but the import package is `wrappers`:
|
|
41
|
+
|
|
42
|
+
```python
|
|
43
|
+
from wrappers import libwconr
|
|
44
|
+
from wrappers import add_dll_registry_path
|
|
45
|
+
|
|
46
|
+
add_dll_registry_path("/opt/wconr/lib") # optional: where the native lib lives
|
|
47
|
+
libwconr.init()
|
|
48
|
+
|
|
49
|
+
state = libwconr.WCRState()
|
|
50
|
+
print(state.list_installed())
|
|
51
|
+
state.close()
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Native library lookup
|
|
55
|
+
|
|
56
|
+
`libwconr.init()` looks for `libwconr.{so,dylib,dll}` in, in order:
|
|
57
|
+
|
|
58
|
+
1. `./` and `./lib/` relative to the current working directory
|
|
59
|
+
2. every directory in `$PATH`
|
|
60
|
+
3. any directory added with `wrappers.add_dll_registry_path(path)`
|
|
61
|
+
|
|
62
|
+
If nothing is found it falls back to the bare file name, so the OS loader
|
|
63
|
+
rules (e.g. `LD_LIBRARY_PATH`, `DYLD_LIBRARY_PATH`) apply.
|
|
64
|
+
|
|
65
|
+
## Development
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
pip install -e ".[test]"
|
|
69
|
+
pytest
|
|
70
|
+
```
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
wrappers/__init__.py,sha256=sF8aIvoQtcFu6YUThn-6NhfQY_MD2inE0_8Oj2a4Z3E,79
|
|
2
|
+
wrappers/dllloader.py,sha256=osl7vevL-qq7tjZKvmljaFFHG36IwxJtXlIMPyeKGaA,2364
|
|
3
|
+
wrappers/libwconr/__init__.py,sha256=vlCdBa0XHjuJG_XcAhQqfSOKEvd_9fHGslYKhfHXfIk,24
|
|
4
|
+
wrappers/libwconr/_libwconr.py,sha256=fqInt5qPPQpQ6z026tc9txbJGwxjxQ9UruosD9ZHFqU,5871
|
|
5
|
+
wrappers/libwconr/libwconr.py,sha256=mI6X1cpX6qWXkfGFEJxexm7BX4V3clCcn_7UQNf9UK8,8634
|
|
6
|
+
libwconr-0.1.0.dist-info/METADATA,sha256=7ItbdQDuWq1x05amsPMJHkiY30Sr8O1H0WxvU7fWvgA,2239
|
|
7
|
+
libwconr-0.1.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
8
|
+
libwconr-0.1.0.dist-info/RECORD,,
|
wrappers/__init__.py
ADDED
wrappers/dllloader.py
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
from ctypes import CDLL
|
|
2
|
+
from genericpath import isfile
|
|
3
|
+
|
|
4
|
+
import os
|
|
5
|
+
|
|
6
|
+
_DLL_PATHS_POSIX = {
|
|
7
|
+
"./",
|
|
8
|
+
"./lib/",
|
|
9
|
+
*tuple(map(lambda x: x if x.endswith('/') else x + '/', filter(lambda x: x, os.environ.get("PATH", "").replace('\\', '/').split(':'))))
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
_DLL_PATHS_NT = {
|
|
13
|
+
".\\",
|
|
14
|
+
".\\lib\\",
|
|
15
|
+
*tuple(map(lambda x: x if x.endswith('\\') else x + '\\', filter(lambda x: x, os.environ.get("PATH", "").replace('/', '\\').split(':'))))
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
def find_dll(name: str, platform = "posix") -> str:
|
|
19
|
+
if (platform.lower == "nt"):
|
|
20
|
+
registry: set = _DLL_PATHS_NT
|
|
21
|
+
name: str = name.replace('/', '\\').strip('\\')
|
|
22
|
+
else:
|
|
23
|
+
registry: set = _DLL_PATHS_POSIX
|
|
24
|
+
name: str = name.replace('\\', '/').strip('/')
|
|
25
|
+
|
|
26
|
+
for item in registry:
|
|
27
|
+
if (isfile(item + name)):
|
|
28
|
+
return (item + name)
|
|
29
|
+
return (None)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def add_dll_registry_path(path: str) -> None:
|
|
33
|
+
if (not path.endswith('/') and not path.endswith('\\')):
|
|
34
|
+
path += "/"
|
|
35
|
+
_DLL_PATHS_NT.add(path.replace('/', '\\'))
|
|
36
|
+
_DLL_PATHS_POSIX.add(path.replace('\\', '/'))
|
|
37
|
+
|
|
38
|
+
class _SymbolRegister(object):
|
|
39
|
+
def __init__(self, name: str, symbol_ptr, response_type, *arguments) -> None:
|
|
40
|
+
self.name: str = name
|
|
41
|
+
self.symbol_ptr = symbol_ptr
|
|
42
|
+
self.response_type = response_type
|
|
43
|
+
self.arguments = [*arguments]
|
|
44
|
+
|
|
45
|
+
self.symbol_ptr.restype = response_type
|
|
46
|
+
self.symbol_ptr.argtypes = tuple(arguments)
|
|
47
|
+
|
|
48
|
+
class DLLoader(object):
|
|
49
|
+
def __init__(self, path: str) -> None:
|
|
50
|
+
self._path = path
|
|
51
|
+
self._registered_functions = {}
|
|
52
|
+
self._dll: CDLL = CDLL(path)
|
|
53
|
+
|
|
54
|
+
def register_function(self, name: str, response_type, *arguments) -> None:
|
|
55
|
+
if (not self._dll):
|
|
56
|
+
raise RuntimeError("dll not open.")
|
|
57
|
+
if (not hasattr(self._dll, name)):
|
|
58
|
+
raise ReferenceError(f"symbol {name} not found in dll {self._path}.")
|
|
59
|
+
self._registered_functions[name] = _SymbolRegister(name, getattr(self._dll, name), response_type, *arguments)
|
|
60
|
+
|
|
61
|
+
def call_function(self, name: str, *arguments):
|
|
62
|
+
if (not self._registered_functions[name]):
|
|
63
|
+
raise ReferenceError(f"symbol {name} not registered.")
|
|
64
|
+
return (self._registered_functions[name].symbol_ptr(*arguments))
|
|
65
|
+
|
|
66
|
+
def __del__(self) -> None:
|
|
67
|
+
if (hasattr(self, "_dll")):
|
|
68
|
+
del self._dll
|
|
69
|
+
|
|
70
|
+
self._dll = None
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .libwconr import *
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
from ctypes import Structure, POINTER, c_short, c_ushort, c_int, c_uint, c_long, c_ulong, c_double, c_float, c_size_t, c_ssize_t, c_void_p, c_char_p
|
|
2
|
+
from ctypes import c_byte as c_char
|
|
3
|
+
from ctypes import c_ubyte as c_uchar
|
|
4
|
+
from enum import Enum
|
|
5
|
+
from sys import platform
|
|
6
|
+
|
|
7
|
+
from ..dllloader import DLLoader, find_dll
|
|
8
|
+
|
|
9
|
+
# ==== Enums ==== #
|
|
10
|
+
|
|
11
|
+
class SUPPORTED_ARCHITECTURES(Enum):
|
|
12
|
+
UNSUPPORTED_ARCH = -(1 << 0)
|
|
13
|
+
X86_64_ARCH = (1 << 0)
|
|
14
|
+
ARM64_ARCH = (1 << 1)
|
|
15
|
+
I686_ARCH = (1 << 2)
|
|
16
|
+
|
|
17
|
+
class SUPPORTED_PLATFORMS(Enum):
|
|
18
|
+
UNSUPPORTED_PLTF = -(1 << 0)
|
|
19
|
+
NT_PLTF = (1 << 0)
|
|
20
|
+
DARWIN_PLTF = (1 << 1)
|
|
21
|
+
GEN_LINUX_PLTF = (1 << 2)
|
|
22
|
+
|
|
23
|
+
class protocol_type(Enum):
|
|
24
|
+
PROT_HTTP = 0
|
|
25
|
+
PROT_WCR = 1
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
# ==== Structs ==== #
|
|
29
|
+
|
|
30
|
+
class wcr_system_s(Structure):
|
|
31
|
+
pass
|
|
32
|
+
|
|
33
|
+
wcr_system_s._fields_ = [
|
|
34
|
+
("arch", c_short),
|
|
35
|
+
("platform", c_short)
|
|
36
|
+
]
|
|
37
|
+
|
|
38
|
+
class wcr_source_s(Structure):
|
|
39
|
+
pass
|
|
40
|
+
|
|
41
|
+
wcr_source_s._fields_ = [
|
|
42
|
+
("url", c_char_p),
|
|
43
|
+
("proto", c_int),
|
|
44
|
+
("access_key", c_char_p),
|
|
45
|
+
("server_pubkey_path", c_char_p)
|
|
46
|
+
]
|
|
47
|
+
|
|
48
|
+
class wcr_state_s(Structure):
|
|
49
|
+
pass
|
|
50
|
+
|
|
51
|
+
wcr_state_s._fields_ = [
|
|
52
|
+
("system_informations", wcr_system_s),
|
|
53
|
+
("cache_path", c_char_p),
|
|
54
|
+
("config_path", c_char_p),
|
|
55
|
+
("sources", POINTER(POINTER(wcr_source_s))),
|
|
56
|
+
("sources_count", c_size_t),
|
|
57
|
+
("lock", c_char * 64),
|
|
58
|
+
("event_callback", c_void_p),
|
|
59
|
+
("event_user_data", POINTER(None))
|
|
60
|
+
]
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
class wcr_installed_pkg_s(Structure):
|
|
64
|
+
pass
|
|
65
|
+
|
|
66
|
+
wcr_installed_pkg_s._fields_ = [
|
|
67
|
+
("name", c_char_p),
|
|
68
|
+
("version", c_char_p),
|
|
69
|
+
("is_dependency", c_int)
|
|
70
|
+
]
|
|
71
|
+
|
|
72
|
+
class wcr_available_pkg_s(Structure):
|
|
73
|
+
pass
|
|
74
|
+
|
|
75
|
+
wcr_available_pkg_s._fields_ = [
|
|
76
|
+
("name", c_char_p),
|
|
77
|
+
("version", c_char_p)
|
|
78
|
+
]
|
|
79
|
+
|
|
80
|
+
class wcr_pkg_variant_s(Structure):
|
|
81
|
+
pass
|
|
82
|
+
|
|
83
|
+
wcr_pkg_variant_s._fields_ = [
|
|
84
|
+
("version", c_char_p),
|
|
85
|
+
("arch", c_char_p),
|
|
86
|
+
("machine", c_char_p)
|
|
87
|
+
]
|
|
88
|
+
|
|
89
|
+
class wcr_pkg_metadata_s(Structure):
|
|
90
|
+
pass
|
|
91
|
+
|
|
92
|
+
wcr_pkg_metadata_s._fields_ = [
|
|
93
|
+
("name", c_char_p),
|
|
94
|
+
("version", c_char_p),
|
|
95
|
+
("arch", c_char_p),
|
|
96
|
+
("machine", c_char_p),
|
|
97
|
+
("description", c_char_p),
|
|
98
|
+
("address", c_char_p),
|
|
99
|
+
("sha256", c_char_p),
|
|
100
|
+
("md5", c_char_p),
|
|
101
|
+
("depends", POINTER(c_char_p)),
|
|
102
|
+
("depends_count", c_size_t),
|
|
103
|
+
("size", c_long),
|
|
104
|
+
("added_at", c_long)
|
|
105
|
+
]
|
|
106
|
+
|
|
107
|
+
class wcr_hash_check_s(Structure):
|
|
108
|
+
pass
|
|
109
|
+
|
|
110
|
+
wcr_hash_check_s._fields_ = [
|
|
111
|
+
("expected", c_char_p),
|
|
112
|
+
("actual", c_char_p),
|
|
113
|
+
("match", c_int)
|
|
114
|
+
]
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
# ==== Interfaces ==== #
|
|
118
|
+
|
|
119
|
+
class Mapper(object):
|
|
120
|
+
def __init__(self, path: str = f"libwconr.{'dll' if platform.startswith('win') else ('dylib' if platform.startswith('darwin') else 'so')}") -> None:
|
|
121
|
+
self.inited: bool = False
|
|
122
|
+
self.base_dll_path: str = path
|
|
123
|
+
self.dll_location: str = None
|
|
124
|
+
self._dll: DLLoader = None
|
|
125
|
+
|
|
126
|
+
def __del__(self):
|
|
127
|
+
self.inited = False
|
|
128
|
+
|
|
129
|
+
del self._dll
|
|
130
|
+
|
|
131
|
+
self._dll = None
|
|
132
|
+
|
|
133
|
+
def init_mapper(self):
|
|
134
|
+
self.dll_location: str = find_dll(self.base_dll_path, 'nt' if platform.startswith("win") else 'posix') or self.base_dll_path
|
|
135
|
+
|
|
136
|
+
if (not self.dll_location):
|
|
137
|
+
raise OSError(f"DLL {self.base_dll_path} not found in any $PATH or registered path via `add_dll_registry_path` nor cwd and cwd/lib.")
|
|
138
|
+
|
|
139
|
+
self._dll: DLLoader = DLLoader(self.dll_location)
|
|
140
|
+
self.inited: bool = True
|
|
141
|
+
|
|
142
|
+
self.map_functions()
|
|
143
|
+
|
|
144
|
+
def call_function(self, name: str, *args):
|
|
145
|
+
if (not self.inited):
|
|
146
|
+
self.init_mapper()
|
|
147
|
+
|
|
148
|
+
return self._dll.call_function(name, *args)
|
|
149
|
+
|
|
150
|
+
def map_functions(self) -> None:
|
|
151
|
+
if (not self._dll):
|
|
152
|
+
self.init_mapper()
|
|
153
|
+
self._dll.register_function("new_state", POINTER(wcr_state_s))
|
|
154
|
+
self._dll.register_function("close_state", None, POINTER(wcr_state_s))
|
|
155
|
+
self._dll.register_function("download_package", c_int, c_char_p, c_char_p)
|
|
156
|
+
self._dll.register_function("write_state", c_int, POINTER(wcr_state_s), c_char_p)
|
|
157
|
+
self._dll.register_function("load_state", POINTER(wcr_state_s), c_char_p)
|
|
158
|
+
self._dll.register_function("wcr_state_add_source", c_int, POINTER(wcr_state_s), c_int, c_char_p)
|
|
159
|
+
self._dll.register_function("sync_package_list", c_int, POINTER(wcr_state_s), c_int, c_char_p)
|
|
160
|
+
self._dll.register_function("install_package", c_int, POINTER(wcr_state_s), c_int, c_char_p, c_char_p)
|
|
161
|
+
self._dll.register_function("uninstall_package", c_int, POINTER(wcr_state_s), c_char_p)
|
|
162
|
+
self._dll.register_function("list_installed", c_int, POINTER(wcr_state_s), POINTER(POINTER(wcr_installed_pkg_s)), POINTER(c_size_t))
|
|
163
|
+
self._dll.register_function("free_installed_list", None, POINTER(wcr_installed_pkg_s), c_size_t)
|
|
164
|
+
self._dll.register_function("wcr_source_set_auth", c_int, POINTER(wcr_state_s), c_size_t, c_char_p, c_char_p)
|
|
165
|
+
self._dll.register_function("search_available", c_int, POINTER(wcr_state_s), c_char_p, POINTER(POINTER(wcr_available_pkg_s)), POINTER(c_size_t))
|
|
166
|
+
self._dll.register_function("free_available_list", None, POINTER(wcr_available_pkg_s), c_size_t)
|
|
167
|
+
self._dll.register_function("list_package_variants", c_int, POINTER(wcr_state_s), c_int, c_char_p, c_char_p, POINTER(POINTER(wcr_pkg_variant_s)), POINTER(c_size_t))
|
|
168
|
+
self._dll.register_function("free_variant_list", None, POINTER(wcr_pkg_variant_s), c_size_t)
|
|
169
|
+
self._dll.register_function("get_package_metadata", c_int, POINTER(wcr_state_s), c_int, c_char_p, c_char_p, POINTER(wcr_pkg_metadata_s))
|
|
170
|
+
self._dll.register_function("free_package_metadata", None, POINTER(wcr_pkg_metadata_s))
|
|
171
|
+
self._dll.register_function("verify_cached_package", c_int, POINTER(wcr_state_s), c_int, c_char_p, c_char_p, POINTER(wcr_hash_check_s))
|
|
172
|
+
self._dll.register_function("free_hash_check", None, POINTER(wcr_hash_check_s))
|
|
173
|
+
self._dll.register_function("wcr_set_event_callback", None, POINTER(wcr_state_s), c_void_p, POINTER(None))
|
|
174
|
+
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
from ._libwconr import *
|
|
2
|
+
|
|
3
|
+
from ctypes import c_char_p, pointer, cast, POINTER, c_ubyte, c_void_p, c_int, c_size_t, create_string_buffer, CFUNCTYPE, Structure
|
|
4
|
+
from enum import Enum
|
|
5
|
+
import os
|
|
6
|
+
|
|
7
|
+
class wcr_event_type(Enum):
|
|
8
|
+
WCR_EVENT_DEBUG = 0
|
|
9
|
+
WCR_EVENT_INFO = 1
|
|
10
|
+
WCR_EVENT_WARNING = 2
|
|
11
|
+
WCR_EVENT_ERROR = 3
|
|
12
|
+
WCR_EVENT_PROGRESS = 4
|
|
13
|
+
|
|
14
|
+
class wcr_event(Structure):
|
|
15
|
+
_fields_ = [
|
|
16
|
+
("type", c_int),
|
|
17
|
+
("message", c_char_p),
|
|
18
|
+
("bytes_done", c_size_t),
|
|
19
|
+
("bytes_total", c_size_t)
|
|
20
|
+
]
|
|
21
|
+
|
|
22
|
+
wcr_event_callback_t = CFUNCTYPE(None, POINTER(wcr_event), c_void_p)
|
|
23
|
+
|
|
24
|
+
_MAPPER = Mapper()
|
|
25
|
+
|
|
26
|
+
def init():
|
|
27
|
+
_MAPPER.init_mapper()
|
|
28
|
+
|
|
29
|
+
class WCRState(object):
|
|
30
|
+
__mapper: Mapper = _MAPPER
|
|
31
|
+
|
|
32
|
+
def __init__(self, _raw_ptr=None) -> None:
|
|
33
|
+
self._event_cb_ref = None
|
|
34
|
+
if _raw_ptr is not None:
|
|
35
|
+
self._cstate = _raw_ptr
|
|
36
|
+
else:
|
|
37
|
+
self._cstate = self.__mapper.call_function("new_state")
|
|
38
|
+
|
|
39
|
+
@classmethod
|
|
40
|
+
def load(cls, filepath: str):
|
|
41
|
+
path = os.path.expanduser(filepath)
|
|
42
|
+
ptr = cls.__mapper.call_function("load_state", path.encode('utf-8'))
|
|
43
|
+
if not ptr:
|
|
44
|
+
return None
|
|
45
|
+
return cls(_raw_ptr=ptr)
|
|
46
|
+
|
|
47
|
+
def save(self, filepath: str) -> int:
|
|
48
|
+
path = os.path.expanduser(filepath)
|
|
49
|
+
os.makedirs(os.path.dirname(path), exist_ok=True)
|
|
50
|
+
return int(self.__mapper.call_function("write_state", self._cstate, path.encode('utf-8')))
|
|
51
|
+
|
|
52
|
+
def add_source(self, proto: int, url: str) -> int:
|
|
53
|
+
return int(self.__mapper.call_function("wcr_state_add_source", self._cstate, proto, url.encode('utf-8')))
|
|
54
|
+
|
|
55
|
+
def get_sources(self) -> list:
|
|
56
|
+
state = self._cstate.contents
|
|
57
|
+
result = []
|
|
58
|
+
for i in range(state.sources_count):
|
|
59
|
+
src = state.sources[i].contents
|
|
60
|
+
entry = {"url": src.url.decode('utf-8'), "proto": src.proto}
|
|
61
|
+
if src.access_key:
|
|
62
|
+
entry["access_key"] = src.access_key.decode('utf-8')
|
|
63
|
+
if src.server_pubkey_path:
|
|
64
|
+
entry["server_pubkey_path"] = src.server_pubkey_path.decode('utf-8')
|
|
65
|
+
result.append(entry)
|
|
66
|
+
return result
|
|
67
|
+
|
|
68
|
+
def dowload_package(self, url, location) -> None:
|
|
69
|
+
if int(self.__mapper.call_function("download_package", cast(create_string_buffer(url.encode('utf-8')), POINTER(c_ubyte)), cast(create_string_buffer(location.encode('utf-8')), POINTER(c_ubyte))) < 0):
|
|
70
|
+
raise RuntimeError("failed to download")
|
|
71
|
+
|
|
72
|
+
def source_set_auth(self, index: int, access_key: str = None, server_pubkey_path: str = None) -> int:
|
|
73
|
+
ak = access_key.encode('utf-8') if access_key else None
|
|
74
|
+
pk = server_pubkey_path.encode('utf-8') if server_pubkey_path else None
|
|
75
|
+
return int(self.__mapper.call_function("wcr_source_set_auth", self._cstate, index, ak, pk))
|
|
76
|
+
|
|
77
|
+
def sync_package_list(self, proto: int, source_uri: str) -> int:
|
|
78
|
+
return int(self.__mapper.call_function("sync_package_list", self._cstate, proto, source_uri.encode('utf-8')))
|
|
79
|
+
|
|
80
|
+
def install_package(self, proto: int, source_uri: str, package_name: str) -> int:
|
|
81
|
+
return int(self.__mapper.call_function("install_package", self._cstate, proto, source_uri.encode('utf-8'), package_name.encode('utf-8')))
|
|
82
|
+
|
|
83
|
+
def uninstall_package(self, package_name: str) -> int:
|
|
84
|
+
return int(self.__mapper.call_function("uninstall_package", self._cstate, package_name.encode('utf-8')))
|
|
85
|
+
|
|
86
|
+
def get_package_metadata(self, proto: int, source_uri: str, package_spec: str) -> dict:
|
|
87
|
+
meta = wcr_pkg_metadata_s()
|
|
88
|
+
rc = int(self.__mapper.call_function("get_package_metadata", self._cstate, proto,
|
|
89
|
+
source_uri.encode('utf-8'), package_spec.encode('utf-8'),
|
|
90
|
+
pointer(meta)))
|
|
91
|
+
if (rc != 0):
|
|
92
|
+
return None
|
|
93
|
+
|
|
94
|
+
def _ds(v):
|
|
95
|
+
return v.decode('utf-8', errors='replace') if v else ""
|
|
96
|
+
|
|
97
|
+
deps = []
|
|
98
|
+
for i in range(meta.depends_count):
|
|
99
|
+
if (meta.depends[i]):
|
|
100
|
+
deps.append(meta.depends[i].decode('utf-8', errors='replace'))
|
|
101
|
+
|
|
102
|
+
result = {
|
|
103
|
+
"name": _ds(meta.name),
|
|
104
|
+
"version": _ds(meta.version),
|
|
105
|
+
"arch": _ds(meta.arch),
|
|
106
|
+
"machine": _ds(meta.machine),
|
|
107
|
+
"description": _ds(meta.description),
|
|
108
|
+
"address": _ds(meta.address),
|
|
109
|
+
"SHA256": _ds(meta.sha256),
|
|
110
|
+
"MD5sum": _ds(meta.md5),
|
|
111
|
+
"depends": deps,
|
|
112
|
+
"size": meta.size,
|
|
113
|
+
"added_at": meta.added_at
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
self.__mapper.call_function("free_package_metadata", pointer(meta))
|
|
117
|
+
return result
|
|
118
|
+
|
|
119
|
+
def list_package_variants(self, proto: int, source_uri: str, package_name: str) -> list:
|
|
120
|
+
out = POINTER(wcr_pkg_variant_s)()
|
|
121
|
+
count = c_size_t(0)
|
|
122
|
+
rc = int(self.__mapper.call_function("list_package_variants", self._cstate, proto,
|
|
123
|
+
source_uri.encode('utf-8'), package_name.encode('utf-8'),
|
|
124
|
+
pointer(out), pointer(count)))
|
|
125
|
+
if (rc != 0):
|
|
126
|
+
return []
|
|
127
|
+
result = []
|
|
128
|
+
for i in range(count.value):
|
|
129
|
+
ver = out[i].version.decode('utf-8', errors='replace') if out[i].version else ""
|
|
130
|
+
arch = out[i].arch.decode('utf-8', errors='replace') if out[i].arch else ""
|
|
131
|
+
mach = out[i].machine.decode('utf-8', errors='replace') if out[i].machine else ""
|
|
132
|
+
result.append({"version": ver, "arch": arch, "machine": mach})
|
|
133
|
+
if (count.value > 0):
|
|
134
|
+
self.__mapper.call_function("free_variant_list", out, count)
|
|
135
|
+
return result
|
|
136
|
+
|
|
137
|
+
def search_available(self, query: str = "") -> list:
|
|
138
|
+
out = POINTER(wcr_available_pkg_s)()
|
|
139
|
+
count = c_size_t(0)
|
|
140
|
+
q = query.encode('utf-8') if query else None
|
|
141
|
+
rc = int(self.__mapper.call_function("search_available", self._cstate, q, pointer(out), pointer(count)))
|
|
142
|
+
if (rc != 0):
|
|
143
|
+
return []
|
|
144
|
+
result = []
|
|
145
|
+
for i in range(count.value):
|
|
146
|
+
name = out[i].name.decode('utf-8', errors='replace') if out[i].name else ""
|
|
147
|
+
version = out[i].version.decode('utf-8', errors='replace') if out[i].version else ""
|
|
148
|
+
result.append({"name": name, "version": version})
|
|
149
|
+
if (count.value > 0):
|
|
150
|
+
self.__mapper.call_function("free_available_list", out, count)
|
|
151
|
+
return result
|
|
152
|
+
|
|
153
|
+
def verify_cached_package(self, proto: int, source_uri: str, package_spec: str) -> dict:
|
|
154
|
+
check = wcr_hash_check_s()
|
|
155
|
+
rc = int(self.__mapper.call_function("verify_cached_package", self._cstate, proto,
|
|
156
|
+
source_uri.encode('utf-8'), package_spec.encode('utf-8'),
|
|
157
|
+
pointer(check)))
|
|
158
|
+
if (rc != 0):
|
|
159
|
+
return None
|
|
160
|
+
|
|
161
|
+
def _ds(v):
|
|
162
|
+
return v.decode('utf-8', errors='replace') if v else ""
|
|
163
|
+
|
|
164
|
+
result = {
|
|
165
|
+
"expected": _ds(check.expected),
|
|
166
|
+
"actual": _ds(check.actual),
|
|
167
|
+
"match": check.match
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
self.__mapper.call_function("free_hash_check", pointer(check))
|
|
171
|
+
return result
|
|
172
|
+
|
|
173
|
+
def list_installed(self) -> list:
|
|
174
|
+
out = POINTER(wcr_installed_pkg_s)()
|
|
175
|
+
count = c_size_t(0)
|
|
176
|
+
rc = int(self.__mapper.call_function("list_installed", self._cstate, pointer(out), pointer(count)))
|
|
177
|
+
if (rc != 0):
|
|
178
|
+
return []
|
|
179
|
+
result = []
|
|
180
|
+
for i in range(count.value):
|
|
181
|
+
name = out[i].name.decode('utf-8', errors='replace') if out[i].name else ""
|
|
182
|
+
version = out[i].version.decode('utf-8', errors='replace') if out[i].version else ""
|
|
183
|
+
result.append({"name": name, "version": version, "is_dependency": bool(out[i].is_dependency)})
|
|
184
|
+
if (count.value > 0):
|
|
185
|
+
self.__mapper.call_function("free_installed_list", out, count)
|
|
186
|
+
return result
|
|
187
|
+
|
|
188
|
+
def set_event_callback(self, callback):
|
|
189
|
+
def _c_callback(event_ptr, user_data):
|
|
190
|
+
ev = event_ptr.contents
|
|
191
|
+
msg = ev.message.decode('utf-8', errors='replace') if ev.message else ""
|
|
192
|
+
callback(wcr_event_type(ev.type), msg, ev.bytes_done, ev.bytes_total)
|
|
193
|
+
|
|
194
|
+
self._event_cb_ref = wcr_event_callback_t(_c_callback)
|
|
195
|
+
self.__mapper.call_function("wcr_set_event_callback", self._cstate, self._event_cb_ref, None)
|
|
196
|
+
|
|
197
|
+
def close(self):
|
|
198
|
+
if (not self._cstate):
|
|
199
|
+
return
|
|
200
|
+
self.__mapper.call_function("close_state", self._cstate)
|
|
201
|
+
self._cstate = None
|
|
202
|
+
self._event_cb_ref = None
|
|
203
|
+
|
|
204
|
+
def __del__(self):
|
|
205
|
+
self.close()
|