mirror of
https://github.com/MCV-Software/TWBlue.git
synced 2024-11-29 22:23:12 -06:00
Store created sessions in the sessions module
This commit is contained in:
parent
0cfa89b389
commit
8cf7ca5ef2
@ -23,6 +23,7 @@ from sessionmanager import manager, sessionManager
|
|||||||
|
|
||||||
import buffersController
|
import buffersController
|
||||||
import messages
|
import messages
|
||||||
|
import sessions
|
||||||
from sessions.twitter import session as session_
|
from sessions.twitter import session as session_
|
||||||
from pubsub import pub
|
from pubsub import pub
|
||||||
import sound
|
import sound
|
||||||
@ -239,12 +240,12 @@ class Controller(object):
|
|||||||
def do_work(self):
|
def do_work(self):
|
||||||
""" Creates the buffer objects for all accounts. This does not starts the buffer streams, only creates the objects."""
|
""" Creates the buffer objects for all accounts. This does not starts the buffer streams, only creates the objects."""
|
||||||
log.debug("Creating buffers for all sessions...")
|
log.debug("Creating buffers for all sessions...")
|
||||||
for i in session_.sessions:
|
for i in sessions.sessions:
|
||||||
log.debug("Working on session %s" % (i,))
|
log.debug("Working on session %s" % (i,))
|
||||||
if session_.sessions[i].is_logged == False:
|
if sessions.sessions[i].is_logged == False:
|
||||||
self.create_ignored_session_buffer(session_.sessions[i])
|
self.create_ignored_session_buffer(sessions.sessions[i])
|
||||||
continue
|
continue
|
||||||
self.create_buffers(session_.sessions[i])
|
self.create_buffers(sessions.sessions[i])
|
||||||
|
|
||||||
# Connection checker executed each minute.
|
# Connection checker executed each minute.
|
||||||
self.checker_function = RepeatingTimer(60, self.check_connection)
|
self.checker_function = RepeatingTimer(60, self.check_connection)
|
||||||
@ -257,12 +258,12 @@ class Controller(object):
|
|||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
""" Starts all buffer objects. Loads their items."""
|
""" Starts all buffer objects. Loads their items."""
|
||||||
for i in session_.sessions:
|
for i in sessions.sessions:
|
||||||
if session_.sessions[i].is_logged == False: continue
|
if sessions.sessions[i].is_logged == False: continue
|
||||||
self.start_buffers(session_.sessions[i])
|
self.start_buffers(sessions.sessions[i])
|
||||||
self.set_buffer_positions(session_.sessions[i])
|
self.set_buffer_positions(sessions.sessions[i])
|
||||||
if config.app["app-settings"]["play_ready_sound"] == True:
|
if config.app["app-settings"]["play_ready_sound"] == True:
|
||||||
session_.sessions[session_.sessions.keys()[0]].sound.play("ready.ogg")
|
sessions.sessions[sessions.sessions.keys()[0]].sound.play("ready.ogg")
|
||||||
if config.app["app-settings"]["speak_ready_msg"] == True:
|
if config.app["app-settings"]["speak_ready_msg"] == True:
|
||||||
output.speak(_(u"Ready"))
|
output.speak(_(u"Ready"))
|
||||||
self.started = True
|
self.started = True
|
||||||
@ -276,8 +277,8 @@ class Controller(object):
|
|||||||
self.view.add_buffer(account.buffer , name=session.settings["twitter"]["user_name"])
|
self.view.add_buffer(account.buffer , name=session.settings["twitter"]["user_name"])
|
||||||
|
|
||||||
def login_account(self, session_id):
|
def login_account(self, session_id):
|
||||||
for i in session_.sessions:
|
for i in sessions.sessions:
|
||||||
if session_.sessions[i].session_id == session_id: session = session_.sessions[i]
|
if sessions.sessions[i].session_id == session_id: session = sessions.sessions[i]
|
||||||
session.login()
|
session.login()
|
||||||
session.db = dict()
|
session.db = dict()
|
||||||
self.create_buffers(session, False)
|
self.create_buffers(session, False)
|
||||||
@ -391,8 +392,8 @@ class Controller(object):
|
|||||||
i.buffer.list.select_item(session.db[str(i.name+"_pos")])
|
i.buffer.list.select_item(session.db[str(i.name+"_pos")])
|
||||||
|
|
||||||
def logout_account(self, session_id):
|
def logout_account(self, session_id):
|
||||||
for i in session_.sessions:
|
for i in sessions.sessions:
|
||||||
if session_.sessions[i].session_id == session_id: session = session_.sessions[i]
|
if sessions.sessions[i].session_id == session_id: session = sessions.sessions[i]
|
||||||
user = session.db["user_name"]
|
user = session.db["user_name"]
|
||||||
delete_buffers = []
|
delete_buffers = []
|
||||||
for i in self.buffers:
|
for i in self.buffers:
|
||||||
@ -642,12 +643,12 @@ class Controller(object):
|
|||||||
for i in self.buffers: i.save_positions()
|
for i in self.buffers: i.save_positions()
|
||||||
log.debug("Exiting...")
|
log.debug("Exiting...")
|
||||||
log.debug("Saving global configuration...")
|
log.debug("Saving global configuration...")
|
||||||
for item in session_.sessions:
|
for item in sessions.sessions:
|
||||||
if session_.sessions[item].logged == False: continue
|
if sessions.sessions[item].logged == False: continue
|
||||||
log.debug("Disconnecting streams for %s session" % (session_.sessions[item].session_id,))
|
log.debug("Disconnecting streams for %s session" % (sessions.sessions[item].session_id,))
|
||||||
session_.sessions[item].sound.cleaner.cancel()
|
sessions.sessions[item].sound.cleaner.cancel()
|
||||||
log.debug("Shelving database for " + session_.sessions[item].session_id)
|
log.debug("Shelving database for " + sessions.sessions[item].session_id)
|
||||||
session_.sessions[item].shelve()
|
sessions.sessions[item].shelve()
|
||||||
if system == "Windows":
|
if system == "Windows":
|
||||||
self.systrayIcon.RemoveIcon()
|
self.systrayIcon.RemoveIcon()
|
||||||
widgetUtils.exit_application()
|
widgetUtils.exit_application()
|
||||||
@ -1320,16 +1321,16 @@ class Controller(object):
|
|||||||
pub.sendMessage("buffer-title-changed", buffer=i)
|
pub.sendMessage("buffer-title-changed", buffer=i)
|
||||||
|
|
||||||
def set_positions(self):
|
def set_positions(self):
|
||||||
for i in session_.sessions:
|
for i in sessions.sessions:
|
||||||
self.set_buffer_positions(i)
|
self.set_buffer_positions(i)
|
||||||
|
|
||||||
def check_connection(self):
|
def check_connection(self):
|
||||||
if self.started == False:
|
if self.started == False:
|
||||||
return
|
return
|
||||||
for i in session_.sessions:
|
for i in sessions.sessions:
|
||||||
try:
|
try:
|
||||||
if session_.sessions[i].is_logged == False: continue
|
if sessions.sessions[i].is_logged == False: continue
|
||||||
session_.sessions[i].check_connection()
|
sessions.sessions[i].check_connection()
|
||||||
except TwythonError: # We shouldn't allow this function to die.
|
except TwythonError: # We shouldn't allow this function to die.
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -1399,14 +1400,14 @@ class Controller(object):
|
|||||||
sm.fill_list()
|
sm.fill_list()
|
||||||
sm.show()
|
sm.show()
|
||||||
for i in sm.new_sessions:
|
for i in sm.new_sessions:
|
||||||
self.create_buffers(session_.sessions[i])
|
self.create_buffers(sessions.sessions[i])
|
||||||
call_threaded(self.start_buffers, session_.sessions[i])
|
call_threaded(self.start_buffers, sessions.sessions[i])
|
||||||
for i in sm.removed_sessions:
|
for i in sm.removed_sessions:
|
||||||
if session_.sessions[i].logged == True:
|
if sessions.sessions[i].logged == True:
|
||||||
self.logout_account(session_.sessions[i].session_id)
|
self.logout_account(sessions.sessions[i].session_id)
|
||||||
self.destroy_buffer(session_.sessions[i].settings["twitter"]["user_name"], session_.sessions[i].settings["twitter"]["user_name"])
|
self.destroy_buffer(sessions.sessions[i].settings["twitter"]["user_name"], sessions.sessions[i].settings["twitter"]["user_name"])
|
||||||
self.accounts.remove(session_.sessions[i].settings["twitter"]["user_name"])
|
self.accounts.remove(sessions.sessions[i].settings["twitter"]["user_name"])
|
||||||
session_.sessions.pop(i)
|
sessions.sessions.pop(i)
|
||||||
|
|
||||||
def update_profile(self, *args, **kwargs):
|
def update_profile(self, *args, **kwargs):
|
||||||
r = user.profileController(self.get_best_buffer().session)
|
r = user.profileController(self.get_best_buffer().session)
|
||||||
@ -1558,5 +1559,5 @@ class Controller(object):
|
|||||||
sent_dms.put_more_items(data)
|
sent_dms.put_more_items(data)
|
||||||
|
|
||||||
def save_data_in_db(self):
|
def save_data_in_db(self):
|
||||||
for i in session_.sessions:
|
for i in sessions.sessions:
|
||||||
session_.sessions[i].shelve()
|
sessions.sessions[i].shelve()
|
||||||
|
@ -12,6 +12,7 @@ import paths
|
|||||||
import time
|
import time
|
||||||
import os
|
import os
|
||||||
import logging
|
import logging
|
||||||
|
import sessions
|
||||||
from sessions.twitter import session
|
from sessions.twitter import session
|
||||||
import manager
|
import manager
|
||||||
import config_utils
|
import config_utils
|
||||||
@ -76,12 +77,12 @@ class sessionManagerController(object):
|
|||||||
def do_ok(self):
|
def do_ok(self):
|
||||||
log.debug("Starting sessions...")
|
log.debug("Starting sessions...")
|
||||||
for i in self.sessions:
|
for i in self.sessions:
|
||||||
if session.sessions.has_key(i) == True: continue
|
if sessions.sessions.has_key(i) == True: continue
|
||||||
s = session.Session(i)
|
s = session.Session(i)
|
||||||
s.get_configuration()
|
s.get_configuration()
|
||||||
if i not in config.app["sessions"]["ignored_sessions"]:
|
if i not in config.app["sessions"]["ignored_sessions"]:
|
||||||
s.login()
|
s.login()
|
||||||
session.sessions[i] = s
|
sessions.sessions[i] = s
|
||||||
self.new_sessions[i] = s
|
self.new_sessions[i] = s
|
||||||
# self.view.destroy()
|
# self.view.destroy()
|
||||||
|
|
||||||
|
@ -1 +1,5 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
""" this package contains code related to Sessions.
|
||||||
|
In TWBlue, a session module defines everything a social network needs to be used in the program."""
|
||||||
|
# let's define a global object for storing sessions across the program.
|
||||||
|
sessions = {}
|
@ -18,8 +18,6 @@ from sessions.twitter.long_tweets import tweets, twishort
|
|||||||
from wxUI import authorisationDialog
|
from wxUI import authorisationDialog
|
||||||
from sessions import base
|
from sessions import base
|
||||||
|
|
||||||
sessions = {}
|
|
||||||
|
|
||||||
class Session(base.baseSession):
|
class Session(base.baseSession):
|
||||||
""" A session object where we will save configuration, the twitter object and a local storage for saving the items retrieved through the Twitter API methods"""
|
""" A session object where we will save configuration, the twitter object and a local storage for saving the items retrieved through the Twitter API methods"""
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user