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

@@ -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":

View File

@@ -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()

View File

@@ -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):

View File

@@ -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()

View File

@@ -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()],))

View File

@@ -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: