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