Debian: Fix help string of @file, add architecture selection, and configurable default values.

master
Valentin Lorentz 2013-07-23 12:15:40 +02:00
parent 677f76bc26
commit 7d29b3c295
2 changed files with 40 additions and 6 deletions

View File

@ -29,6 +29,11 @@
import supybot.conf as conf
import supybot.registry as registry
try:
from supybot.i18n import PluginInternationalization
_ = PluginInternationalization('AttackProtector')
except:
_ = lambda x:x
def configure(advanced):
# This will be called by supybot to configure this module. advanced is
@ -38,9 +43,30 @@ def configure(advanced):
from supybot.questions import output, expect, anything, something, yn
conf.registerPlugin('Debian', True)
class ValidBranch(registry.OnlySomeStrings):
validStrings = ('oldstable', 'stable', 'testing', 'unstable',
'experimental')
class ValidMode(registry.OnlySomeStrings):
validStrings = ('path', 'exactfilename', 'filename')
class ValidSection(registry.OnlySomeStrings):
validStrings = ('any', 'main', 'contrib', 'non-free')
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."""))
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
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',
registry.String('any', _("""Determines the default architecture,
ie. the architecture selected if --arch is not given.""")))
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:

View File

@ -55,6 +55,7 @@ class Debian(callbacks.Plugin):
"""[--exact] \
[--mode {path,filename,exactfilename}] \
[--branch {oldstable,stable,testing,unstable,experimental}] \
[--arch <architecture>] \
[--section {main,contrib,non-free}] <file name>
Returns the package(s) containing the <file name>.
@ -63,12 +64,18 @@ class Debian(callbacks.Plugin):
url = 'http://packages.debian.org/search?searchon=contents' + \
'&keywords=%(keywords)s&mode=%(mode)s&suite=%(suite)s' + \
'&arch=%(arch)s'
args = {'keywords': None, 'mode': 'path', 'suite': 'stable',
'arch': 'any'}
chan = 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)}
exact = ('exact', True) in optlist
for (key, value) in optlist:
if key == 'branch':
args['suite'] = value
elif key == 'section':
args['section'] = value
elif key == 'arch':
args['arch'] = value
elif key == 'mode':
@ -110,9 +117,10 @@ class Debian(callbacks.Plugin):
'mode': ('literal', ('path',
'exactfilename',
'filename')),
'arch': ('literal', ('main',
'section': ('literal', ('main',
'contrib',
'non-free'))}),
'non-free')),
'arch': 'somethingWithoutSpaces'}),
'text'])
_debreflags = re.DOTALL | re.IGNORECASE