mirror of
https://github.com/MCV-Software/TWBlue.git
synced 2025-07-17 21:56:07 -04:00
Adding log information to events
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import argparse
|
||||
import paths
|
||||
import logging
|
||||
log = logging.getLogger("commandlineLauncher")
|
||||
|
||||
parser = argparse.ArgumentParser(description="TW Blue command line launcher")
|
||||
group = parser.add_mutually_exclusive_group()
|
||||
@@ -8,6 +10,7 @@ group.add_argument("-p", "--portable", help="Use TW Blue as a portable aplicatio
|
||||
group.add_argument("-i", "--installed", help="Use TW Blue as an installed application. Config files will be saved on the user data directory", action="store_true")
|
||||
parser.add_argument("-d", "--data-directory", action="store", dest="directory", help="Specifies the directory where TW Blue saves the data files")
|
||||
args = parser.parse_args()
|
||||
log.debug("Starting TWBlue with the following arguments: installed = %s, portable = %s and directory = %s" % (args.installed, args.portable, args.directory))
|
||||
if args.installed == True: paths.mode = "installed"
|
||||
elif args.portable == True:
|
||||
paths.mode = "portable"
|
||||
|
@@ -1,6 +1,9 @@
|
||||
# -*- coding: cp1252 -*-
|
||||
from config_utils import Configuration, ConfigurationResetException
|
||||
import paths
|
||||
import logging
|
||||
|
||||
log = logging.getLogger("config")
|
||||
|
||||
MAINFILE = "twblue.conf"
|
||||
MAINSPEC = "app-configuration.defaults"
|
||||
@@ -9,6 +12,7 @@ app = None
|
||||
|
||||
def setup ():
|
||||
global app
|
||||
log.debug("Loading global app settings...")
|
||||
try:
|
||||
app = Configuration(paths.config_path(MAINFILE), paths.app_path(MAINSPEC))
|
||||
except ConfigurationResetException:
|
||||
|
@@ -8,11 +8,13 @@ import config
|
||||
import sound
|
||||
import messages
|
||||
import languageHandler
|
||||
import logging
|
||||
from twitter import compose, utils
|
||||
from wxUI import buffers, dialogs, commonMessageDialogs
|
||||
from mysc.thread_utils import call_threaded
|
||||
from twython import TwythonError
|
||||
|
||||
log = logging.getLogger("controller.buffers")
|
||||
class bufferController(object):
|
||||
def __init__(self, parent=None, function=None, session=None, *args, **kwargs):
|
||||
super(bufferController, self).__init__()
|
||||
@@ -113,6 +115,7 @@ class bufferController(object):
|
||||
class accountPanel(bufferController):
|
||||
def __init__(self, parent, name, account):
|
||||
super(accountPanel, self).__init__(parent, None, name)
|
||||
log.debug("Initializing buffer %s, account %s" % (name, account,))
|
||||
self.buffer = buffers.accountPanel(parent, name)
|
||||
self.type = self.buffer.type
|
||||
self.compose_function = None
|
||||
@@ -126,6 +129,7 @@ class accountPanel(bufferController):
|
||||
class emptyPanel(bufferController):
|
||||
def __init__(self, parent, name, account):
|
||||
super(emptyPanel, self).__init__(parent, None, name)
|
||||
log.debug("Initializing buffer %s, account %s" % (name, account,))
|
||||
self.buffer = buffers.emptyPanel(parent, name)
|
||||
self.type = self.buffer.type
|
||||
self.compose_function = None
|
||||
@@ -139,6 +143,7 @@ class emptyPanel(bufferController):
|
||||
class baseBufferController(bufferController):
|
||||
def __init__(self, parent, function, name, sessionObject, account, bufferType=None, *args, **kwargs):
|
||||
super(baseBufferController, self).__init__(parent, function, *args, **kwargs)
|
||||
log.debug("Initializing buffer %s, account %s" % (name, account,))
|
||||
if bufferType != None:
|
||||
self.buffer = getattr(buffers, bufferType)(parent, name)
|
||||
else:
|
||||
@@ -148,6 +153,7 @@ class baseBufferController(bufferController):
|
||||
self.id = self.buffer.GetId()
|
||||
self.session = sessionObject
|
||||
self.compose_function = compose.compose_tweet
|
||||
log.debug("Compose_function: %s" % (self.compose_function,))
|
||||
self.account = account
|
||||
self.buffer.account = account
|
||||
self.bind_events()
|
||||
@@ -156,11 +162,16 @@ class baseBufferController(bufferController):
|
||||
return " ".join(self.compose_function(self.get_right_tweet(), self.session.db, self.session.settings["general"]["relative_times"])[1:-2])
|
||||
|
||||
def start_stream(self):
|
||||
log.debug("Starting stream for buffer %s, account %s and type %s" % (self.name, self.account, self.type))
|
||||
log.debug("args: %s, kwargs: %s" % (self.args, self.kwargs))
|
||||
val = self.session.call_paged(self.function, *self.args, **self.kwargs)
|
||||
number_of_items = self.session.order_buffer(self.name, val)
|
||||
log.debug("Number of items retrieved: %d" % (number_of_items,))
|
||||
self.put_items_on_list(number_of_items)
|
||||
|
||||
def put_items_on_list(self, number_of_items):
|
||||
log.debug("The list contains %d items " % (self.buffer.list.get_count(),))
|
||||
log.debug("Putting %d items on the list" % (number_of_items,))
|
||||
if self.buffer.list.get_count() == 0:
|
||||
for i in self.session.db[self.name]:
|
||||
tweet = self.compose_function(i, self.session.db, self.session.settings["general"]["relative_times"])
|
||||
@@ -175,6 +186,7 @@ class baseBufferController(bufferController):
|
||||
for i in self.session.db[self.name][0:number_of_items]:
|
||||
tweet = self.compose_function(i, self.session.db, self.session.settings["general"]["relative_times"])
|
||||
self.buffer.list.insert_item(True, *tweet)
|
||||
log.debug("Now the list contains %d items " % (self.buffer.list.get_count(),))
|
||||
|
||||
def add_new_item(self, item):
|
||||
tweet = self.compose_function(item, self.session.db, self.session.settings["general"]["relative_times"])
|
||||
@@ -184,6 +196,7 @@ class baseBufferController(bufferController):
|
||||
self.buffer.list.insert_item(True, *tweet)
|
||||
|
||||
def bind_events(self):
|
||||
log.debug("Binding events...")
|
||||
self.buffer.list.list.Bind(wx.EVT_LIST_ITEM_FOCUSED, self.onFocus)
|
||||
self.buffer.list.list.Bind(wx.EVT_CHAR_HOOK, self.get_event)
|
||||
widgetUtils.connect_event(self.buffer, widgetUtils.BUTTON_PRESSED, self.post_tweet, self.buffer.tweet)
|
||||
@@ -305,6 +318,7 @@ class baseBufferController(bufferController):
|
||||
class eventsBufferController(bufferController):
|
||||
def __init__(self, parent, name, session, account, *args, **kwargs):
|
||||
super(eventsBufferController, self).__init__(parent, *args, **kwargs)
|
||||
log.debug("Initializing buffer %s, account %s" % (name, account,))
|
||||
self.buffer = buffers.eventsPanel(parent, name)
|
||||
self.name = name
|
||||
self.account = account
|
||||
@@ -332,7 +346,9 @@ class eventsBufferController(bufferController):
|
||||
class peopleBufferController(baseBufferController):
|
||||
def __init__(self, parent, function, name, sessionObject, account, bufferType=None, *args, **kwargs):
|
||||
super(peopleBufferController, self).__init__(parent, function, name, sessionObject, account, bufferType="peoplePanel")
|
||||
log.debug("Initializing buffer %s, account %s" % (name, account,))
|
||||
self.compose_function = compose.compose_followers_list
|
||||
log.debug("Compose_function: self.compose_function" % (self.compose_function,))
|
||||
self.get_tweet = self.get_right_tweet
|
||||
|
||||
def onFocus(self, ev):
|
||||
@@ -344,11 +360,16 @@ class peopleBufferController(baseBufferController):
|
||||
def delete_item(self): pass
|
||||
|
||||
def start_stream(self):
|
||||
log.debug("Starting stream for %s buffer, %s account" % (self.name, self.account,))
|
||||
log.debug("args: %s, kwargs: %s" % (self.args, self.kwargs))
|
||||
val = self.session.get_cursored_stream(self.name, self.function, *self.args, **self.kwargs)
|
||||
# self.session.order_cursored_buffer(self.name, self.session.db[self.name])
|
||||
log.debug("Number of items retrieved: %d" % (val,))
|
||||
self.put_items_on_list(val)
|
||||
|
||||
def put_items_on_list(self, number_of_items):
|
||||
log.debug("The list contains %d items" % (self.buffer.list.get_count(),))
|
||||
log.debug("Putting %d items on the list..." % (number_of_items,))
|
||||
if self.buffer.list.get_count() == 0:
|
||||
for i in self.session.db[self.name]["items"]:
|
||||
tweet = self.compose_function(i, self.session.db, self.session.settings["general"]["relative_times"])
|
||||
@@ -363,6 +384,7 @@ class peopleBufferController(baseBufferController):
|
||||
for i in self.session.db[self.name]["items"][0:number_of_items]:
|
||||
tweet = self.compose_function(i, self.session.db)
|
||||
self.buffer.list.insert_item(True, *tweet)
|
||||
log.debug("now the list contains %d items" % (self.buffer.list.get_count(),))
|
||||
|
||||
def get_right_tweet(self):
|
||||
tweet = self.session.db[self.name]["items"][self.buffer.list.get_selected()]
|
||||
@@ -370,8 +392,12 @@ class peopleBufferController(baseBufferController):
|
||||
|
||||
class searchBufferController(baseBufferController):
|
||||
def start_stream(self):
|
||||
log.debug("Starting stream for %s buffer, %s account and %s type" % (self.name, self.account, self.type))
|
||||
log.debug("args: %s, kwargs: %s" % (self.args, self.kwargs))
|
||||
log.debug("Function: %s" % (self.function,))
|
||||
val = getattr(self.session.twitter.twitter, self.function)(*self.args, **self.kwargs)
|
||||
number_of_items = self.session.order_buffer(self.name, val["statuses"])
|
||||
log.debug("Number of items retrieved: %d" % (number_of_items,))
|
||||
self.put_items_on_list(number_of_items)
|
||||
if number_of_items > 0:
|
||||
sound.player.play("search_updated.ogg")
|
||||
@@ -380,11 +406,17 @@ class searchPeopleBufferController(searchBufferController):
|
||||
|
||||
def __init__(self, parent, function, name, sessionObject, account, bufferType="peoplePanel", *args, **kwargs):
|
||||
super(searchPeopleBufferController, self).__init__(parent, function, name, sessionObject, account, bufferType="peoplePanel", *args, **kwargs)
|
||||
log.debug("Initializing buffer %s, account %s" % (name, account,))
|
||||
self.compose_function = compose.compose_followers_list
|
||||
|
||||
log.debug("Compose_function: %s" % (self.compose_function,))
|
||||
|
||||
def start_stream(self):
|
||||
log.debug("starting stream for %s buffer, %s account and %s type" % (self.name, self.account, self.type))
|
||||
log.debug("args: %s, kwargs: %s" % (self.args, self.kwargs))
|
||||
log.debug("Function: %s" % (self.function,))
|
||||
val = getattr(self.session.twitter.twitter, self.function)(*self.args, **self.kwargs)
|
||||
number_of_items = self.session.order_buffer(self.name, val)
|
||||
log.debug("Number of items retrieved: %d" % (number_of_items,))
|
||||
self.put_items_on_list(number_of_items)
|
||||
if number_of_items > 0:
|
||||
sound.player.play("search_updated.ogg")
|
||||
|
@@ -50,6 +50,7 @@ class Controller(object):
|
||||
return buffer
|
||||
|
||||
def bind_stream_events(self):
|
||||
log.debug("Binding events for the Twitter stream API...")
|
||||
pub.subscribe(self.manage_home_timelines, "item-in-home")
|
||||
pub.subscribe(self.manage_mentions, "mention")
|
||||
pub.subscribe(self.manage_direct_messages, "direct-message")
|
||||
@@ -67,6 +68,7 @@ class Controller(object):
|
||||
widgetUtils.connect_event(self.view, widgetUtils.CLOSE_EVENT, self.exit)
|
||||
|
||||
def bind_other_events(self):
|
||||
log.debug("Binding other application events...")
|
||||
pub.subscribe(self.editing_keystroke, "editing_keystroke")
|
||||
pub.subscribe(self.manage_stream_errors, "stream-error")
|
||||
widgetUtils.connect_event(self.view, widgetUtils.MENU, self.search, menuitem=self.view.menuitem_search)
|
||||
@@ -165,6 +167,7 @@ class Controller(object):
|
||||
tl.timer.start()
|
||||
|
||||
def search(self, *args, **kwargs):
|
||||
log.debug("Creating a new search...")
|
||||
dlg = dialogs.search.searchDialog()
|
||||
if dlg.get_response() == widgetUtils.OK:
|
||||
term = dlg.get("term")
|
||||
@@ -174,6 +177,7 @@ class Controller(object):
|
||||
buffer.session.settings["other_buffers"]["tweet_searches"].append(term)
|
||||
search = buffersController.searchBufferController(self.view.nb, "search", "%s-searchterm" % (term,), buffer.session, buffer.session.db["user_name"], bufferType="searchPanel", q=term)
|
||||
else:
|
||||
log.error("A buffer for the %s search term is already created. You can't create a duplicate buffer." % (term,))
|
||||
return
|
||||
elif dlg.get("users") == True:
|
||||
search = buffersController.searchPeopleBufferController(self.view.nb, "search_users", "%s-searchUser" % (term,), buffer.session, buffer.session.db["user_name"], bufferType=None, q=term)
|
||||
@@ -230,8 +234,11 @@ class Controller(object):
|
||||
buffer.destroy_status()
|
||||
|
||||
def exit(self, *args, **kwargs):
|
||||
log.debug("Exiting...")
|
||||
for item in session_.sessions:
|
||||
log.debug("Saving config for %s session" % (session_.sessions[item].session_id,))
|
||||
session_.sessions[item].settings.write()
|
||||
log.debug("Disconnecting streams for %s session" % (session_.sessions[item].session_id,))
|
||||
session_.sessions[item].main_stream.disconnect()
|
||||
session_.sessions[item].timelinesStream.disconnect()
|
||||
sound.player.cleaner.cancel()
|
||||
@@ -404,9 +411,8 @@ class Controller(object):
|
||||
print "i've pressed"
|
||||
|
||||
def start_buffers(self, session):
|
||||
log.debug("starting buffers... Session %s" % (session,))
|
||||
log.debug("starting buffers... Session %s" % (session.session_id,))
|
||||
for i in self.buffers:
|
||||
log.debug("Starting %s for %s" % (i.name, session))
|
||||
if i.session == session and i.needs_init == True:
|
||||
i.start_stream()
|
||||
log.debug("Starting the streaming endpoint")
|
||||
|
@@ -28,7 +28,9 @@ import config
|
||||
from pubsub import pub
|
||||
from mysc.thread_utils import call_threaded
|
||||
import sound_lib
|
||||
import logging
|
||||
|
||||
log = logging.getLogger("extra.AudioUploader.audioUploader")
|
||||
class audioUploader(object):
|
||||
def __init__(self, configFile, completed_callback):
|
||||
self.config = configFile
|
||||
@@ -45,6 +47,7 @@ class audioUploader(object):
|
||||
widgetUtils.connect_event(self.dialog.discard, widgetUtils.BUTTON_PRESSED, self.on_discard)
|
||||
if self.dialog.get_response() == widgetUtils.OK:
|
||||
self.postprocess()
|
||||
log.debug("Uploading file %s to %s..." % (self.file, self.dialog.get("services")))
|
||||
self.uploaderDialog = wx_transfer_dialogs.UploadDialog(self.file)
|
||||
output.speak(_(u"Attaching..."))
|
||||
if self.dialog.get("services") == "Dropbox":
|
||||
|
@@ -4,11 +4,13 @@ import time
|
||||
import os
|
||||
import exceptions
|
||||
import dropbox
|
||||
import logging
|
||||
from utils import *
|
||||
from dropbox.rest import ErrorResponse
|
||||
from StringIO import StringIO
|
||||
from pubsub import pub
|
||||
|
||||
log = logging.getLogger("extra.AudioUploader.dropbox_transfer")
|
||||
class UnauthorisedError(exceptions.Exception):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(UnauthorisedError, self).__init__(*args, **kwargs)
|
||||
@@ -38,25 +40,31 @@ class newChunkedUploader(dropbox.client.ChunkedUploader):
|
||||
|
||||
class dropboxLogin(object):
|
||||
def __init__(self, config):
|
||||
log.debug("Trying to login in Dropbox...")
|
||||
self.logged = False
|
||||
self.app_key = "c8ikm0gexqvovol"
|
||||
self.app_secret = "gvvi6fzfecooast"
|
||||
self.config = config
|
||||
|
||||
def get_url(self):
|
||||
log.debug("Getting autorisation URL...")
|
||||
self.flow = dropbox.client.DropboxOAuth2FlowNoRedirect(self.app_key, self.app_secret)
|
||||
return self.flow.start()
|
||||
|
||||
def authorise(self, code):
|
||||
log.debug("Authorising TWBlue in Dropbox...")
|
||||
access_token, user_id = self.flow.finish(code)
|
||||
log.debug("Saving tokens...")
|
||||
config["services"]["dropbox_token"] = access_token
|
||||
self.logged = True
|
||||
|
||||
class dropboxUploader(object):
|
||||
def __init__(self, config, filename, completed_callback, short_url=False):
|
||||
if config["services"]["dropbox_token"] != "":
|
||||
log.debug("logging in Dropbox...")
|
||||
self.client = dropbox.client.DropboxClient(config["services"]["dropbox_token"])
|
||||
else:
|
||||
log.error("Dropbox is not authorised for this session.")
|
||||
raise UnauthorisedError("You need authorise TWBlue")
|
||||
self.filename = filename
|
||||
self.short_url = short_url
|
||||
@@ -68,6 +76,7 @@ class dropboxUploader(object):
|
||||
self.background_thread = None
|
||||
self.current = 0
|
||||
self.transfer_rate = 0
|
||||
log.debug("File Size: %d " % (self.file_size,))
|
||||
|
||||
def elapsed_time(self):
|
||||
if not self.start_time:
|
||||
@@ -75,6 +84,7 @@ class dropboxUploader(object):
|
||||
return time.time() - self.start_time
|
||||
|
||||
def perform_transfer(self):
|
||||
log.debug("Starting transfer...")
|
||||
self.start_time = time.time()
|
||||
while self.uploader.offset < self.file_size:
|
||||
self.uploader.upload_chunked(self.file_size/100)
|
||||
@@ -100,6 +110,7 @@ class dropboxUploader(object):
|
||||
self.background_thread.start()
|
||||
|
||||
def transfer_completed(self):
|
||||
log.debug("Transfer completed")
|
||||
self.uploader.finish(os.path.basename(self.filename))
|
||||
if callable(self.completed_callback):
|
||||
self.completed_callback()
|
||||
|
@@ -4,14 +4,17 @@ import sys
|
||||
import threading
|
||||
import time
|
||||
import json
|
||||
import logging
|
||||
from utils import *
|
||||
from pubsub import pub
|
||||
|
||||
log = logging.getLogger("extra.AudioUploader.transfer")
|
||||
class Transfer(object):
|
||||
|
||||
def __init__(self, url=None, filename=None, follow_location=True, completed_callback=None, verbose=False, *args, **kwargs):
|
||||
self.url = url
|
||||
self.filename = filename
|
||||
log.debug("Uploading audio to %s, filename %s" % (url, filename))
|
||||
self.curl = pycurl.Curl()
|
||||
self.start_time = None
|
||||
self.completed_callback = completed_callback
|
||||
@@ -51,9 +54,11 @@ class Transfer(object):
|
||||
pub.sendMessage("uploading", data=progress)
|
||||
|
||||
def perform_transfer(self):
|
||||
log.debug("starting upload...")
|
||||
self.start_time = time.time()
|
||||
self.curl.perform()
|
||||
self.curl.close()
|
||||
log.debug("Upload finished.")
|
||||
self.complete_transfer()
|
||||
|
||||
def perform_threaded(self):
|
||||
|
@@ -19,9 +19,12 @@
|
||||
import wx
|
||||
import widgetUtils
|
||||
import output
|
||||
import logging
|
||||
log = logging.getLogger("extra.AudioUploader.wx_UI")
|
||||
|
||||
class audioDialog(widgetUtils.BaseDialog):
|
||||
def __init__(self, services):
|
||||
log.debug("creating audio dialog.")
|
||||
super(audioDialog, self).__init__(None, -1, _(u"Attach audio"))
|
||||
panel = wx.Panel(self)
|
||||
sizer = wx.BoxSizer(wx.VERTICAL)
|
||||
@@ -50,10 +53,12 @@ class audioDialog(widgetUtils.BaseDialog):
|
||||
sizer.Add(self.attach)
|
||||
|
||||
def enable_control(self, control):
|
||||
log.debug("Enabling control %s" % (control,))
|
||||
if hasattr(self, control):
|
||||
getattr(self, control).Enable()
|
||||
|
||||
def disable_control(self, control):
|
||||
log.debug("Disabling control %s" % (control,))
|
||||
if hasattr(self, control):
|
||||
getattr(self, control).Disable()
|
||||
|
||||
|
@@ -3,20 +3,29 @@ import widgetUtils
|
||||
import config
|
||||
import os
|
||||
import paths
|
||||
import logging
|
||||
log = logging.getLogger("extra.SoundsTutorial.soundsTutorial")
|
||||
import sound
|
||||
import wx_ui
|
||||
import soundsTutorial_constants
|
||||
|
||||
class soundsTutorial(object):
|
||||
def __init__(self):
|
||||
log.debug("Creating sounds tutorial object...")
|
||||
super(soundsTutorial, self).__init__()
|
||||
self.actions = []
|
||||
log.debug("Loading actions for sounds tutorial...")
|
||||
[self.actions.append(i[1]) for i in soundsTutorial_constants.actions]
|
||||
self.files = []
|
||||
log.debug("Searching sound files...")
|
||||
[self.files.append(i[0]) for i in soundsTutorial_constants.actions]
|
||||
log.debug("Creating dialog...")
|
||||
self.dialog = wx_ui.soundsTutorialDialog(self.actions)
|
||||
widgetUtils.connect_event(self.dialog.play, widgetUtils.BUTTON_PRESSED, self.on_play)
|
||||
self.dialog.get_response()
|
||||
|
||||
def on_play(self, *args, **kwargs):
|
||||
sound.player.play(self.files[self.dialog.items.GetSelection()]+".ogg")
|
||||
try:
|
||||
sound.player.play(self.files[self.dialog.items.GetSelection()]+".ogg")
|
||||
except:
|
||||
log.exception("Error playing the %s sound" % (self.files[self.dialog.items.GetSelection()],))
|
@@ -1,4 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import logging
|
||||
log = logging.getLogger("extra.SpellChecker.spellChecker")
|
||||
import wx_ui
|
||||
import widgetUtils
|
||||
import output
|
||||
@@ -10,15 +12,22 @@ from enchant.errors import DictNotFoundError
|
||||
class spellChecker(object):
|
||||
def __init__(self, text, dictionary):
|
||||
super(spellChecker, self).__init__()
|
||||
log.debug("Creating the SpellChecker object. Dictionary: %s" % (dictionary,))
|
||||
self.active = True
|
||||
try:
|
||||
if config.app["app-settings"]["language"] == "system": self.checker = SpellChecker()
|
||||
else: self.checker = SpellChecker(languageHandler.getLanguage())
|
||||
if config.app["app-settings"]["language"] == "system":
|
||||
log.debug("Using the system language")
|
||||
self.checker = SpellChecker()
|
||||
else:
|
||||
log.debug("Using language: %s" % (languageHandler.getLanguage(),))
|
||||
self.checker = SpellChecker(languageHandler.getLanguage())
|
||||
self.checker.set_text(text)
|
||||
except DictNotFoundError:
|
||||
log.exception("Dictionary for language %s not found." % (dictionary,))
|
||||
wx_ui.dict_not_found_error()
|
||||
self.active = False
|
||||
if self.active == True:
|
||||
log.debug("Creating dialog...")
|
||||
self.dialog = wx_ui.spellCheckerDialog()
|
||||
widgetUtils.connect_event(self.dialog.ignore, widgetUtils.BUTTON_PRESSED, self.ignore)
|
||||
widgetUtils.connect_event(self.dialog.ignoreAll, widgetUtils.BUTTON_PRESSED, self.ignoreAll)
|
||||
@@ -37,6 +46,7 @@ class spellChecker(object):
|
||||
output.speak(textToSay)
|
||||
self.dialog.set_word_and_suggestions(word=self.checker.word, context=context, suggestions=self.checker.suggest())
|
||||
except StopIteration:
|
||||
log.debug("Process finished.")
|
||||
wx_ui.finished()
|
||||
self.dialog.Destroy()
|
||||
# except AttributeError:
|
||||
|
@@ -6,6 +6,9 @@ import locale
|
||||
import gettext
|
||||
import paths
|
||||
import platform
|
||||
import logging
|
||||
|
||||
log = logging.getLogger("languageHandler")
|
||||
|
||||
# A fix for the mac locales
|
||||
#if platform.system() == 'Darwin':
|
||||
@@ -116,6 +119,7 @@ def makePgettext(translations):
|
||||
return pgettext
|
||||
|
||||
def setLanguage(lang):
|
||||
log.debug("Setting language for: %s" % (lang,))
|
||||
system = platform.system()
|
||||
global curLang
|
||||
try:
|
||||
@@ -161,6 +165,7 @@ def setLanguage(lang):
|
||||
trans=gettext.translation("twblue",fallback=True)
|
||||
curLang="en"
|
||||
trans.install(unicode=True)
|
||||
log.debug("Current language: %s" % (curLang,))
|
||||
# Install our pgettext function.
|
||||
# __builtin__.__dict__["pgettext"] = makePgettext(trans)
|
||||
|
||||
|
@@ -15,6 +15,8 @@ requests_log = logging.getLogger("requests")
|
||||
requests_log.setLevel(logging.WARNING)
|
||||
oauthlib_log = logging.getLogger("oauthlib")
|
||||
oauthlib_log.setLevel(logging.WARNING)
|
||||
requests_oauthlib_log = logging.getLogger("requests_oauthlib")
|
||||
requests_oauthlib_log.setLevel(logging.WARNING)
|
||||
suds_log = logging.getLogger("suds")
|
||||
suds_log.setLevel(logging.WARNING)
|
||||
server_log = logging.getLogger("BaseHTTPServer")
|
||||
@@ -26,12 +28,12 @@ logger.setLevel(logging.DEBUG)
|
||||
|
||||
#handlers
|
||||
|
||||
app_handler = RotatingFileHandler(paths.logs_path(APP_LOG_FILE), maxBytes=1000000)
|
||||
app_handler = RotatingFileHandler(paths.logs_path(APP_LOG_FILE), maxBytes=1000000, mode="w")
|
||||
app_handler.setFormatter(formatter)
|
||||
app_handler.setLevel(logging.DEBUG)
|
||||
logger.addHandler(app_handler)
|
||||
|
||||
error_handler = logging.FileHandler(paths.logs_path(ERROR_LOG_FILE))
|
||||
error_handler = logging.FileHandler(paths.logs_path(ERROR_LOG_FILE), mode="w")
|
||||
error_handler.setFormatter(formatter)
|
||||
error_handler.setLevel(logging.ERROR)
|
||||
logger.addHandler(error_handler)
|
||||
|
@@ -1,12 +1,15 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import wx
|
||||
import platform
|
||||
import logging
|
||||
log = logging.getLogger("multiplatform_widgets.widgets")
|
||||
|
||||
class list(object):
|
||||
def __init__(self, parent, *columns, **listArguments):
|
||||
self.system = platform.system()
|
||||
self.columns = columns
|
||||
self.listArguments = listArguments
|
||||
log.debug("Creating list: Columns: %s, arguments: %s" % (self.columns, self.listArguments))
|
||||
self.create_list(parent)
|
||||
# self.set_size()
|
||||
|
||||
|
@@ -1,12 +1,17 @@
|
||||
import os
|
||||
import languageHandler
|
||||
import logging
|
||||
log = logging.getLogger("mysc.localization")
|
||||
|
||||
def get(rootFolder):
|
||||
log.debug("Getting documentation folder. RootFolder: %s" % (rootFolder,))
|
||||
defaultLocale = languageHandler.curLang
|
||||
if len(defaultLocale) > 2:
|
||||
defaultLocale = defaultLocale[:2]
|
||||
log.debug("Locale: %s" % (defaultLocale,))
|
||||
if os.path.exists(rootFolder+"/"+defaultLocale):
|
||||
return defaultLocale
|
||||
else:
|
||||
log.debug("The folder does not exist, using the English folder...")
|
||||
return "en"
|
||||
|
||||
|
@@ -1,4 +1,6 @@
|
||||
import threading
|
||||
import logging
|
||||
log = logging.getLogger("mysc.repeating_timer")
|
||||
|
||||
class RepeatingTimer(threading.Thread):
|
||||
"""Call a function after a specified number of seconds, it will then repeat again after the specified number of seconds
|
||||
@@ -20,6 +22,7 @@ class RepeatingTimer(threading.Thread):
|
||||
|
||||
def cancel(self):
|
||||
"""Stop the timer if it hasn't finished yet"""
|
||||
log.debug("Stopping repeater for %s" % (self.function,))
|
||||
self.finished.set()
|
||||
stop = cancel
|
||||
|
||||
@@ -27,8 +30,7 @@ class RepeatingTimer(threading.Thread):
|
||||
while not self.finished.is_set():
|
||||
self.finished.wait(self.interval)
|
||||
if not self.finished.is_set(): #In case someone has canceled while waiting
|
||||
# try:
|
||||
self.function(*self.args, **self.kwargs)
|
||||
# except:
|
||||
# pass
|
||||
# logging.exception("Execution failed. Function: %r args: %r and kwargs: %r" % (self.function, self.args, self.kwargs))
|
||||
try:
|
||||
self.function(*self.args, **self.kwargs)
|
||||
except:
|
||||
log.exception("Execution failed. Function: %r args: %r and kwargs: %r" % (self.function, self.args, self.kwargs))
|
||||
|
@@ -12,7 +12,8 @@ def call_threaded(func, *args, **kwargs):
|
||||
func(*a, **k)
|
||||
except TwythonRateLimitError:
|
||||
pass
|
||||
# except:
|
||||
except:
|
||||
logging.exception("Thread %d with function %r, args of %r, and kwargs of %r failed to run." % (threading.current_thread().ident, func, a, k))
|
||||
# pass
|
||||
thread = threading.Thread(target=new_func, args=args, kwargs=kwargs)
|
||||
thread.daemon = True
|
||||
@@ -21,7 +22,6 @@ def call_threaded(func, *args, **kwargs):
|
||||
|
||||
def stream_threaded(func, *args, **kwargs):
|
||||
def new_func(*a, **k):
|
||||
# global session
|
||||
try:
|
||||
func(**k)
|
||||
except:
|
||||
|
@@ -2,6 +2,7 @@
|
||||
import platform
|
||||
import os
|
||||
import sys
|
||||
import logging
|
||||
from platform_utils import paths as paths_
|
||||
|
||||
from functools import wraps
|
||||
@@ -9,6 +10,8 @@ from functools import wraps
|
||||
mode = None
|
||||
directory = None
|
||||
|
||||
log = logging.getLogger("paths")
|
||||
|
||||
def merge_paths(func):
|
||||
@wraps(func)
|
||||
def merge_paths_wrapper(*a):
|
||||
@@ -28,6 +31,7 @@ def config_path():
|
||||
elif mode == "installed":
|
||||
path = data_path("config")
|
||||
if not os.path.exists(path):
|
||||
log.debug("%s path does not exist, creating..." % (path,))
|
||||
os.mkdir(path)
|
||||
return path
|
||||
|
||||
@@ -40,6 +44,7 @@ def logs_path():
|
||||
elif mode == "installed":
|
||||
path = data_path("logs")
|
||||
if not os.path.exists(path):
|
||||
log.debug("%s path does not exist, creating..." % (path,))
|
||||
os.mkdir(path)
|
||||
return path
|
||||
|
||||
|
@@ -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)
|
||||
|
||||
|
@@ -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
|
||||
|
||||
|
@@ -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
|
@@ -19,8 +19,10 @@ player = URLPlayer = None
|
||||
def setup():
|
||||
global player, URLPlayer
|
||||
if not player:
|
||||
log.debug("Creating sound player...")
|
||||
player = soundSystem()
|
||||
if not URLPlayer:
|
||||
log.debug("creating stream URL player...")
|
||||
URLPlayer = URLStream()
|
||||
|
||||
def recode_audio(filename, quality=4.5):
|
||||
@@ -44,9 +46,11 @@ class soundSystem(object):
|
||||
self.path = paths.sound_path(config.app["app-settings"]["current_soundpack"])
|
||||
self.soundpack_OK = True
|
||||
elif os.path.exists(paths.sound_path("default")):
|
||||
log.error("The soundpack does not exist, using default...")
|
||||
self.path = paths.sound_path("default")
|
||||
self.soundpack_OK = True
|
||||
else:
|
||||
log.error("Path for the current soundpack does not exist and the default soundpack is deleted, TWBlue will not play sounds.")
|
||||
self.soundpack_OK = False
|
||||
|
||||
def __init__(self):
|
||||
@@ -56,9 +60,11 @@ class soundSystem(object):
|
||||
self.input = sound_lib.input.Input()
|
||||
# Try to use the selected device from the configuration. It can fail if the machine does not has a mic.
|
||||
try:
|
||||
log.debug("Setting input and output devices...")
|
||||
self.output.set_device(self.output.find_device_by_name(config.app["app-settings"]["output_device"]))
|
||||
self.input.set_device(self.input.find_device_by_name(config.app["app-settings"]["input_device"]))
|
||||
except:
|
||||
log.error("Error in input or output devices, using defaults...")
|
||||
config.app["app-settings"]["output_device"] = "Default"
|
||||
config.app["app-settings"]["input_device"] = "Default"
|
||||
|
||||
|
@@ -13,6 +13,10 @@ class timelinesStreamer(TwythonStreamer):
|
||||
def on_error(self, status_code, data):
|
||||
log.debug("%s: %s" % (status_code, data))
|
||||
|
||||
def on_timeout(self, *args, **kwargs):
|
||||
log.debug("Twitter timeout Error")
|
||||
pub.sendMessage("stream-error")
|
||||
|
||||
def check_tls(self, data):
|
||||
for i in self.session.settings["other_buffers"]["timelines"]:
|
||||
if data["user"]["screen_name"] == i:
|
||||
|
@@ -12,6 +12,10 @@ class streamer(TwythonStreamer):
|
||||
self.muted_users = self.session.db["muted_users"]
|
||||
# self.blocked_users = []
|
||||
|
||||
def on_timeout(self, *args, **kwargs):
|
||||
log.debug("Twitter timeout Error")
|
||||
pub.sendMessage("stream-error")
|
||||
|
||||
def on_error(self, status_code, data):
|
||||
log.debug("Error %s: %s" % (status_code, data))
|
||||
|
||||
|
@@ -97,5 +97,7 @@ def is_allowed(tweet):
|
||||
if tweet.has_key("retweeted_status"): tweet = tweet["retweeted_status"]
|
||||
source = re.sub(r"(?s)<.*?>", "", tweet["source"])
|
||||
for i in config.main["twitter"]["ignored_clients"]:
|
||||
if i.lower() == source.lower(): allowed = False
|
||||
if i.lower() == source.lower():
|
||||
allowed = False
|
||||
log.exception("Tuit not allowed: %s" % (tweet["text"],))
|
||||
return allowed
|
Reference in New Issue
Block a user