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
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:

View File

@ -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&section=%(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'