Added exception handlers to deshelve and shelve methods.

This commit is contained in:
Bill Dengler 2015-05-02 03:41:28 -04:00
parent 7174984973
commit f39adb658b

View File

@ -13,6 +13,8 @@ from twitter import utils
from twython import TwythonError, TwythonRateLimitError, TwythonAuthError from twython import TwythonError, TwythonRateLimitError, TwythonAuthError
import config_utils import config_utils
import shelve import shelve
import application
import os
from mysc.thread_utils import stream_threaded from mysc.thread_utils import stream_threaded
from pubsub import pub from pubsub import pub
log = logging.getLogger("sessionmanager.session") log = logging.getLogger("sessionmanager.session")
@ -362,15 +364,26 @@ class Session(object):
def shelve(self): def shelve(self):
"Shelve the database to allow for persistance." "Shelve the database to allow for persistance."
shelfname=paths.config_path(str(self.session_id)+".db") shelfname=paths.config_path(str(self.session_id)+".db")
try:
shelf=shelve.open(paths.config_path(shelfname),'c') shelf=shelve.open(paths.config_path(shelfname),'c')
for key,value in self.db.items(): for key,value in self.db.items():
print(key)
shelf[key]=value shelf[key]=value
shelf.close() shelf.close()
except:
output.speak("An exception occurred while shelving the " + application.name + " database. It will be deleted and rebuilt automatically. If this error persists, send the error log to the " + application.name + " developers.",True)
log.exception("Exception while shelving" + shelfname)
os.remove(shelfname)
def deshelve(self): def deshelve(self):
"Import a shelved database." "Import a shelved database."
shelfname=paths.config_path(str(self.session_id)+".db") shelfname=paths.config_path(str(self.session_id)+".db")
try:
shelf=shelve.open(paths.config_path(shelfname),'c') shelf=shelve.open(paths.config_path(shelfname),'c')
for key,value in shelf.items(): for key,value in shelf.items():
self.db[key]=value self.db[key]=value
shelf.close() shelf.close()
except:
output.speak("An exception occurred while deshelving the " + application.name + " database. It will be deleted and rebuilt automatically. If this error persists, send the error log to the " + application.name + " developers.",True)
log.exception("Exception while deshelving" + shelfname)
os.remove(shelfname)