.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
voidlinux.py
Go to the documentation of this file.
1# SPDX-License-Identifier: AGPL-3.0-or-later
2"""SearXNG engine for `Void Linux binary packages`_. Void is a general purpose
3operating system, based on the monolithic Linux kernel. Its package system
4allows you to quickly install, update and remove software; software is provided
5in binary packages or can be built directly from sources with the help of the
6XBPS source packages collection.
7
8.. _Void Linux binary packages: https://voidlinux.org/packages/
9
10"""
11
12import re
13
14from urllib.parse import quote_plus
15from searx.utils import humanize_bytes
16
17about = {
18 'website': 'https://voidlinux.org/packages/',
19 'wikidata_id': 'Q19310966',
20 'use_official_api': True,
21 'official_api_documentation': None,
22 'require_api_key': False,
23 'results': 'JSON',
24}
25
26categories = ['packages', 'it']
27
28base_url = "https://xq-api.voidlinux.org"
29pkg_repo_url = "https://github.com/void-linux/void-packages"
30
31void_arch = 'x86_64'
32"""Default architecture to search for. For valid values see :py:obj:`ARCH_RE`"""
33
34ARCH_RE = re.compile('aarch64-musl|armv6l-musl|armv7l-musl|x86_64-musl|aarch64|armv6l|armv7l|i686|x86_64')
35"""Regular expresion that match a architecture in the query string."""
36
37
38def request(query, params):
39 arch_path = ARCH_RE.search(query)
40 if arch_path:
41 arch_path = arch_path.group(0)
42 query = query.replace(arch_path, '').strip()
43 else:
44 arch_path = void_arch
45
46 params['url'] = f"{base_url}/v1/query/{arch_path}?q={quote_plus(query)}"
47 return params
48
49
50def response(resp):
51 """
52 At Void Linux, several packages sometimes share the same source code
53 (template) and therefore also have the same URL. Results with identical
54 URLs are merged as one result for SearXNG.
55 """
56
57 packages = {}
58 for result in resp.json()['data']:
59
60 # 32bit and dbg packages don't have their own package templates
61 github_slug = re.sub(r"-(32bit|dbg)$", "", result['name'])
62 pkg_url = f"{pkg_repo_url}/tree/master/srcpkgs/{github_slug}"
63
64 pkg_list = packages.get(pkg_url, [])
65 pkg_list.append(
66 {
67 'title': result['name'],
68 'content': f"{result['short_desc']} - {humanize_bytes(result['filename_size'])}",
69 'package_name': result['name'],
70 'version': f"v{result['version']}_{result['revision']}",
71 'tags': result['repository'],
72 }
73 )
74 packages[pkg_url] = pkg_list
75
76 results = []
77 for pkg_url, pkg_list in packages.items():
78
79 results.append(
80 {
81 'url': pkg_url,
82 'template': 'packages.html',
83 'title': ' | '.join(x['title'] for x in pkg_list),
84 'content': pkg_list[0]['content'],
85 'package_name': ' | '.join(x['package_name'] for x in pkg_list),
86 'version': pkg_list[0]['version'],
87 'tags': [x['tags'] for x in pkg_list],
88 }
89 )
90 return results
request(query, params)
Definition voidlinux.py:38