1 # -*- coding: utf-8 -*-
3 # Copyright (C) 2020 kaliko <kaliko@azylum.org>
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, version 3 only.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 from re import compile as re_compile
20 from .plugin import Plugin, botcmd
21 from .lib import get_pkg
24 class Archive(Plugin):
25 """Fetch package info from the archive
27 stable_codename = 'buster'
28 re_pkg = re_compile(r'(?P<package>[0-9a-z.+-]+)$')
30 def __init__(self, bot):
31 Plugin.__init__(self, bot)
34 def archive(self, rcv, args):
35 """Fetch pkg info from the archive:
37 !archive pkg-name : Returns package versions (by suite)
42 self.log.info('more than one packages provided')
43 pkg = Archive.re_pkg.match(args[0])
45 msg = 'Wrong package name format re: "{}"'.format(
46 Archive.re_pkg.pattern)
49 pkg_name = pkg.groupdict('package').get('package')
50 info = get_pkg(pkg_name)
52 self.reply(rcv, 'pakage not found')
55 suites_av = set(info.keys() & {'stable', 'testing', 'unstable',
56 f'{Archive.stable_codename}-backports'})
57 for suite in sorted(suites_av):
58 cpnt = '/'.join({v['component'] for v in info[suite].values()})
59 versions = '/'.join(info[suite].keys())
60 messages.append(f'{suite:16}: {versions} {cpnt}')
61 msg = '\n'.join(messages)