]> kaliko git repositories - sid.git/blob - sid/archive.py
Bump version
[sid.git] / sid / archive.py
1 # -*- coding: utf-8 -*-
2
3 # Copyright (C) 2020 kaliko <kaliko@azylum.org>
4
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.
8
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.
13
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/>.
16
17
18 from re import compile as re_compile
19
20 from .plugin import Plugin, botcmd
21 from .lib import get_pkg
22
23
24 class Archive(Plugin):
25     """Fetches package info from the archive
26     """
27     #: Current stable Suite
28     stable_codename = 'buster'
29     #: Pakage name regexp
30     re_pkg = re_compile(r'(?P<package>[0-9a-z.+-]+)$')
31
32     def __init__(self, bot):
33         Plugin.__init__(self, bot)
34
35     @botcmd
36     def archive(self, rcv, args):
37         """Fetches package info from the archive
38
39         ``!archive pkg-name`` : Returns package versions (by suite)"""
40         if not args:
41             return
42         if len(args) > 1:
43             self.log.info('more than one packages provided')
44         pkg = Archive.re_pkg.match(args[0])
45         if not pkg:
46             msg = 'Wrong package name format re: "{}"'.format(
47                 Archive.re_pkg.pattern)
48             self.reply(rcv, msg)
49             return
50         pkg_name = pkg.groupdict('package').get('package')
51         info = get_pkg(pkg_name)
52         if not info:
53             self.reply(rcv, 'pakage not found')
54             return
55         messages = []
56         suites_av = set(info.keys() & {'stable', 'testing', 'unstable',
57                                        f'{Archive.stable_codename}-backports'})
58         for suite in sorted(suites_av):
59             cpnt = '/'.join({v['component'] for v in info[suite].values()})
60             versions = '/'.join(info[suite].keys())
61             messages.append(f'{suite:16}: {versions} {cpnt}')
62         msg = '\n'.join(messages)
63         self.reply(rcv, msg)