.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
alpinelinux.py
Go to the documentation of this file.
1# SPDX-License-Identifier: AGPL-3.0-or-later
2"""`Alpine Linux binary packages`_. `Alpine Linux`_ is a Linux-based operation
3system designed to be small, simple and secure. Contrary to many other Linux
4distributions, it uses musl, BusyBox and OpenRC. Alpine is mostly used on
5servers and for Docker images.
6
7.. _Alpine Linux binary packages: https://pkgs.alpinelinux.org
8.. _Alpine Linux: https://www.alpinelinux.org
9
10"""
11
12import re
13
14from urllib.parse import urlencode
15from lxml import html
16from dateutil import parser
17
18from searx.utils import eval_xpath, eval_xpath_list, extract_text
19
20about = {
21 'website': 'https://www.alpinelinux.org',
22 'wikidata_id': 'Q4033826',
23 'use_official_api': False,
24 'official_api_documentation': None,
25 'require_api_key': False,
26 'results': 'HTML',
27}
28paging = True
29categories = ['packages', 'it']
30
31base_url = "https://pkgs.alpinelinux.org"
32alpine_arch = 'x86_64'
33"""Kernel architecture: ``x86_64``, ``x86``, ``aarch64``, ``armhf``,
34``ppc64le``, ``s390x``, ``armv7`` or ``riscv64``"""
35
36ARCH_RE = re.compile("x86_64|x86|aarch64|armhf|ppc64le|s390x|armv7|riscv64")
37"""Regular expression to match supported architectures in the query string."""
38
39
40def request(query, params):
41 query_arch = ARCH_RE.search(query)
42 if query_arch:
43 query_arch = query_arch.group(0)
44 query = query.replace(query_arch, '').strip()
45
46 args = {
47 # use wildcards to match more than just packages with the exact same
48 # name as the query
49 'name': f"*{query}*",
50 'page': params['pageno'],
51 'arch': query_arch or alpine_arch,
52 }
53 params['url'] = f"{base_url}/packages?{urlencode(args)}"
54 return params
55
56
57def response(resp):
58 results = []
59
60 doc = html.fromstring(resp.text)
61 for result in eval_xpath_list(doc, "//table/tbody/tr"):
62
63 if len(result.xpath("./td")) < 9:
64 # skip non valid entries in the result table
65 # e.g the "No item found..." message
66 continue
67
68 results.append(
69 {
70 'template': 'packages.html',
71 'url': base_url + extract_text(eval_xpath(result, './td[contains(@class, "package")]/a/@href')),
72 'title': extract_text(eval_xpath(result, './td[contains(@class, "package")]')),
73 'package_name': extract_text(eval_xpath(result, './td[contains(@class, "package")]')),
74 'publishedDate': parser.parse(extract_text(eval_xpath(result, './td[contains(@class, "bdate")]'))),
75 'version': extract_text(eval_xpath(result, './td[contains(@class, "version")]')),
76 'homepage': extract_text(eval_xpath(result, './td[contains(@class, "url")]/a/@href')),
77 'maintainer': extract_text(eval_xpath(result, './td[contains(@class, "maintainer")]')),
78 'license_name': extract_text(eval_xpath(result, './td[contains(@class, "license")]')),
79 'tags': [extract_text(eval_xpath(result, './td[contains(@class, "repo")]'))],
80 }
81 )
82
83 return results