Restores buffer positions at startup using cached database

This commit is contained in:
Manuel Cortez 2015-08-25 13:37:31 -05:00
parent bd4aa89c2b
commit 4f0e6d758b
2 changed files with 14 additions and 4 deletions

View File

@ -142,6 +142,13 @@ class bufferController(object):
call_threaded(self.session.api_call, call_name="update_status_with_media", status=text, media=tweet.image)
if hasattr(tweet.message, "destroy"): tweet.message.destroy()
def save_positions(self):
try:
self.session.db[self.name+"_pos"]=self.buffer.list.get_selected()
except AttributeError:
pass
class accountPanel(bufferController):
def __init__(self, parent, name, account, account_id):
super(accountPanel, self).__init__(parent, None, name)
@ -520,7 +527,6 @@ class baseBufferController(bufferController):
self.session.sound.play("audio.ogg")
if utils.is_geocoded(tweet):
self.session.sound.play("geo.ogg")
self.session.db[self.name+"_pos"]=self.buffer.list.get_selected()
# @_tweets_exist
def audio(self, url='', *args, **kwargs):

View File

@ -235,7 +235,6 @@ class Controller(object):
self.create_ignored_session_buffer(session_.sessions[i])
continue
self.create_buffers(session_.sessions[i])
self.set_buffer_positions(session_.sessions[i])
# Connection checker executed each minute.
self.checker_function = RepeatingTimer(60, self.check_connection)
@ -246,6 +245,7 @@ class Controller(object):
for i in session_.sessions:
if session_.sessions[i].is_logged == False: continue
self.start_buffers(session_.sessions[i])
self.set_buffer_positions(session_.sessions[i])
if config.app["app-settings"]["play_ready_sound"] == True:
session_.sessions[session_.sessions.keys()[0]].sound.play("ready.ogg")
if config.app["app-settings"]["speak_ready_msg"] == True:
@ -368,7 +368,7 @@ class Controller(object):
def set_buffer_positions(self,session):
"Sets positions for buffers if values exist in the database."
for i in self.buffers:
if i.name+"_pos" in session.db and hasattr(i.buffer,'list'):
if i.account == session.db["user_name"] and session.db.has_key(i.name+"_pos") and hasattr(i.buffer,'list'):
i.buffer.list.select_item(session.db[str(i.name+"_pos")])
def logout_account(self, session_id):
@ -549,6 +549,7 @@ class Controller(object):
self.exit_()
def exit_(self, *args, **kwargs):
for i in self.buffers: i.save_positions()
log.debug("Exiting...")
log.debug("Saving global configuration...")
config.app.write()
@ -943,7 +944,6 @@ class Controller(object):
return
if buff == self.get_last_buffer(buffer.account) or buff+1 == self.view.get_buffer_count():
self.view.change_buffer(self.get_first_buffer(buffer.account))
print "Regresando"
else:
self.view.change_buffer(buff+1)
while self.get_current_buffer().invisible == False: self.skip_buffer(True)
@ -1196,6 +1196,10 @@ class Controller(object):
log.debug("Starting the streaming endpoint")
session.start_streaming()
def set_positions(self):
for i in session_.sessions:
self.set_buffer_positions(i)
def manage_stream_errors(self, session):
log.debug(" Restarting %s session streams. It will be destroyed" % (session,))
s = session_.sessions[session]