Skip to content

Commit

Permalink
feat: add snapcraft source
Browse files Browse the repository at this point in the history
  • Loading branch information
Maks1mS authored Feb 22, 2025
1 parent fca89f7 commit cc9001a
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
14 changes: 14 additions & 0 deletions docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
~~~~~~~~~~~~~~~~~~~~~~~
::
Expand Down
32 changes: 32 additions & 0 deletions nvchecker_source/snapcraft.py
Original file line number Diff line number Diff line change
@@ -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}")

0 comments on commit cc9001a

Please sign in to comment.