Adding log information to events

This commit is contained in:
2015-01-18 17:19:39 -06:00
parent bd1b0b5e32
commit fd70bedc05
28 changed files with 204 additions and 41 deletions

View File

@@ -3,6 +3,8 @@
import config
import paths
import os
import logging
log = logging.getLogger("sessionmanager.manager")
import session_exceptions
manager = None
@@ -26,8 +28,10 @@ class sessionManager(object):
return False
def add_session(self, id):
log.debug("Adding a new session: %s" % (id,))
path = paths.config_path(id)
if not os.path.exists(path):
log.debug("Creating %s path" % (paths.config_path(path),))
os.mkdir(path)
config.app["sessions"]["sessions"].append(id)

View File

@@ -7,10 +7,12 @@ import paths
import output
import time
import sound
import logging
from twitter import utils
from twython import TwythonError, TwythonRateLimitError, TwythonAuthError
from config_utils import Configuration, ConfigurationResetException
from mysc.thread_utils import stream_threaded
log = logging.getLogger("sessionmanager.session")
sessions = {}
@@ -96,8 +98,10 @@ class Session(object):
file_ = "%s/session.conf" % (self.session_id,)
try:
log.debug("Creating config file %s" % (file_,))
self.settings = Configuration(paths.config_path(file_), paths.app_path("Conf.defaults"))
except:
log.exception("The session configuration has failed.")
self.settings = None
@_require_configuration
@@ -107,8 +111,10 @@ class Session(object):
if the user account isn't authorised, it needs to call self.authorise() before login."""
if self.settings["twitter"]["user_key"] != None and self.settings["twitter"]["user_secret"] != None:
log.debug("Logging in to twitter...")
self.twitter.login(self.settings["twitter"]["user_key"], self.settings["twitter"]["user_secret"])
self.logged = True
log.debug("Logged.")
else:
self.logged = False
raise Exceptions.RequireCredentialsSessionError
@@ -262,10 +268,12 @@ class Session(object):
self.get_timelines()
def get_main_stream(self):
log.debug("Starting the main stream...")
self.main_stream = twitter.buffers.stream.streamer(application.app_key, application.app_secret, self.settings["twitter"]["user_key"], self.settings["twitter"]["user_secret"], self)
stream_threaded(self.main_stream.user, self.session_id)
def get_timelines(self):
log.debug("Starting the timelines stream...")
self.timelinesStream = twitter.buffers.indibidual.timelinesStreamer(application.app_key, application.app_secret, self.settings["twitter"]["user_key"], self.settings["twitter"]["user_secret"], session=self)
ids = ""
for i in self.settings["other_buffers"]["timelines"]:
@@ -275,9 +283,11 @@ class Session(object):
def listen_stream_error(self):
if hasattr(self, "main_stream"):
log.debug("Disconnecting the main stream...")
self.main_stream.disconnect()
del self.main_stream
if hasattr(self, "timelinesStream"):
log.debug("disconnecting the timelines stream...")
self.timelinesStream.disconnect()
del self.timelinesStream

View File

@@ -4,27 +4,35 @@ import wxUI as view
import paths
import time
import os
import logging
import session
import manager
from config_utils import Configuration
import config
log = logging.getLogger("sessionmanager.sessionManager")
class sessionManagerController(object):
def __init__(self):
super(sessionManagerController, self).__init__()
log.debug("Setting up the session manager.")
manager.setup()
def fill_list(self):
sessionsList = []
log.debug("Filling the sessions list.")
self.sessions = []
for i in os.listdir(paths.config_path()):
if os.path.isdir(paths.config_path(i)) and i not in config.app["sessions"]["ignored_sessions"]:
log.debug("Adding session %s" % (i,))
strconfig = "%s/session.conf" % (paths.config_path(i))
config_test = Configuration(strconfig)
name = config_test["twitter"]["user_name"]
if name != "" and config_test["twitter"]["user_key"] != "" and config_test["twitter"]["user_secret"] != "":
sessionsList.append(name)
self.sessions.append(i)
else:
log.debug("Ignoring session %s" % (i,))
if hasattr(self, "view"): self.view.fill_list(sessionsList)
def show(self):
@@ -33,6 +41,7 @@ class sessionManagerController(object):
self.view.Destroy()
def do_ok(self):
log.debug("Starting sessions...")
for i in self.sessions:
s = session.Session(i)
s.get_configuration()
@@ -41,6 +50,7 @@ class sessionManagerController(object):
def manage_new_account(self):
location = (str(time.time())[:6])
log.debug("Creating session in the %s path" % (location,))
s = session.Session(location)
manager.manager.add_session(location)
s.get_configuration()
@@ -49,5 +59,6 @@ class sessionManagerController(object):
self.sessions.append(location)
self.view.add_new_session_to_list()
except:
log.exception("Error authorising the session")
self.view.show_unauthorised_error()
return