Debian: Add configurable default values for @version.

master
Valentin Lorentz 2013-07-23 12:39:37 +02:00
parent 7d29b3c295
commit d4c0b34e3f
2 changed files with 45 additions and 19 deletions

View File

@ -43,30 +43,51 @@ def configure(advanced):
from supybot.questions import output, expect, anything, something, yn from supybot.questions import output, expect, anything, something, yn
conf.registerPlugin('Debian', True) conf.registerPlugin('Debian', True)
class ValidBranch(registry.OnlySomeStrings): class ValidFileBranch(registry.OnlySomeStrings):
validStrings = ('oldstable', 'stable', 'testing', 'unstable', validStrings = ('oldstable', 'stable', 'testing', 'unstable',
'experimental') 'experimental')
class ValidMode(registry.OnlySomeStrings): class ValidFileMode(registry.OnlySomeStrings):
validStrings = ('path', 'exactfilename', 'filename') validStrings = ('path', 'exactfilename', 'filename')
class ValidSection(registry.OnlySomeStrings): class ValidFileSection(registry.OnlySomeStrings):
validStrings = ('any', 'main', 'contrib', 'non-free') 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') Debian = conf.registerPlugin('Debian')
conf.registerChannelValue(Debian, 'bold', conf.registerChannelValue(Debian, 'bold',
registry.Boolean(True, _("""Determines whether the plugin will use bold in registry.Boolean(True, _("""Determines whether the plugin will use bold in
the responses to some of its commands."""))) the responses to some of its commands.""")))
conf.registerGroup(Debian, 'defaults') conf.registerGroup(Debian, 'defaults')
conf.registerChannelValue(Debian.defaults, 'branch', conf.registerGroup(Debian.defaults, 'file')
ValidBranch('stable', _("""Determines the default branch, ie. the branch conf.registerChannelValue(Debian.defaults.file, 'branch',
selected if --branch is not given."""))) ValidFileBranch('stable', _("""Determines the default branch, ie. the
conf.registerChannelValue(Debian.defaults, 'mode', branch selected if --branch is not given.""")))
ValidMode('path', _("""Determines the default mode, ie. the mode conf.registerChannelValue(Debian.defaults.file, 'mode',
ValidFileMode('path', _("""Determines the default mode, ie. the mode
selected if --mode is not given."""))) selected if --mode is not given.""")))
conf.registerChannelValue(Debian.defaults, 'section', conf.registerChannelValue(Debian.defaults.file, 'section',
ValidSection('any', _("""Determines the default section, ie. the section ValidFileSection('any', _("""Determines the default section, ie. the
selected if --section is not given."""))) section selected if --section is not given.""")))
conf.registerChannelValue(Debian.defaults, 'arch', conf.registerChannelValue(Debian.defaults.file, 'arch',
registry.String('any', _("""Determines the default architecture, registry.String('any', _("""Determines the default architecture,
ie. the architecture selected if --arch is not given."""))) 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: # vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:

View File

@ -64,12 +64,13 @@ class Debian(callbacks.Plugin):
url = 'http://packages.debian.org/search?searchon=contents' + \ url = 'http://packages.debian.org/search?searchon=contents' + \
'&keywords=%(keywords)s&mode=%(mode)s&suite=%(suite)s' + \ '&keywords=%(keywords)s&mode=%(mode)s&suite=%(suite)s' + \
'&arch=%(arch)s' '&arch=%(arch)s'
chan = msg.args[0] def reg(name):
return self.registryValue('defaults.file.%s' % name, msg.args[0])
args = {'keywords': None, args = {'keywords': None,
'mode': self.registryValue('defaults.mode', chan), 'mode': reg('mode'),
'suite': self.registryValue('defaults.branch', chan), 'suite': reg('branch'),
'section': self.registryValue('defaults.section', chan), 'section': reg('section'),
'arch': self.registryValue('defaults.arch', chan)} 'arch': reg('arch')}
exact = ('exact', True) in optlist exact = ('exact', True) in optlist
for (key, value) in optlist: for (key, value) in optlist:
if key == 'branch': if key == 'branch':
@ -139,8 +140,12 @@ class Debian(callbacks.Plugin):
--section defaults to all, and defines in what section to search.""" --section defaults to all, and defines in what section to search."""
url = 'http://packages.debian.org/search?keywords=%(keywords)s' + \ url = 'http://packages.debian.org/search?keywords=%(keywords)s' + \
'&searchon=%(searchon)s&suite=%(suite)s&section=%(section)s' '&searchon=%(searchon)s&suite=%(suite)s&section=%(section)s'
args = {'keywords': None, 'searchon': 'names', 'suite': 'all', def reg(name):
'section': 'all'} 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: for (key, value) in optlist:
if key == 'exact': if key == 'exact':
url += '&exact=1' url += '&exact=1'