gardenappl / vrms-arch

Virtual Richard M. Stallman for Arch Linux
BSD 3-Clause "New" or "Revised" License
13 stars 6 forks source link

Feature request: Add option to check single package(s) #10

Open mahlzahn opened 11 months ago

mahlzahn commented 11 months ago

Expected behaviour

For a free package packageA, a non-free packageB and a packageC with ambiguous licenses

vrms packageA packageB packageC

should yield

packageB: ['nonFreeLicenseA', …]

and possibly in the stderr

Non-free packages: 1 (33.3% of total)
Packages with ambiguous licenses: 1 (33.3% of total)
Use --list-unknowns to list them (or --help for more info)

If a package of given packages is not found either raise an error or write a message to the stderr with the corresponding package and maybe exit with error code 1.

Origin of package information

I suggest to look for the license information for a given package in the following order:

  1. locally installed packages
  2. global package database (from synced repositories, as with option -g)
  3. [optional] external: official package repository on https://archlinux.org/packages
  4. [optional] external: community-operated package repository on https://aur.archlinux.org

Possible implementation of external lookup

The search in 1. and 2. should be easily implementable. 3. and 4. need some further implementation (either with external package or with some simple HTTP requests, see https://wiki.archlinux.org/title/Official_repositories_web_interface#Exact_name and https://aur.archlinux.org/rpc/swagger)

E.g. for package coreutils

import json
import urllib.request

package = 'coreutils'
with urllib.request.urlopen(f'https://archlinux.org/packages/search/json/?name={package}') as f:
    print(json.JSONDecoder().decode(f.read().decode())['results'][0]['licenses'])

yields

['GFDL-1.3-or-later', 'GPL-3.0-or-later']

and for package vrms-arch

package = 'vrms-arch'
with urllib.request.urlopen(f'https://aur.archlinux.org/rpc/v5/info/{package}') as f:
    print(json.JSONDecoder().decode(f.read().decode())['results'][0]['License'])

yields

['custom:BSD3']

Of course, this needs also proper handling of errors such as missing internet connection, etc.