mirror of
https://github.com/MCV-Software/TWBlue.git
synced 2024-11-22 19:28:09 -06:00
Initial shelve support for persistance in sessions.
This commit is contained in:
parent
e7943cba50
commit
594985dec4
@ -12,6 +12,7 @@ import logging
|
|||||||
from twitter import utils
|
from twitter import utils
|
||||||
from twython import TwythonError, TwythonRateLimitError, TwythonAuthError
|
from twython import TwythonError, TwythonRateLimitError, TwythonAuthError
|
||||||
import config_utils
|
import config_utils
|
||||||
|
import shelve
|
||||||
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")
|
||||||
@ -91,7 +92,8 @@ class Session(object):
|
|||||||
self.logged = False
|
self.logged = False
|
||||||
self.settings = None
|
self.settings = None
|
||||||
self.twitter = twitter.twitter.twitter()
|
self.twitter = twitter.twitter.twitter()
|
||||||
self.db = {}
|
self.db={}
|
||||||
|
self.deshelve()
|
||||||
self.reconnection_function_active = False
|
self.reconnection_function_active = False
|
||||||
self.counter = 0
|
self.counter = 0
|
||||||
self.lists = []
|
self.lists = []
|
||||||
@ -355,4 +357,21 @@ class Session(object):
|
|||||||
del self.timelinesStream
|
del self.timelinesStream
|
||||||
else:
|
else:
|
||||||
self.main_stream.disconnect()
|
self.main_stream.disconnect()
|
||||||
del self.main_stream
|
del self.main_stream
|
||||||
|
|
||||||
|
def shelve(self):
|
||||||
|
"Shelve the database to allow for persistance."
|
||||||
|
shelfname=paths.config_path(str(self.session_id)+".db")
|
||||||
|
shelf=shelve.open(paths.config_path(shelfname),'c')
|
||||||
|
for key,value in self.db.items():
|
||||||
|
shelf[key]=value
|
||||||
|
shelf.close()
|
||||||
|
|
||||||
|
def deshelve(self):
|
||||||
|
"Import a shelved database."
|
||||||
|
shelfname=paths.config_path(str(self.session_id)+".db")
|
||||||
|
shelf=shelve.open(paths.config_path(shelfname),'c')
|
||||||
|
for key,value in shelf.items():
|
||||||
|
self.db[key]=value
|
||||||
|
shelf.close()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user