Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/archinstall
diff options
context:
space:
mode:
authorDaniel <blackrabbit256@gmail.com>2022-03-03 23:54:43 +1100
committerGitHub <noreply@github.com>2022-03-03 13:54:43 +0100
commitd9d59bee680bddbfacc61ec389b5015f79ff162c (patch)
tree41c45375240ebcc7aab5ae4c5f65e9047ccd144c /archinstall
parent47a9fba94b819c4184b0378b1241857df1e0ba39 (diff)
Fix #1018 (#1021)
* Fix #1018 * Fix flake8 Co-authored-by: Daniel Girtler <girtler.daniel@gmail.com>
Diffstat (limited to 'archinstall')
-rw-r--r--archinstall/lib/packages/packages.py29
1 files changed, 18 insertions, 11 deletions
diff --git a/archinstall/lib/packages/packages.py b/archinstall/lib/packages/packages.py
index b2c8ab8e..d5834f43 100644
--- a/archinstall/lib/packages/packages.py
+++ b/archinstall/lib/packages/packages.py
@@ -1,25 +1,35 @@
import json
import ssl
-import urllib.request
from typing import Dict, Any, Tuple, List
+from urllib.error import HTTPError
+from urllib.parse import urlencode
+from urllib.request import urlopen
from ..exceptions import PackageError, SysCallError
from ..models.dataclasses import PackageSearch, PackageSearchResult, LocalPackage
from ..pacman import run_pacman
-BASE_URL_PKG_SEARCH = 'https://archlinux.org/packages/search/json/?name={package}'
+BASE_URL_PKG_SEARCH = 'https://archlinux.org/packages/search/json/'
# BASE_URL_PKG_CONTENT = 'https://archlinux.org/packages/search/json/'
-BASE_GROUP_URL = 'https://archlinux.org/groups/search/json/?name={group}'
+BASE_GROUP_URL = 'https://archlinux.org/groups/search/json/'
-def group_search(name :str) -> List[PackageSearchResult]:
- # TODO UPSTREAM: Implement /json/ for the groups search
+def _make_request(url: str, params: Dict) -> Any:
ssl_context = ssl.create_default_context()
ssl_context.check_hostname = False
ssl_context.verify_mode = ssl.CERT_NONE
+
+ encoded = urlencode(params)
+ full_url = f'{url}?{encoded}'
+
+ return urlopen(full_url, context=ssl_context)
+
+
+def group_search(name :str) -> List[PackageSearchResult]:
+ # TODO UPSTREAM: Implement /json/ for the groups search
try:
- response = urllib.request.urlopen(BASE_GROUP_URL.format(group=name), context=ssl_context)
- except urllib.error.HTTPError as err:
+ response = _make_request(BASE_GROUP_URL, {'name': name})
+ except HTTPError as err:
if err.code == 404:
return []
else:
@@ -38,10 +48,7 @@ def package_search(package :str) -> PackageSearch:
"""
# TODO UPSTREAM: Implement bulk search, either support name=X&name=Y or split on space (%20 or ' ')
# TODO: utilize pacman cache first, upstream second.
- ssl_context = ssl.create_default_context()
- ssl_context.check_hostname = False
- ssl_context.verify_mode = ssl.CERT_NONE
- response = urllib.request.urlopen(BASE_URL_PKG_SEARCH.format(package=package), context=ssl_context)
+ response = _make_request(BASE_URL_PKG_SEARCH, {'name': package})
if response.code != 200:
raise PackageError(f"Could not locate package: [{response.code}] {response}")