mirror of
https://github.com/lilydjwg/nvchecker.git
synced 2025-03-10 06:14:02 +00:00
feat: add snapcraft source
This commit is contained in:
parent
fca89f7830
commit
cc9001ad88
2 changed files with 46 additions and 0 deletions
|
@ -1080,6 +1080,20 @@ repo
|
|||
|
||||
This source supports :ref:`list options`.
|
||||
|
||||
Check Snapcraft
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
::
|
||||
|
||||
source = "snapcraft"
|
||||
|
||||
This source allows you to check the latest package versions in the `Snapcraft <https://snapcraft.io>`_.
|
||||
|
||||
snap
|
||||
Name of the snap package.
|
||||
|
||||
channel
|
||||
Name of the channel.
|
||||
|
||||
Combine others' results
|
||||
~~~~~~~~~~~~~~~~~~~~~~~
|
||||
::
|
||||
|
|
32
nvchecker_source/snapcraft.py
Normal file
32
nvchecker_source/snapcraft.py
Normal file
|
@ -0,0 +1,32 @@
|
|||
# MIT licensed
|
||||
# Copyright (c) 2025 Maxim Slipenko <maxim@slipenko.com>, et al.
|
||||
|
||||
from nvchecker.api import (
|
||||
GetVersionError
|
||||
)
|
||||
|
||||
URL="https://api.snapcraft.io/v2/snaps/info/%(snap)s"
|
||||
|
||||
async def get_version(
|
||||
name: str, conf, *,
|
||||
cache, keymanager,
|
||||
**kwargs,
|
||||
):
|
||||
try:
|
||||
snap = conf.get("snap")
|
||||
channel = conf.get("channel")
|
||||
|
||||
result = await cache.get_json(
|
||||
URL % { "snap": snap },
|
||||
headers={
|
||||
"Snap-Device-Series": "16",
|
||||
},
|
||||
)
|
||||
except:
|
||||
raise GetVersionError(f"Failed to request snap info for {snap}")
|
||||
|
||||
for c in result['channel-map']:
|
||||
if c['channel']['name'] == channel:
|
||||
return c['version']
|
||||
|
||||
raise GetVersionError(f"Failed to find version for {snap}")
|
Loading…
Add table
Reference in a new issue