File: archpkg.py

package info (click to toggle)
python-nvchecker 2.16-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 736 kB
  • sloc: python: 4,801; makefile: 25
file content (37 lines) | stat: -rw-r--r-- 1,089 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# MIT licensed
# Copyright (c) 2013-2020 lilydjwg <lilydjwg@gmail.com>, et al.

from nvchecker.api import session, RichResult, GetVersionError

URL = 'https://www.archlinux.org/packages/search/json/'

async def request(pkg):
  res = await session.get(URL, params={"name": pkg})
  return res.json()

async def get_version(name, conf, *, cache, **kwargs):
  pkg = conf.get('archpkg') or name
  strip_release = conf.get('strip_release', False)
  provided = conf.get('provided')

  data = await cache.get(pkg, request)

  if not data['results']:
    raise GetVersionError('Arch package not found')

  r = [r for r in data['results'] if r['repo'] != 'testing'][0]

  if provided:
    provides = dict(x.split('=', 1) for x in r['provides'] if '=' in x)
    version = provides.get(provided, None)
    if strip_release:
      version = version.split('-', 1)[0]
  elif strip_release:
    version = r['pkgver']
  else:
    version = r['pkgver'] + '-' + r['pkgrel']

  return RichResult(
    version = version,
    url = f'https://archlinux.org/packages/{r["repo"]}/{r["arch"]}/{r["pkgname"]}/',
  )