mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-27 13:19:24 +01:00
Better error handling of bad loads.
This commit is contained in:
parent
58b3268bdd
commit
33254cb538
@ -76,13 +76,19 @@ class PickleBayesDB(plugins.DbiChannelDB):
|
|||||||
self.filename = filename
|
self.filename = filename
|
||||||
self.nickFilename = self.filename.replace('pickle', 'nick.pickle')
|
self.nickFilename = self.filename.replace('pickle', 'nick.pickle')
|
||||||
self.bayes = reverend.thomas.Bayes(tokenize)
|
self.bayes = reverend.thomas.Bayes(tokenize)
|
||||||
if os.path.exists(self.filename) and \
|
if os.path.exists(self.filename):
|
||||||
os.path.getsize(self.filename):
|
try:
|
||||||
self.bayes.load(self.filename)
|
self.bayes.load(self.filename)
|
||||||
|
except (EOFError, EnvironmentError), e:
|
||||||
|
log.error('Couldn\'t load bayes pickle from %s: %s',
|
||||||
|
self.filename, utils.exnToString(e))
|
||||||
self.nickBayes = reverend.thomas.Bayes(tokenize)
|
self.nickBayes = reverend.thomas.Bayes(tokenize)
|
||||||
if os.path.exists(self.nickFilename) and \
|
if os.path.exists(self.nickFilename):
|
||||||
os.path.getsize(self.nickFilename):
|
try:
|
||||||
self.nickBayes.load(self.nickFilename)
|
self.nickBayes.load(self.nickFilename)
|
||||||
|
except (EOFError, EnvironmentError), e:
|
||||||
|
log.error('Couldn\'t load nickbayes pickle from %s: %s',
|
||||||
|
self.nickFilename, utils.exnToString(e))
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
self.bayes.save(self.filename)
|
self.bayes.save(self.filename)
|
||||||
@ -121,6 +127,8 @@ class Bayes(callbacks.Privmsg):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.__parent = super(Bayes, self)
|
self.__parent = super(Bayes, self)
|
||||||
self.__parent.__init__()
|
self.__parent.__init__()
|
||||||
|
global log
|
||||||
|
log = self.log
|
||||||
self.db = BayesDB()
|
self.db = BayesDB()
|
||||||
|
|
||||||
def die(self):
|
def die(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user