arch-scripts/aur.py
coderkun 50e01eaabd Load all AUR packages of a database with one call
Use a single RPC call to load all AUR packages for a database.
Additionally use verson 5 since all previous versions have been
deprecated.
2021-09-21 23:51:25 +02:00

168 lines
3.6 KiB
Python

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import certifi
import json
import urllib3
class AURPackage:
"""Representation of an Arch Linux User Repsitory (AUR) package."""
def __init__(self, name):
"""Construct a new AUR package representation."""
self.name = name
self.version = None
self.desc = None
self.url = None
self.license = None
self.maintainer = None
self.votes = None
self.url_path = None
self.package_base = None
self.out_of_date = None
self.last_modified = None
self._exists = False
def get_name(self):
"""Get name."""
return self.name
def set_version(self, version):
"""Set version."""
self.version = version
def get_version(self):
"""Get version."""
return self.version
def set_desc(self, desc):
"""Set description."""
self.desc = desc
def get_desc(self):
"""Get description."""
return self.desc
def set_url(self, url):
"""Set URL."""
self.url = url
def get_url(self):
"""Get URL."""
return self.url
def set_license(self, license):
"""Set license."""
self.license = license
def get_license(self):
"""Get license."""
return self.license
def set_maintainer(self, maintainer):
"""Set maintainer."""
self.maintainer = maintainer
def get_maintainer(self):
"""Get maintainer."""
return self.maintainer
def set_votes(self, votes):
"""Set number of votes."""
self.votes = votes
def get_votes(self):
"""Get number of votes."""
return self.votes
def set_url_path(self, url_path):
"""Set URL path."""
self.url_path = url_path
def get_url_path(self):
"""Get URL path."""
return self.url_path
def set_package_base(self, package_base):
"""Set package base."""
self.package_base = package_base
def get_package_base(self):
"""Get package base."""
return self.package_base
def set_out_of_date(self, out_of_date):
"""Set date the package was flagged as out-of-date."""
self.out_of_date = out_of_date
def get_out_of_date(self):
"""Get date the package was flagged as out-of-date."""
return self.out_of_date
def set_last_modified(self, last_modified):
"""Set date of last modification."""
self.last_modified = last_modified
def get_last_modified(self):
"""Get date of last modification."""
return self.last_modified
class AURLoader:
"""URL of the [AUR] website"""
AUR_URL = 'https://aur.archlinux.org'
"""URL-path for packages"""
PACKAGE_PATH = 'packages'
"""URL-path of RPC"""
RPC_PATH = 'rpc'
"""Parameters of RPC"""
RPC_PARAMS = 'v=5&type=info'
"""Argument parameter of RPC"""
RPC_PARAM_ARG = 'arg[]'
def load_package_data(names):
"""Load packages via API."""
# Construct URL
url = "{}/{}?{}".format(AURLoader.AUR_URL, AURLoader.RPC_PATH, AURLoader.RPC_PARAMS)
for name in names:
url += "&{}={}".format(AURLoader.RPC_PARAM_ARG, name)
# Call API via https
https = urllib3.PoolManager(ca_certs=certifi.where())
# Get and parse response
response = https.request('GET', url)
if response.status == 200:
data = json.loads(response.data.decode('utf-8'))
if data['resultcount'] > 0:
return data['results']
else:
print("error:", response.status)
return []