snap-python 0.1.0__py3-none-any.whl → 0.1.1__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.
- snap_python/client.py +45 -33
- snap_python/components/snaps.py +98 -43
- snap_python/components/store.py +114 -2
- snap_python/utils.py +14 -0
- snap_python-0.1.1.dist-info/METADATA +66 -0
- {snap_python-0.1.0.dist-info → snap_python-0.1.1.dist-info}/RECORD +8 -8
- snap_python-0.1.0.dist-info/METADATA +0 -52
- {snap_python-0.1.0.dist-info → snap_python-0.1.1.dist-info}/LICENSE +0 -0
- {snap_python-0.1.0.dist-info → snap_python-0.1.1.dist-info}/WHEEL +0 -0
snap_python/client.py
CHANGED
|
@@ -65,16 +65,19 @@ class SnapClient(AbstractSnapsClient):
|
|
|
65
65
|
|
|
66
66
|
@retry(httpx.HTTPError, tries=3, delay=1, backoff=1)
|
|
67
67
|
async def request(self, method: str, endpoint: str, **kwargs) -> httpx.Response:
|
|
68
|
-
"""
|
|
68
|
+
r"""
|
|
69
69
|
Sends an HTTP request to the specified endpoint using the given method and parameters.
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
70
|
+
|
|
71
|
+
:param method: The HTTP method to use for the request (e.g., 'GET', 'POST').
|
|
72
|
+
:type method: str
|
|
73
|
+
:param endpoint: The API endpoint to send the request to.
|
|
74
|
+
:type endpoint: str
|
|
75
|
+
:param `**kwargs`: Additional keyword arguments to pass to the request.
|
|
76
|
+
|
|
77
|
+
:returns: The response object from the HTTP request.
|
|
78
|
+
:rtype: httpx.Response
|
|
79
|
+
|
|
80
|
+
:raises httpx.HTTPStatusError: If the response contains an HTTP status code indicating an error.
|
|
78
81
|
"""
|
|
79
82
|
|
|
80
83
|
response = await self.snapd_client.request(
|
|
@@ -85,16 +88,19 @@ class SnapClient(AbstractSnapsClient):
|
|
|
85
88
|
|
|
86
89
|
@retry(httpx.HTTPError, tries=3, delay=1, backoff=1)
|
|
87
90
|
async def request_raw(self, method: str, endpoint: str, **kwargs) -> httpx.Response:
|
|
88
|
-
"""
|
|
91
|
+
r"""
|
|
89
92
|
Sends an HTTP request using the specified method and endpoint.
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
93
|
+
|
|
94
|
+
:param method: The HTTP method to use for the request (e.g., 'GET', 'POST').
|
|
95
|
+
:type method: str
|
|
96
|
+
:param endpoint: The endpoint URL to send the request to.
|
|
97
|
+
:type endpoint: str
|
|
98
|
+
:param `**kwargs`: Additional keyword arguments to pass to the request.
|
|
99
|
+
|
|
100
|
+
:returns: The response object resulting from the HTTP request.
|
|
101
|
+
:rtype: httpx.Response
|
|
102
|
+
|
|
103
|
+
:raises httpx.HTTPStatusError: If the response contains an HTTP status code indicating an error.
|
|
98
104
|
"""
|
|
99
105
|
|
|
100
106
|
response = await self.snapd_client.request(method, endpoint, **kwargs)
|
|
@@ -103,10 +109,11 @@ class SnapClient(AbstractSnapsClient):
|
|
|
103
109
|
return response
|
|
104
110
|
|
|
105
111
|
async def ping(self) -> httpx.Response:
|
|
106
|
-
"""
|
|
112
|
+
"""
|
|
113
|
+
Reserved for human-readable content describing the service.
|
|
107
114
|
|
|
108
|
-
|
|
109
|
-
|
|
115
|
+
:returns: The response from the ping request.
|
|
116
|
+
:rtype: httpx.Response
|
|
110
117
|
"""
|
|
111
118
|
response = await self.snapd_client.get(f"{self._base_url}/")
|
|
112
119
|
|
|
@@ -116,12 +123,14 @@ class SnapClient(AbstractSnapsClient):
|
|
|
116
123
|
async def get_changes_by_id(self, change_id: str) -> ChangesResponse:
|
|
117
124
|
"""
|
|
118
125
|
Asynchronously retrieves changes by their ID.
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
126
|
+
|
|
127
|
+
:param change_id: The ID of the change to retrieve.
|
|
128
|
+
:type change_id: str
|
|
129
|
+
|
|
130
|
+
:returns: The response object containing the changes.
|
|
131
|
+
:rtype: ChangesResponse
|
|
132
|
+
|
|
133
|
+
:raises httpx.HTTPStatusError: If the request results in an HTTP error.
|
|
125
134
|
"""
|
|
126
135
|
|
|
127
136
|
try:
|
|
@@ -140,16 +149,19 @@ class SnapClient(AbstractSnapsClient):
|
|
|
140
149
|
) -> AsyncGenerator[ChangesResponse, None]:
|
|
141
150
|
"""
|
|
142
151
|
Asynchronous generator to fetch changes by change ID.
|
|
152
|
+
|
|
143
153
|
This generator continuously requests changes from the server using the provided
|
|
144
154
|
change ID and yields the response as a ChangesResponse object. It includes error
|
|
145
155
|
handling for HTTP status errors and adds a small delay between requests to avoid
|
|
146
156
|
overwhelming the server.
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
157
|
+
|
|
158
|
+
:param change_id: The ID of the change to fetch.
|
|
159
|
+
:type change_id: str
|
|
160
|
+
|
|
161
|
+
:yields: The response object containing the changes.
|
|
162
|
+
:rtype: ChangesResponse
|
|
163
|
+
|
|
164
|
+
:raises httpx.HTTPStatusError: If the request fails with an HTTP status error.
|
|
153
165
|
"""
|
|
154
166
|
while True:
|
|
155
167
|
try:
|
snap_python/components/snaps.py
CHANGED
|
@@ -21,6 +21,15 @@ class SnapsEndpoints:
|
|
|
21
21
|
self.common_endpoint = "snaps"
|
|
22
22
|
|
|
23
23
|
async def list_installed_snaps(self) -> InstalledSnapListResponse:
|
|
24
|
+
"""
|
|
25
|
+
Asynchronously retrieves a list of installed snaps.
|
|
26
|
+
|
|
27
|
+
:returns: The response containing the list of installed snaps.
|
|
28
|
+
:rtype: InstalledSnapListResponse
|
|
29
|
+
|
|
30
|
+
:raises httpx.HTTPStatusError: If the response status code does not indicate success.
|
|
31
|
+
"""
|
|
32
|
+
|
|
24
33
|
response: httpx.Response = await self._client.request(
|
|
25
34
|
"GET", self.common_endpoint
|
|
26
35
|
)
|
|
@@ -35,6 +44,17 @@ class SnapsEndpoints:
|
|
|
35
44
|
return response
|
|
36
45
|
|
|
37
46
|
async def get_snap_info(self, snap: str) -> SingleInstalledSnapResponse:
|
|
47
|
+
"""
|
|
48
|
+
Retrieves information about a specific snap.
|
|
49
|
+
|
|
50
|
+
:param snap: The name of the snap to retrieve information for.
|
|
51
|
+
:type snap: str
|
|
52
|
+
|
|
53
|
+
:returns: The response containing information about the snap.
|
|
54
|
+
:rtype: SingleInstalledSnapResponse
|
|
55
|
+
|
|
56
|
+
:raises httpx.HTTPStatusError: If the response status code does not indicate success.
|
|
57
|
+
"""
|
|
38
58
|
try:
|
|
39
59
|
response: httpx.Response = await self._client.request(
|
|
40
60
|
"GET", f"{self.common_endpoint}/{snap}"
|
|
@@ -50,6 +70,16 @@ class SnapsEndpoints:
|
|
|
50
70
|
return SingleInstalledSnapResponse.model_validate_json(response.content)
|
|
51
71
|
|
|
52
72
|
async def is_snap_installed(self, snap: str) -> bool:
|
|
73
|
+
"""
|
|
74
|
+
Check if a snap package is installed.
|
|
75
|
+
|
|
76
|
+
:param snap: The name of the snap package to check.
|
|
77
|
+
:type snap: str
|
|
78
|
+
|
|
79
|
+
:returns: True if the snap package is installed, False otherwise.
|
|
80
|
+
:rtype: bool
|
|
81
|
+
"""
|
|
82
|
+
|
|
53
83
|
snap_info = await self.get_snap_info(snap)
|
|
54
84
|
if snap_info.status == "OK":
|
|
55
85
|
return True
|
|
@@ -67,27 +97,36 @@ class SnapsEndpoints:
|
|
|
67
97
|
filename: str = None,
|
|
68
98
|
wait: bool = False,
|
|
69
99
|
) -> AsyncResponse | ChangesResponse:
|
|
70
|
-
"""
|
|
71
|
-
|
|
72
|
-
To sideload a snap, provide the filename parameter with the path to the snap file
|
|
100
|
+
"""
|
|
101
|
+
Install or sideload a snap.
|
|
73
102
|
|
|
103
|
+
To sideload a snap, provide the filename parameter with the path to the snap file.
|
|
74
104
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
105
|
+
:param snap: Name of the snap to install.
|
|
106
|
+
:type snap: str
|
|
107
|
+
:param channel: Channel to install, defaults to "stable".
|
|
108
|
+
:type channel: str, optional
|
|
109
|
+
:param classic: Install with classic confinement, defaults to False.
|
|
110
|
+
:type classic: bool, optional
|
|
111
|
+
:param dangerous: Install the given snap files even if there are no pre-acknowledged signatures for them, meaning they are not verified and could be dangerous if true (optional, implied by devmode), defaults to False.
|
|
112
|
+
:type dangerous: bool, optional
|
|
113
|
+
:param devmode: Install with devmode, defaults to False.
|
|
114
|
+
:type devmode: bool, optional
|
|
115
|
+
:param jailmode: Install snap with jailmode, defaults to False.
|
|
116
|
+
:type jailmode: bool, optional
|
|
117
|
+
:param revision: Install a specific revision of the snap, defaults to None.
|
|
118
|
+
:type revision: int, optional
|
|
119
|
+
:param filename: Path to snap to sideload, defaults to None.
|
|
120
|
+
:type filename: str, optional
|
|
121
|
+
:param wait: Whether to wait for snap to install. If not waiting, will return async response with change id, defaults to False.
|
|
122
|
+
:type wait: bool, optional
|
|
85
123
|
|
|
86
|
-
|
|
87
|
-
|
|
124
|
+
:raises FileNotFoundError: If the specified snap file does not exist.
|
|
125
|
+
:raises ValueError: If attempting to sideload without the dangerous flag set to True.
|
|
126
|
+
:raises SnapdAPIError: If there is an error during the snap install.
|
|
88
127
|
|
|
89
|
-
|
|
90
|
-
|
|
128
|
+
:returns: If wait is True, will return ChangesResponse. Otherwise, will return AsyncResponse.
|
|
129
|
+
:rtype: AsyncResponse | ChangesResponse
|
|
91
130
|
"""
|
|
92
131
|
request_data = {
|
|
93
132
|
"action": "install",
|
|
@@ -149,15 +188,20 @@ class SnapsEndpoints:
|
|
|
149
188
|
) -> AsyncResponse | ChangesResponse:
|
|
150
189
|
"""
|
|
151
190
|
Asynchronously removes a snap package.
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
191
|
+
|
|
192
|
+
:param snap: The name of the snap package to remove.
|
|
193
|
+
:type snap: str
|
|
194
|
+
:param purge: If True, purges the snap package. Defaults to False.
|
|
195
|
+
:type purge: bool, optional
|
|
196
|
+
:param terminate: If True, terminates the snap package. Defaults to False.
|
|
197
|
+
:type terminate: bool, optional
|
|
198
|
+
:param wait: If True, waits for the removal process to complete. Defaults to False.
|
|
199
|
+
:type wait: bool, optional
|
|
200
|
+
|
|
201
|
+
:returns: The response from the snapd API, either an asynchronous response or a changes response if waiting for completion.
|
|
202
|
+
:rtype: AsyncResponse | ChangesResponse
|
|
203
|
+
|
|
204
|
+
:raises SnapdAPIError: If there is an error in the snap removal process.
|
|
161
205
|
"""
|
|
162
206
|
request_data = {
|
|
163
207
|
"action": "remove",
|
|
@@ -206,23 +250,34 @@ class SnapsEndpoints:
|
|
|
206
250
|
) -> AsyncResponse | ChangesResponse:
|
|
207
251
|
"""
|
|
208
252
|
Refreshes a snap package.
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
253
|
+
|
|
254
|
+
:param snap: The name of the snap package to refresh.
|
|
255
|
+
:type snap: str
|
|
256
|
+
:param channel: The channel to refresh the snap from. Defaults to "stable".
|
|
257
|
+
:type channel: str, optional
|
|
258
|
+
:param classic: Whether to use classic confinement. Defaults to False.
|
|
259
|
+
:type classic: bool, optional
|
|
260
|
+
:param dangerous: Whether to allow installation of unasserted snaps. Defaults to False.
|
|
261
|
+
:type dangerous: bool, optional
|
|
262
|
+
:param devmode: Whether to use development mode. Defaults to False.
|
|
263
|
+
:type devmode: bool, optional
|
|
264
|
+
:param ignore_validation: Whether to ignore validation. Defaults to False.
|
|
265
|
+
:type ignore_validation: bool, optional
|
|
266
|
+
:param jailmode: Whether to use jail mode. Defaults to False.
|
|
267
|
+
:type jailmode: bool, optional
|
|
268
|
+
:param revision: The specific revision to refresh to. Defaults to None.
|
|
269
|
+
:type revision: int, optional
|
|
270
|
+
:param filename: The path to the snap file for sideloading. Defaults to None.
|
|
271
|
+
:type filename: str, optional
|
|
272
|
+
:param wait: Whether to wait for the refresh operation to complete. Defaults to False.
|
|
273
|
+
:type wait: bool, optional
|
|
274
|
+
|
|
275
|
+
:returns: The response from the refresh operation.
|
|
276
|
+
:rtype: AsyncResponse | ChangesResponse
|
|
277
|
+
|
|
278
|
+
:raises FileNotFoundError: If the specified snap file does not exist.
|
|
279
|
+
:raises ValueError: If attempting to sideload without the dangerous flag set to True.
|
|
280
|
+
:raises SnapdAPIError: If there is an error during the snap refresh.
|
|
226
281
|
"""
|
|
227
282
|
request_data = {
|
|
228
283
|
"action": "refresh",
|
snap_python/components/store.py
CHANGED
|
@@ -37,6 +37,19 @@ class StoreEndpoints:
|
|
|
37
37
|
self.store_client.headers.update(headers)
|
|
38
38
|
|
|
39
39
|
async def get_snap_details(self, snap_name: str, fields: list[str] | None = None):
|
|
40
|
+
"""
|
|
41
|
+
Get details of a snap.
|
|
42
|
+
|
|
43
|
+
:param snap_name: The name of the snap.
|
|
44
|
+
:type snap_name: str
|
|
45
|
+
:param fields: The fields to include in the response.
|
|
46
|
+
:type fields: list[str], optional
|
|
47
|
+
|
|
48
|
+
:returns: The snap details.
|
|
49
|
+
:rtype: dict
|
|
50
|
+
|
|
51
|
+
:raises ValueError: If invalid fields are provided.
|
|
52
|
+
"""
|
|
40
53
|
query = {}
|
|
41
54
|
if fields is not None:
|
|
42
55
|
if not all(field in VALID_SEARCH_CATEGORY_FIELDS for field in fields):
|
|
@@ -52,6 +65,19 @@ class StoreEndpoints:
|
|
|
52
65
|
return response.json()
|
|
53
66
|
|
|
54
67
|
async def get_snap_info(self, snap_name: str, fields: list[str] | None = None):
|
|
68
|
+
"""
|
|
69
|
+
Get information about a snap.
|
|
70
|
+
|
|
71
|
+
:param snap_name: The name of the snap.
|
|
72
|
+
:type snap_name: str
|
|
73
|
+
:param fields: The fields to include in the response.
|
|
74
|
+
:type fields: list[str], optional
|
|
75
|
+
|
|
76
|
+
:returns: The snap information.
|
|
77
|
+
:rtype: InfoResponse
|
|
78
|
+
|
|
79
|
+
:raises ValueError: If invalid fields are provided.
|
|
80
|
+
"""
|
|
55
81
|
query = {}
|
|
56
82
|
if fields is not None:
|
|
57
83
|
if not all(field in VALID_SNAP_INFO_FIELDS for field in fields):
|
|
@@ -69,6 +95,19 @@ class StoreEndpoints:
|
|
|
69
95
|
async def get_categories(
|
|
70
96
|
self, type: str | None = None, fields: list[str] | None = None
|
|
71
97
|
) -> CategoryResponse:
|
|
98
|
+
"""
|
|
99
|
+
Get categories of snaps.
|
|
100
|
+
|
|
101
|
+
:param type: The type of categories.
|
|
102
|
+
:type type: str, optional
|
|
103
|
+
:param fields: The fields to include in the response.
|
|
104
|
+
:type fields: list[str], optional
|
|
105
|
+
|
|
106
|
+
:returns: The categories.
|
|
107
|
+
:rtype: CategoryResponse
|
|
108
|
+
|
|
109
|
+
:raises ValueError: If invalid fields are provided.
|
|
110
|
+
"""
|
|
72
111
|
query = {}
|
|
73
112
|
if fields is not None:
|
|
74
113
|
if not all(field in VALID_CATEGORY_FIELDS for field in fields):
|
|
@@ -86,6 +125,19 @@ class StoreEndpoints:
|
|
|
86
125
|
async def get_category_by_name(
|
|
87
126
|
self, name: str, fields: list[str] | None = None
|
|
88
127
|
) -> SingleCategoryResponse:
|
|
128
|
+
"""
|
|
129
|
+
Get a category by name.
|
|
130
|
+
|
|
131
|
+
:param name: The name of the category.
|
|
132
|
+
:type name: str
|
|
133
|
+
:param fields: The fields to include in the response.
|
|
134
|
+
:type fields: list[str], optional
|
|
135
|
+
|
|
136
|
+
:returns: The category.
|
|
137
|
+
:rtype: SingleCategoryResponse
|
|
138
|
+
|
|
139
|
+
:raises ValueError: If invalid fields are provided.
|
|
140
|
+
"""
|
|
89
141
|
query = {}
|
|
90
142
|
if fields is not None:
|
|
91
143
|
if not all(field in VALID_CATEGORY_FIELDS for field in fields):
|
|
@@ -114,10 +166,39 @@ class StoreEndpoints:
|
|
|
114
166
|
publisher: str | None = None,
|
|
115
167
|
headers: dict[str, str] | None = None,
|
|
116
168
|
) -> SearchResponse:
|
|
117
|
-
"""from https://api.snapcraft.io/docs/search.html#snaps_find
|
|
118
|
-
and https://snapcraft.io/docs/snapd-api#heading--find
|
|
119
169
|
"""
|
|
170
|
+
Search for snaps in the store.
|
|
171
|
+
|
|
172
|
+
:param query: The search query.
|
|
173
|
+
:type query: str, optional
|
|
174
|
+
:param fields: The fields to include in the response.
|
|
175
|
+
:type fields: str, optional
|
|
176
|
+
:param name_startswith: Filter snaps by name prefix.
|
|
177
|
+
:type name_startswith: str, optional
|
|
178
|
+
:param architecture: Filter snaps by architecture.
|
|
179
|
+
:type architecture: str, optional
|
|
180
|
+
:param common_id: Filter snaps by common ID.
|
|
181
|
+
:type common_id: str, optional
|
|
182
|
+
:param category: Filter snaps by category.
|
|
183
|
+
:type category: str, optional
|
|
184
|
+
:param channel: Filter snaps by channel.
|
|
185
|
+
:type channel: str, optional
|
|
186
|
+
:param confiement: Filter snaps by confinement.
|
|
187
|
+
:type confiement: str, optional
|
|
188
|
+
:param featured: Filter snaps by featured status.
|
|
189
|
+
:type featured: bool, optional
|
|
190
|
+
:param private: Filter snaps by private status.
|
|
191
|
+
:type private: bool, optional
|
|
192
|
+
:param publisher: Filter snaps by publisher.
|
|
193
|
+
:type publisher: str, optional
|
|
194
|
+
:param headers: Additional headers to include in the request.
|
|
195
|
+
:type headers: dict[str, str], optional
|
|
120
196
|
|
|
197
|
+
:returns: The search response.
|
|
198
|
+
:rtype: SearchResponse
|
|
199
|
+
|
|
200
|
+
:raises ValueError: If invalid fields are provided.
|
|
201
|
+
"""
|
|
121
202
|
route = "/snaps/find"
|
|
122
203
|
query_dict: dict = {
|
|
123
204
|
"q": query,
|
|
@@ -160,14 +241,45 @@ class StoreEndpoints:
|
|
|
160
241
|
|
|
161
242
|
@retry.retry(Exception, tries=3, delay=2, backoff=2)
|
|
162
243
|
async def retry_get_snap_info(self, snap_name: str, fields: list[str]):
|
|
244
|
+
"""
|
|
245
|
+
Retry getting snap information.
|
|
246
|
+
|
|
247
|
+
:param snap_name: The name of the snap.
|
|
248
|
+
:type snap_name: str
|
|
249
|
+
:param fields: The fields to include in the response.
|
|
250
|
+
:type fields: list[str]
|
|
251
|
+
|
|
252
|
+
:returns: The snap information.
|
|
253
|
+
:rtype: InfoResponse
|
|
254
|
+
"""
|
|
163
255
|
return await self.get_snap_info(snap_name=snap_name, fields=fields)
|
|
164
256
|
|
|
165
257
|
async def get_top_snaps_from_category(self, category: str) -> SearchResponse:
|
|
258
|
+
"""
|
|
259
|
+
Get top snaps from a category.
|
|
260
|
+
|
|
261
|
+
:param category: The category name.
|
|
262
|
+
:type category: str
|
|
263
|
+
|
|
264
|
+
:returns: The search response.
|
|
265
|
+
:rtype: SearchResponse
|
|
266
|
+
"""
|
|
166
267
|
return await self.find(
|
|
167
268
|
category=category, fields=["title", "store-url", "summary"]
|
|
168
269
|
)
|
|
169
270
|
|
|
170
271
|
async def get_all_snaps_for_arch(self, arch: str) -> ArchSearchResponse:
|
|
272
|
+
"""
|
|
273
|
+
Get all snaps for a given architecture.
|
|
274
|
+
|
|
275
|
+
:param arch: The architecture.
|
|
276
|
+
:type arch: str
|
|
277
|
+
|
|
278
|
+
:returns: The search response.
|
|
279
|
+
:rtype: ArchSearchResponse
|
|
280
|
+
|
|
281
|
+
:raises ValueError: If invalid architecture is provided.
|
|
282
|
+
"""
|
|
171
283
|
# use the old "/api/v1/snaps/names" to get all snaps for a given architecture
|
|
172
284
|
|
|
173
285
|
# ensure valid arch
|
snap_python/utils.py
CHANGED
|
@@ -6,6 +6,10 @@ from snap_python.schemas.changes import ChangesResponse
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
class SnapdAPIError(Exception):
|
|
9
|
+
"""
|
|
10
|
+
General Exception raised for errors in the Snapd API.
|
|
11
|
+
"""
|
|
12
|
+
|
|
9
13
|
pass
|
|
10
14
|
|
|
11
15
|
|
|
@@ -24,6 +28,16 @@ class AbstractSnapsClient(ABC): # pragma: no cover
|
|
|
24
28
|
|
|
25
29
|
|
|
26
30
|
def going_to_reload_daemon(changes: ChangesResponse | None) -> bool:
|
|
31
|
+
"""
|
|
32
|
+
Determines if a daemon reload is required based on the provided changes.
|
|
33
|
+
|
|
34
|
+
:param changes: An instance of ChangesResponse or None.
|
|
35
|
+
:type changes: ChangesResponse | None
|
|
36
|
+
|
|
37
|
+
:returns: True if a daemon reload or restart is required, False otherwise.
|
|
38
|
+
:rtype: bool
|
|
39
|
+
"""
|
|
40
|
+
|
|
27
41
|
if changes is None or not isinstance(changes, ChangesResponse):
|
|
28
42
|
return False
|
|
29
43
|
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: snap-python
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: Interact with snapd and snapstore(s) from Python
|
|
5
|
+
License: MIT
|
|
6
|
+
Author: Alexander Lukens
|
|
7
|
+
Author-email: alexdlukens@gmail.com
|
|
8
|
+
Requires-Python: >=3.10,<4.0
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
15
|
+
Requires-Dist: httpx (>=0.27.2,<0.28.0)
|
|
16
|
+
Requires-Dist: pydantic (>=2.9.2,<3.0.0)
|
|
17
|
+
Requires-Dist: retry (>=0.9.2,<0.10.0)
|
|
18
|
+
Project-URL: Documentation, https://alexdlukens.github.io/snap-python/
|
|
19
|
+
Project-URL: Repository, https://github.com/alexdlukens/snap-python
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
|
|
22
|
+
# snap-python
|
|
23
|
+
|
|
24
|
+
snap-python provides an API client to interact with snapd
|
|
25
|
+
|
|
26
|
+
[Click here to read the documentation](https://alexdlukens.github.io/snap-python/)
|
|
27
|
+
|
|
28
|
+
## Installation
|
|
29
|
+
|
|
30
|
+
To install snap-python, you can use pip:
|
|
31
|
+
|
|
32
|
+
```
|
|
33
|
+
pip install snap-python
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Usage
|
|
37
|
+
|
|
38
|
+
Here is a simple example of how to use snap-python:
|
|
39
|
+
|
|
40
|
+
```python
|
|
41
|
+
# uses asyncio, must be run in an event loop
|
|
42
|
+
>>> import asyncio
|
|
43
|
+
>>> from snap_python.client import SnapClient
|
|
44
|
+
>>> sc = SnapClient()
|
|
45
|
+
>>> installed_snaps = asyncio.run(sc.snaps.list_installed_snaps())
|
|
46
|
+
>>> [snap.name for snap in installed_snaps.result]
|
|
47
|
+
[..., 'vlc', 'snapcraft', 'firefox', 'store-tui', 'gtk-common-themes', 'thunderbird', ...]
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Get details for installed snap `vlc`
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
|
|
54
|
+
# uses asyncio, must be run in an event loop
|
|
55
|
+
>>> import asyncio
|
|
56
|
+
>>> from snap_python.client import SnapClient
|
|
57
|
+
>>> sc = SnapClient()
|
|
58
|
+
>>> vlc_snap = asyncio.run(sc.snaps.get_snap_info("vlc"))
|
|
59
|
+
>>> vlc_snap.result.version
|
|
60
|
+
'3.0.20-1-g2617de71b6'
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## License
|
|
64
|
+
|
|
65
|
+
This project is licensed under the MIT License. See the LICENSE file for more details.
|
|
66
|
+
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
snap_python/__init__.py,sha256=gV43Nempk7HFKD1UCvxUhmP9x6dBmPjotcITREr81Vg,222
|
|
2
|
-
snap_python/client.py,sha256=
|
|
2
|
+
snap_python/client.py,sha256=rZAfzcQNhdtTyjQml1N-9-nAianFyEwOaI4H_0FMaFE,6612
|
|
3
3
|
snap_python/components/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
4
|
snap_python/components/config.py,sha256=IO_gCrumphEZioINFmXxb8I5OVsKC9cgSa28sQbZ700,1775
|
|
5
|
-
snap_python/components/snaps.py,sha256=
|
|
6
|
-
snap_python/components/store.py,sha256=
|
|
5
|
+
snap_python/components/snaps.py,sha256=FQ362L83jmhu3MLKszOU1w5jGP8l5-WNBlUTLnR6IW8,13176
|
|
6
|
+
snap_python/components/store.py,sha256=8E613XeKWt9kc7bAtKPhYq1PULmxZU0RnrULKW2HGQQ,10778
|
|
7
7
|
snap_python/schemas/changes.py,sha256=7SYUFXAQq9arl7hAA3YQ0YubMurPJtknTOVxP8ryqew,1919
|
|
8
8
|
snap_python/schemas/common.py,sha256=GLtC9aBo3O8vLKX9PNvzE-_DKN02OGpwsS7Ik2WK9-8,2608
|
|
9
9
|
snap_python/schemas/config.py,sha256=xXTGhk6TpwI8RlR6_qnfWlBHrBnTwr3hRCO5qCnN-6U,107
|
|
@@ -16,8 +16,8 @@ snap_python/schemas/store/json/category_schema.json,sha256=c4h_eyyBbChOiNby3hYfj
|
|
|
16
16
|
snap_python/schemas/store/json/snaps_find_schema.json,sha256=TfKpnievs5QOc7ah97ATMCQTOEfKspONTZnwSwq_0fI,8866
|
|
17
17
|
snap_python/schemas/store/json/snaps_info_schema.json,sha256=udoOovb6Ea7EnE_R9RuZ1CpY1wOJ3-K8xP4-8zKHgrQ,15888
|
|
18
18
|
snap_python/schemas/store/search.py,sha256=u92aFLLuvDwpfMNHlZo7O2-k-kj7cgzAOtvxxsvi6mU,3718
|
|
19
|
-
snap_python/utils.py,sha256=
|
|
20
|
-
snap_python-0.1.
|
|
21
|
-
snap_python-0.1.
|
|
22
|
-
snap_python-0.1.
|
|
23
|
-
snap_python-0.1.
|
|
19
|
+
snap_python/utils.py,sha256=cmUooPg5DzNL197Xxvu7LGD4Gwk3xxsT68wbVytRtV0,1240
|
|
20
|
+
snap_python-0.1.1.dist-info/LICENSE,sha256=lYXNZszxC_l2rlBvrHYs-esDegxWh8MKtjrdxA24uOk,1072
|
|
21
|
+
snap_python-0.1.1.dist-info/METADATA,sha256=CKofDQQsSyKxoIVDf4ELXETRIva_1w6Hxoe--UJh0S8,1883
|
|
22
|
+
snap_python-0.1.1.dist-info/WHEEL,sha256=IYZQI976HJqqOpQU6PHkJ8fb3tMNBFjg-Cn-pwAbaFM,88
|
|
23
|
+
snap_python-0.1.1.dist-info/RECORD,,
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.3
|
|
2
|
-
Name: snap-python
|
|
3
|
-
Version: 0.1.0
|
|
4
|
-
Summary: An api to interact with snapd and snap stores
|
|
5
|
-
License: MIT
|
|
6
|
-
Author: Alexander Lukens
|
|
7
|
-
Author-email: alexdlukens@gmail.com
|
|
8
|
-
Requires-Python: >=3.10,<4.0
|
|
9
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
-
Classifier: Programming Language :: Python :: 3
|
|
11
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
12
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
13
|
-
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
-
Classifier: Programming Language :: Python :: 3.13
|
|
15
|
-
Requires-Dist: httpx (>=0.27.2,<0.28.0)
|
|
16
|
-
Requires-Dist: pydantic (>=2.9.2,<3.0.0)
|
|
17
|
-
Requires-Dist: retry (>=0.9.2,<0.10.0)
|
|
18
|
-
Project-URL: Repository, https://github.com/alexlukens/snap-python
|
|
19
|
-
Description-Content-Type: text/markdown
|
|
20
|
-
|
|
21
|
-
# snap_python
|
|
22
|
-
|
|
23
|
-
snap_python provides an API client to interact with snapd
|
|
24
|
-
|
|
25
|
-
## Installation
|
|
26
|
-
|
|
27
|
-
To install snap_python, you can use pip:
|
|
28
|
-
|
|
29
|
-
```
|
|
30
|
-
pip install snap_python
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
## Usage
|
|
34
|
-
|
|
35
|
-
Here is a simple example of how to use snap_python:
|
|
36
|
-
|
|
37
|
-
```python
|
|
38
|
-
# TODO
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
## Create a Release
|
|
42
|
-
|
|
43
|
-
```bash
|
|
44
|
-
git tag -a v0.x.x -m "Release v0.x.x"
|
|
45
|
-
gh release create v0.x.x --title "Release v0.x.x"
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
The automation will build a wheel and push it to pypi
|
|
49
|
-
|
|
50
|
-
## License
|
|
51
|
-
|
|
52
|
-
This project is licensed under the MIT License. See the LICENSE file for more details.
|
|
File without changes
|
|
File without changes
|