mirror of
https://github.com/MCV-Software/TWBlue.git
synced 2024-11-22 19:28:09 -06:00
Added exception handlers to deshelve and shelve methods.
This commit is contained in:
parent
7174984973
commit
f39adb658b
@ -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")
|
||||||
shelf=shelve.open(paths.config_path(shelfname),'c')
|
try:
|
||||||
for key,value in self.db.items():
|
shelf=shelve.open(paths.config_path(shelfname),'c')
|
||||||
shelf[key]=value
|
for key,value in self.db.items():
|
||||||
shelf.close()
|
print(key)
|
||||||
|
shelf[key]=value
|
||||||
|
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")
|
||||||
shelf=shelve.open(paths.config_path(shelfname),'c')
|
try:
|
||||||
for key,value in shelf.items():
|
shelf=shelve.open(paths.config_path(shelfname),'c')
|
||||||
self.db[key]=value
|
for key,value in shelf.items():
|
||||||
shelf.close()
|
self.db[key]=value
|
||||||
|
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)
|
Loading…
Reference in New Issue
Block a user