# -*- coding: utf-8 -*-
+# SPDX-FileCopyrightText: 2020 kaliko <kaliko@azylum.org>
+# SPDX-License-Identifier: GPL-3.0-or-later
+"""Fetch packages info from the archive
-# Copyright (C) 2020 kaliko <kaliko@azylum.org>
-
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, version 3 only.
-
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
+>>> from sid.archive import Archive
+"""
from re import compile as re_compile
class Archive(Plugin):
- """Fetch package info from the archive
+ """Fetches package info from the archive
"""
+ #: Current stable Suite
stable_codename = 'buster'
+ #: Pakage name regexp
re_pkg = re_compile(r'(?P<package>[0-9a-z.+-]+)$')
def __init__(self, bot):
Plugin.__init__(self, bot)
- bot.add_event_handler("muc::%s::message" %
- self.bot.room, self.muc_message)
-
- def muc_message(self, msg):
- """Handler method dealing with MUC incoming messages"""
- # Does not reply to myself
- if msg['mucnick'] == self.bot.nick:
- return
- if '#' not in msg['body']:
- return
- bugs = list()
- for bug_id in set(Bugs.re_bugs.findall(msg['body'].strip())):
- self.log.debug('got bug id: %s', bug_id)
- query = debianbts.get_status(bug_id)
- if len(query) == 1:
- bug = query[0]
- url = debianbts.BTS_URL + bug_id
- bugs.append({'id': bug_id,
- 'package': bug.package,
- 'summary': bug.subject,
- 'url': url})
- else:
- self.log.warning('Wrong bug number "%s"?', bug_id)
- bugs.append({'id': bug_id})
- for bug in bugs:
- if len(bug) == 1:
- message = 'Invalid bug id: {id}'.format(**bug)
- self.reply(msg, message)
- else:
- message = {'mhtml': '<a href="%(url)s">#%(id)s</a>: %(package)s “ %(summary)s ”' % bug,
- 'mbody': '#%(id)s: %(package)s “ %(summary)s ” %(url)s' % bug}
- self.reply(msg, message)
@botcmd
def archive(self, rcv, args):
- """Fetch pkg info from the archive:
+ """Fetches package info from the archive
- !archive pkg-name : Returns package versions (by suite)
- """
+ ``!archive pkg-name`` : Returns package versions (by suite)"""
if not args:
return
if len(args) > 1:
suites_av = set(info.keys() & {'stable', 'testing', 'unstable',
f'{Archive.stable_codename}-backports'})
for suite in sorted(suites_av):
- component = '/'.join({v['component'] for v in info[suite].values()})
+ cpnt = '/'.join({v['component'] for v in info[suite].values()})
versions = '/'.join(info[suite].keys())
- messages.append(f'{suite:16}: {versions} {component}')
+ messages.append(f'{suite:16}: {versions} {cpnt}')
msg = '\n'.join(messages)
self.reply(rcv, msg)