1 # -*- coding: utf-8 -*-
2 # SPDX-FileCopyrightText: 2020 kaliko <kaliko@azylum.org>
3 # SPDX-License-Identifier: GPL-3.0-or-later
4 """Fetch packages info from the archive
6 >>> from sid.archive import Archive
9 from re import compile as re_compile
11 from .plugin import Plugin, botcmd
12 from .lib import get_pkg
15 class Archive(Plugin):
16 """Fetches package info from the archive
18 #: Current stable Suite
19 stable_codename = 'buster'
21 re_pkg = re_compile(r'(?P<package>[0-9a-z.+-]+)$')
23 def __init__(self, bot):
24 Plugin.__init__(self, bot)
27 def archive(self, rcv, args):
28 """Fetches package info from the archive
30 ``!archive pkg-name`` : Returns package versions (by suite)"""
34 self.log.info('more than one packages provided')
35 pkg = Archive.re_pkg.match(args[0])
37 msg = 'Wrong package name format re: "{}"'.format(
38 Archive.re_pkg.pattern)
41 pkg_name = pkg.groupdict('package').get('package')
42 info = get_pkg(pkg_name)
44 self.reply(rcv, 'pakage not found')
47 suites_av = set(info.keys() & {'stable', 'testing', 'unstable',
48 f'{Archive.stable_codename}-backports'})
49 for suite in sorted(suites_av):
50 cpnt = '/'.join({v['component'] for v in info[suite].values()})
51 versions = '/'.join(info[suite].keys())
52 messages.append(f'{suite:16}: {versions} {cpnt}')
53 msg = '\n'.join(messages)