This commit is contained in:
Terence Simpson 2010-05-29 00:55:07 +01:00
parent f3de8f84a6
commit 5082202a3e
3 changed files with 48 additions and 42 deletions

View File

@ -28,7 +28,7 @@ class SpaceSeparatedListOfTypes(registry.SpaceSeparatedListOf):
def configure(advanced):
from supybot.question import yn, something, output
from supybot.questions import yn, something, output
import sqlite
import re
import os
@ -43,7 +43,7 @@ def configure(advanced):
def getReviewTime():
output("How many days should the bot wait before requesting a ban/quiet review?")
review = something("Can be an integer or decimal value. Zero disables reviews.", default=str(Bantracker.review._default))
review = something("Can be an integer or decimal value. Zero disables reviews.", default=str(Bantracker.request.review._default))
try:
review = float(review)
@ -62,17 +62,17 @@ def configure(advanced):
request = yn("Enable review and comment requests from bot?", default=False)
if request and advanced:
output("Which types would you like the bot to request comments for?")
output(format("The available request types are %L", type))
types = anything("Separate types by spaces or commas:", default=', '.join(Bantracker.type._default))
output(format("The available request types are %L", Bantracker.request.type._default))
types = anything("Separate types by spaces or commas:", default=', '.join(Bantracker.request.type._default))
type = set([])
for name in re.split(r',?\s+', types):
name = name.lower()
if name in ('removal', 'ban', 'quiet'):
type.append(name)
type.add(name)
output("Which nicks should be bot not requets comments from?")
output("Is case insensitive and wildcards '*' and '?' are accepted.")
ignores = anything("Separate types by spaces or commas:", default=', '.join(Bantracker.ignore._default))
ignores = anything("Separate types by spaces or commas:", default=', '.join(Bantracker.request.ignore._default))
ignore = set([])
for name in re.split(r',?\s+', ignores):
name = name.lower()
@ -81,7 +81,7 @@ def configure(advanced):
output("You can set the comment and review requests for some nicks to be forwarded to specific nicks/channels")
output("Which nicks should these requests be forwarded for?")
output("Is case insensitive and wildcards '*' and '?' are accepted.")
forwards = anything("Separate types by spaces or commas:", default=', '.join(Bantracker.forward._default))
forwards = anything("Separate types by spaces or commas:", default=', '.join(Bantracker.request.forward._default))
forward = set([])
for name in re.split(r',?\s+', forwards):
name = name.lower()
@ -89,30 +89,30 @@ def configure(advanced):
output("Which nicks/channels should the requests be forwarded to?")
output("Is case insensitive and wildcards '*' and '?' are accepted.")
channels_i = anything("Separate types by spaces or commas:", default=', '.join(Bantracker.channels._default))
channels_i = anything("Separate types by spaces or commas:", default=', '.join(Bantracker.request.forward._default))
channels = set([])
for name in re.split(r',?\s+', channel_i):
for name in re.split(r',?\s+', channels_i):
name = name.lower()
channels.add(name)
review = getReviewTime()
else:
type = Bantracker.type._default
ignore = Bantracker.ignore._default
forward = Bantracker.forward._default
channels = Bantracker.channels._default
review = Bantracker.review._default
type = Bantracker.request.type._default
ignore = Bantracker.request.ignore._default
forward = Bantracker.request.forward._default
channels = Bantracker.request.forward.channels._default
review = Bantracker.request.review._default
Bantracker.enabled.setValue(enabled)
Bantracker.database.setValue(database)
Bantracker.bansite.setValue(bansite)
Bantracker.request.setValue(request)
Bantracker.type.setValue(type)
Bantracker.ignore.setValue(ignore)
Bantracker.forward.setValue(forward)
Bantracker.channels.setValue(channels)
Bantracker.review.setValue(review)
Bantracker.request.type.setValue(type)
Bantracker.request.ignore.setValue(ignore)
Bantracker.request.forward.setValue(forward)
Bantracker.request.forward.channels.setValue(channels)
Bantracker.request.review.setValue(review)
# Create the initial database
db_file = Bantracker.database()
@ -129,7 +129,6 @@ def configure(advanced):
cur = con.cursor()
try:
con.begin()
cur.execute("""CREATE TABLE 'bans' (
id INTEGER PRIMARY KEY,
channel VARCHAR(30) NOT NULL,
@ -170,6 +169,7 @@ def configure(advanced):
else:
con.commit()
finally:
cur.close()
con.close()
Bantracker = conf.registerPlugin('Bantracker')

View File

@ -20,6 +20,7 @@ import supybot.registry as registry
def configure(advanced):
from supybot.questions import yn, something, output
from supybot.utils.str import format
import os
import sqlite
import re
@ -38,11 +39,11 @@ def configure(advanced):
ignores = set([])
output("This plugin can be configured to always ignore certain factoid requests, this is useful when you want another plugin to handle them")
output("For instance, the PackageInfo plugin responds to !info and !find, so those should be ignored in Encyclopedia to allow this to work")
ignores_i = anythnig("Which factoid requets should the bot always ignore?", default=', '.join(Encyclopedia.ignores._default))
for name in re.split(r',?\s', +ignore_i):
ignores_i = anything("Which factoid requets should the bot always ignore?", default=', '.join(Encyclopedia.ignores._default))
for name in re.split(r',?\s', ignores_i):
ignores.add(name.lower())
curStabel = something("What is short name of the current stable release?", default=Encyclopedia.curStable._default)
curStable = something("What is short name of the current stable release?", default=Encyclopedia.curStable._default)
curStableLong = something("What is long name of the current stable release?", default=Encyclopedia.curStableLong._default)
curStableNum = something("What is version number of the current stable release?", default=Encyclopedia.curStableNum._default)
@ -51,14 +52,14 @@ def configure(advanced):
curDevelNum = something("What is version number of the current development release?", default=Encyclopedia.curDevelNum._default)
curLTS = something("What is short name of the current LTS release?", default=Encyclopedia.curLTS._default)
curLTSong = something("What is long name of the current LTS release?", default=Encyclopedia.curLTSLoong._default)
curLTSLong = something("What is long name of the current LTS release?", default=Encyclopedia.curLTSLong._default)
curLTSNum = something("What is version number of the current LTS release?", default=Encyclopedia.curLTSNum._default)
else:
datadir = Encyclopedia.datadir._default
database = Encyclopedia.database._default
prefixchar = Encyclopedia.prefixchar._default
ignores = Encyclopedia.ignores._default
curStabel = Encyclopedia.curStable._default
curStable = Encyclopedia.curStable._default
curStableLong = Encyclopedia.curStableLong._default
curStableNum = Encyclopedia.curStableNum._default
curDevel = Encyclopedia.curDevel._default
@ -120,7 +121,6 @@ def configure(advanced):
cur = con.cursor()
try:
con.begin()
cur.execute("""CREATE TABLE facts (
id INTEGER PRIMARY KEY,
author VARCHAR(100) NOT NULL,
@ -144,6 +144,7 @@ def configure(advanced):
else:
con.commit()
finally:
cur.close()
con.close()
Encyclopedia = conf.registerPlugin('Encyclopedia')

View File

@ -24,9 +24,11 @@ def configure(advanced):
def makeSource(release):
return """deb http://archive.ubuntu.com/ubuntu/ %s main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ %s main restricted universe multiverse
"""
""" % (release, release)
#"""
from supybot.questions import output, expect, something, yn
import commands
import os
def anything(prompt, default=None):
@ -41,12 +43,12 @@ deb-src http://archive.ubuntu.com/ubuntu/ %s main restricted universe multiverse
if enabled and advanced:
prefixchar = something("Which prefix character should be bot respond to?", default=PackageInfo.prefixchar._default)
defaultRelease = something("What should be the default distrobution when not specified?", default=PackageInfo.defaultRelease._default)
aptdir = something("Which directory should be used for the apt cache when looking up packages?", default=supybot.directories.data.dirize('aptdir'))
aptdir = something("Which directory should be used for the apt cache when looking up packages?", default=conf.supybot.directories.data.dirize('aptdir'))
# People tend to thing this should be /var/cache/apt
while aptdir.beginswith('/var'):
while aptdir.startswith('/var'):
output("NO! Do not use your systems apt directory")
aptdir = something("Which directory should be used for the apt cache when looking up packages?", default=supybot.directories.data.dirize('aptdir'))
aptdir = something("Which directory should be used for the apt cache when looking up packages?", default=conf.supybot.directories.data.dirize('aptdir'))
else:
prefixchar = PackageInfo.prefixchar._default
@ -66,11 +68,17 @@ deb-src http://archive.ubuntu.com/ubuntu/ %s main restricted universe multiverse
default_dists.add(defaultRelease)
for release in default_dist:
## Create the aptdir
try:
os.makedirs(aptdir)
except OSError: # The error number would be OS dependant (17 on Linux 2.6, ?? on others). So just pass on this
pass
for release in default_dists:
filename = os.path.join(aptdir, "%s.list" % release)
try:
output("Creating %s" % filename)
fd = fileutils.open(filename)
fd = open(filename, 'wb')
fd.write("# Apt sources list for Ubuntu %s\n" % release)
fd.write(makeSource(release))
fd.write(makeSource(release + '-security'))
@ -78,30 +86,27 @@ deb-src http://archive.ubuntu.com/ubuntu/ %s main restricted universe multiverse
fd.close()
for sub in ('backports', 'proposed'):
release = "%s-%s" % sub
filename = os.path.join(aptdir, "%s.list" % release)
sub_release = "%s-%s" % (release, sub)
filename = os.path.join(aptdir, "%s.list" % sub_release)
output("Creating %s" % filename)
fd = fileutils.open(filename)
fd = open(filename, 'wb')
fd.write("# Apt sources list for Ubuntu %s\n" % release)
fd.write(makeSource(release))
fd.write(makeSource(sub_release))
fd.close()
except Exception, e:
output("Error writing to %r: %r (%s)" % (filename, str(e), type(e)))
if yn("In order for the plugin to use these sources, you must run the 'update_apt' script, do you want to do this now?", default=True):
os.environ['DIR'] = aptdir # the update_apt script checks if DIR is set and uses it if it is
(e, o) = commands.getstatusoutput(update_apt)
if e != 0:
if commands.getstatus(update_apt) != 0:
output("There was an error running update_apt, please run '%s -v' to get more information" % update_apt)
(e, o) = commands.statusoutput('which apt-file')
if e != 0:
if commands.getstatusoutput('which apt-file') != 0:
output("You need to install apt-file in order to use the !find command of this plugin")
else:
if yn("In order for the !find command to work, you must run the 'update_apt_file' script, do you want to do this now?", default=True):
os.environ['DIR'] = aptdir # the update_apt_file script checks if DIR is set and uses it if it is
(e, o) = commands.getstatusoutput(update_apt_file)
if e != 0:
if commands.getstatusoutput(update_apt_file) != 0:
output("There was an error running update_apt_file, please run '%s -v' to get more information" % update_apt_file)
PackageInfo = conf.registerPlugin('PackageInfo')