From d4c0b34e3ff9bcf56ce3a97065f280afdf4bdb57 Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Tue, 23 Jul 2013 12:39:37 +0200 Subject: [PATCH] Debian: Add configurable default values for @version. --- Debian/config.py | 45 +++++++++++++++++++++++++++++++++------------ Debian/plugin.py | 19 ++++++++++++------- 2 files changed, 45 insertions(+), 19 deletions(-) diff --git a/Debian/config.py b/Debian/config.py index ba3e129..66c6237 100644 --- a/Debian/config.py +++ b/Debian/config.py @@ -43,30 +43,51 @@ def configure(advanced): from supybot.questions import output, expect, anything, something, yn conf.registerPlugin('Debian', True) -class ValidBranch(registry.OnlySomeStrings): +class ValidFileBranch(registry.OnlySomeStrings): validStrings = ('oldstable', 'stable', 'testing', 'unstable', 'experimental') -class ValidMode(registry.OnlySomeStrings): +class ValidFileMode(registry.OnlySomeStrings): validStrings = ('path', 'exactfilename', 'filename') -class ValidSection(registry.OnlySomeStrings): +class ValidFileSection(registry.OnlySomeStrings): validStrings = ('any', 'main', 'contrib', 'non-free') +class ValidVersionBranch(registry.OnlySomeStrings): + validStrings = ('oldstable', 'stable', 'testing', 'unstable', + 'experimental', 'all') +class ValidVersionSection(registry.OnlySomeStrings): + validStrings = ('all', 'main', 'contrib', 'non-free') +class ValidVersionSearchon(registry.OnlySomeStrings): + validStrings = ('names', 'all', 'sourcenames') + Debian = conf.registerPlugin('Debian') conf.registerChannelValue(Debian, 'bold', registry.Boolean(True, _("""Determines whether the plugin will use bold in the responses to some of its commands."""))) conf.registerGroup(Debian, 'defaults') -conf.registerChannelValue(Debian.defaults, 'branch', - ValidBranch('stable', _("""Determines the default branch, ie. the branch - selected if --branch is not given."""))) -conf.registerChannelValue(Debian.defaults, 'mode', - ValidMode('path', _("""Determines the default mode, ie. the mode +conf.registerGroup(Debian.defaults, 'file') +conf.registerChannelValue(Debian.defaults.file, 'branch', + ValidFileBranch('stable', _("""Determines the default branch, ie. the + branch selected if --branch is not given."""))) +conf.registerChannelValue(Debian.defaults.file, 'mode', + ValidFileMode('path', _("""Determines the default mode, ie. the mode selected if --mode is not given."""))) -conf.registerChannelValue(Debian.defaults, 'section', - ValidSection('any', _("""Determines the default section, ie. the section - selected if --section is not given."""))) -conf.registerChannelValue(Debian.defaults, 'arch', +conf.registerChannelValue(Debian.defaults.file, 'section', + ValidFileSection('any', _("""Determines the default section, ie. the + section selected if --section is not given."""))) +conf.registerChannelValue(Debian.defaults.file, 'arch', registry.String('any', _("""Determines the default architecture, ie. the architecture selected if --arch is not given."""))) +conf.registerGroup(Debian.defaults, 'version') +conf.registerChannelValue(Debian.defaults.version, 'branch', + ValidVersionBranch('all', _("""Determines the default branch, ie. the + branch selected if --branch is not given."""))) +conf.registerChannelValue(Debian.defaults.version, 'section', + ValidVersionSection('all', _("""Determines the default section, ie. the + section selected if --section is not given."""))) +conf.registerChannelValue(Debian.defaults.version, 'searchon', + ValidVersionSearchon('names', _("""Determines the default 'searchon', ie. + where to search if --searchon is not given."""))) + + # vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: diff --git a/Debian/plugin.py b/Debian/plugin.py index 7189f3b..b4a2785 100644 --- a/Debian/plugin.py +++ b/Debian/plugin.py @@ -64,12 +64,13 @@ class Debian(callbacks.Plugin): url = 'http://packages.debian.org/search?searchon=contents' + \ '&keywords=%(keywords)s&mode=%(mode)s&suite=%(suite)s' + \ '&arch=%(arch)s' - chan = msg.args[0] + def reg(name): + return self.registryValue('defaults.file.%s' % name, msg.args[0]) args = {'keywords': None, - 'mode': self.registryValue('defaults.mode', chan), - 'suite': self.registryValue('defaults.branch', chan), - 'section': self.registryValue('defaults.section', chan), - 'arch': self.registryValue('defaults.arch', chan)} + 'mode': reg('mode'), + 'suite': reg('branch'), + 'section': reg('section'), + 'arch': reg('arch')} exact = ('exact', True) in optlist for (key, value) in optlist: if key == 'branch': @@ -139,8 +140,12 @@ class Debian(callbacks.Plugin): --section defaults to all, and defines in what section to search.""" url = 'http://packages.debian.org/search?keywords=%(keywords)s' + \ '&searchon=%(searchon)s&suite=%(suite)s§ion=%(section)s' - args = {'keywords': None, 'searchon': 'names', 'suite': 'all', - 'section': 'all'} + def reg(name): + return self.registryValue('defaults.version.%s' % name, msg.args[0]) + args = {'keywords': None, + 'searchon': reg('searchon'), + 'suite': reg('branch'), + 'section': reg('section')} for (key, value) in optlist: if key == 'exact': url += '&exact=1'