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.
This commit is contained in:
parent
e2008e8700
commit
50e01eaabd
2 changed files with 117 additions and 47 deletions
127
aur.py
127
aur.py
|
|
@ -11,14 +11,6 @@ import urllib3
|
|||
|
||||
class AURPackage:
|
||||
"""Representation of an Arch Linux User Repsitory (AUR) package."""
|
||||
"""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.php'
|
||||
"""Parameters of RPC"""
|
||||
RPC_PARAMS = 'type=info&arg='
|
||||
|
||||
|
||||
def __init__(self, name):
|
||||
|
|
@ -35,39 +27,6 @@ class AURPackage:
|
|||
self.out_of_date = None
|
||||
self.last_modified = None
|
||||
self._exists = False
|
||||
self._load(name)
|
||||
|
||||
|
||||
def _load(self, name):
|
||||
"""Load package via API."""
|
||||
# Construct URL
|
||||
url = "{}/{}?{}{}".format(AURPackage.AUR_URL, AURPackage.RPC_PATH, AURPackage.RPC_PARAMS, 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:
|
||||
self._exists = True
|
||||
values = data['results']
|
||||
self.version = values['Version']
|
||||
self.desc = values['Description']
|
||||
self.url = values['URL']
|
||||
self.license = values['License']
|
||||
self.maintainer = values['Maintainer']
|
||||
self.votes = values['NumVotes']
|
||||
self.url_path = values['URLPath']
|
||||
self.package_base = values['PackageBase']
|
||||
self.out_of_date = values['OutOfDate']
|
||||
self.last_modified = values['LastModified']
|
||||
else:
|
||||
print("error:", response.status)
|
||||
|
||||
|
||||
def exists(self):
|
||||
"""Check if the package exists (in the AUR)."""
|
||||
return self._exists
|
||||
|
||||
|
||||
def get_name(self):
|
||||
|
|
@ -75,51 +34,135 @@ class AURPackage:
|
|||
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 []
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue