From e00e3978a660d399c5fe23cb4a1fd5da75fd4eb4 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Mon, 28 Sep 2009 17:59:10 -0500 Subject: [PATCH] Switching back to module level loggers --- src/browser_emu.py | 12 ++++++------ src/channel_manager.py | 9 ++++++--- src/connection.py | 11 +++++++---- src/connection_manager.py | 7 +++++-- src/gtk_toolbox.py | 5 ++++- src/gv_backend.py | 41 +++++++++++++++++++---------------------- src/handle.py | 5 ++++- src/simple_presence.py | 5 ++++- 8 files changed, 55 insertions(+), 40 deletions(-) diff --git a/src/browser_emu.py b/src/browser_emu.py index 88a0b62..32ffbca 100644 --- a/src/browser_emu.py +++ b/src/browser_emu.py @@ -32,6 +32,7 @@ import logging import socket +_moduleLogger = logging.getLogger("browser_emu") socket.setdefaulttimeout(10) @@ -100,7 +101,7 @@ class MozillaEmulator(object): @return: The raw HTML page data """ - logging.warning("Performing download of %s" % url) + _moduleLogger.warning("Performing download of %s" % url) if extraheaders is None: extraheaders = {} @@ -113,9 +114,9 @@ class MozillaEmulator(object): req, u = self.build_opener(url, postdata, extraheaders, forbid_redirect) openerdirector = u.open(req) if self.debug: - print req.get_method(), url - print openerdirector.code, openerdirector.msg - print openerdirector.headers + _moduleLogger.info("%r - %r" % (req.get_method(), url)) + _moduleLogger.info("%r - %r" % (openerdirector.code, openerdirector.msg)) + _moduleLogger.info("%r" % (openerdirector.headers)) self.cookies.extract_cookies(openerdirector, req) if only_head: return openerdirector @@ -127,8 +128,7 @@ class MozillaEmulator(object): raise # Retry :-) - if self.debug: - print "MozillaEmulator: urllib2.URLError, retryting ", cnt + _moduleLogger.info("MozillaEmulator: urllib2.URLError, retryting %d" % cnt) def _read(self, openerdirector, trycount): chunks = [] diff --git a/src/channel_manager.py b/src/channel_manager.py index ad6faed..90fdd99 100644 --- a/src/channel_manager.py +++ b/src/channel_manager.py @@ -6,6 +6,9 @@ import telepathy import channel +_moduleLogger = logging.getLogger("channel_manager") + + class ChannelManager(object): def __init__(self, connection): @@ -31,7 +34,7 @@ class ChannelManager(object): elif handle.get_type() == telepathy.HANDLE_TYPE_CONTACT: chan = channel.contact_list.creat_contact_list_channel(self._connRef(), handle) else: - logging.warn("Unknown channel type %r" % handle.get_type()) + _moduleLogger.warn("Unknown channel type %r" % handle.get_type()) self._listChannels[handle] = chan self._connRef().add_channel(chan, handle, suppress_handler) return chan @@ -40,7 +43,7 @@ class ChannelManager(object): if handle in self._textChannels: chan = self._textChannels[handle] else: - logging.debug("Requesting new text channel") + _moduleLogger.debug("Requesting new text channel") contact = handle.contact if conversation is None: @@ -55,7 +58,7 @@ class ChannelManager(object): if handle in self._callChannels: chan = self._callChannels[handle] else: - logging.debug("Requesting new call channel") + _moduleLogger.debug("Requesting new call channel") contact = handle.contact if conversation is None: diff --git a/src/connection.py b/src/connection.py index 3fe60b1..304491d 100644 --- a/src/connection.py +++ b/src/connection.py @@ -10,6 +10,9 @@ import channel_manager import simple_presence +_moduleLogger = logging.getLogger("connection") + + class TheOneRingConnection(telepathy.server.Connection, simple_presence.SimplePresenceMixin): MANDATORY_PARAMETERS = { @@ -45,9 +48,9 @@ class TheOneRingConnection(telepathy.server.Connection, simple_presence.SimplePr self.set_self_handle(handle.create_handle(self, 'connection')) - logging.info("Connection to the account %s created" % account) + _moduleLogger.info("Connection to the account %s created" % account) except Exception, e: - logging.exception("Failed to create Connection") + _moduleLogger.exception("Failed to create Connection") raise @property @@ -98,9 +101,9 @@ class TheOneRingConnection(telepathy.server.Connection, simple_presence.SimplePr """ try: self._backend.logout() - logging.info("Disconnected") + _moduleLogger.info("Disconnected") except Exception: - logging.exception("Disconnecting Failed") + _moduleLogger.exception("Disconnecting Failed") self.StatusChanged( telepathy.CONNECTION_STATUS_DISCONNECTED, telepathy.CONNECTION_STATUS_REASON_REQUESTED diff --git a/src/connection_manager.py b/src/connection_manager.py index 68e9be6..9f9dd88 100644 --- a/src/connection_manager.py +++ b/src/connection_manager.py @@ -7,6 +7,9 @@ import constants import connection +_moduleLogger = logging.getLogger("connection_manager") + + class TheOneRingConnectionManager(telepathy.server.ConnectionManager): def __init__(self, shutdown_func=None): @@ -14,7 +17,7 @@ class TheOneRingConnectionManager(telepathy.server.ConnectionManager): self._protos[constants._telepathy_protocol_name_] = connection.TheOneRingConnection self._on_shutdown = shutdown_func - logging.info("Connection manager created") + _moduleLogger.info("Connection manager created") def GetParameters(self, proto): """ @@ -67,7 +70,7 @@ class TheOneRingConnectionManager(telepathy.server.ConnectionManager): """ for connection in self._connections: connection.Disconnect() - logging.info("Connection manager quitting") + _moduleLogger.info("Connection manager quitting") def _shutdown(self): if ( diff --git a/src/gtk_toolbox.py b/src/gtk_toolbox.py index da9accc..a74dea6 100644 --- a/src/gtk_toolbox.py +++ b/src/gtk_toolbox.py @@ -12,6 +12,9 @@ import threading import Queue +_moduleLogger = logging.getLogger("gtk_toolbox") + + @contextlib.contextmanager def flock(path, timeout=-1): WAIT_FOREVER = -1 @@ -137,7 +140,7 @@ def comap(function, target): mappedItem = function(*item) target.send(mappedItem) except Exception, e: - logging.exception("Forwarding exception!") + _moduleLogger.exception("Forwarding exception!") target.throw(e.__class__, str(e)) diff --git a/src/gv_backend.py b/src/gv_backend.py index 9af81cf..4d6e19c 100644 --- a/src/gv_backend.py +++ b/src/gv_backend.py @@ -46,6 +46,7 @@ except ImportError: simplejson = None +_moduleLogger = logging.getLogger("gv_backend") _TRUE_REGEX = re.compile("true") _FALSE_REGEX = re.compile("false") @@ -97,10 +98,6 @@ def itergroup(iterator, count, padValue = None): return itertools.izip(*nIterators) -class NetworkError(RuntimeError): - pass - - class GVDialer(object): """ This class encapsulates all of the knowledge necessary to interact with the GoogleVoice servers @@ -137,7 +134,7 @@ class GVDialer(object): try: self._grab_account_info() except Exception, e: - logging.exception(str(e)) + _moduleLogger.exception(str(e)) return False self._browser.cookies.save() @@ -166,8 +163,8 @@ class GVDialer(object): try: loginSuccessOrFailurePage = self._browser.download(self._loginURL, loginPostData) except urllib2.URLError, e: - logging.exception(str(e)) - raise NetworkError("%s is not accesible" % self._loginURL) + _moduleLogger.exception(str(e)) + raise RuntimeError("%s is not accesible" % self._loginURL) return self.is_authed() @@ -197,8 +194,8 @@ class GVDialer(object): } callSuccessPage = self._browser.download(self._clicktocallURL, clickToCallData, None, otherData) except urllib2.URLError, e: - logging.exception(str(e)) - raise NetworkError("%s is not accesible" % self._clicktocallURL) + _moduleLogger.exception(str(e)) + raise RuntimeError("%s is not accesible" % self._clicktocallURL) if self._gvDialingStrRe.search(callSuccessPage) is None: raise RuntimeError("Google Voice returned an error") @@ -222,8 +219,8 @@ class GVDialer(object): } smsSuccessPage = self._browser.download(self._sendSmsURL, smsData, None, otherData) except urllib2.URLError, e: - logging.exception(str(e)) - raise NetworkError("%s is not accesible" % self._sendSmsURL) + _moduleLogger.exception(str(e)) + raise RuntimeError("%s is not accesible" % self._sendSmsURL) return True @@ -343,8 +340,8 @@ class GVDialer(object): try: contactsPage = self._browser.download(contactsPageUrl) except urllib2.URLError, e: - logging.exception(str(e)) - raise NetworkError("%s is not accesible" % contactsPageUrl) + _moduleLogger.exception(str(e)) + raise RuntimeError("%s is not accesible" % contactsPageUrl) for contact_match in self._contactsRe.finditer(contactsPage): contactId = contact_match.group(1) contactName = saxutils.unescape(contact_match.group(2)) @@ -370,8 +367,8 @@ class GVDialer(object): try: detailPage = self._browser.download(self._contactDetailURL + '/' + contactId) except urllib2.URLError, e: - logging.exception(str(e)) - raise NetworkError("%s is not accesible" % self._contactDetailURL) + _moduleLogger.exception(str(e)) + raise RuntimeError("%s is not accesible" % self._contactDetailURL) for detail_match in self._contactDetailPhoneRe.finditer(detailPage): phoneNumber = detail_match.group(1) @@ -385,8 +382,8 @@ class GVDialer(object): try: voicemailPage = self._browser.download(self._voicemailURL) except urllib2.URLError, e: - logging.exception(str(e)) - raise NetworkError("%s is not accesible" % self._voicemailURL) + _moduleLogger.exception(str(e)) + raise RuntimeError("%s is not accesible" % self._voicemailURL) voicemailHtml = self._grab_html(voicemailPage) parsedVoicemail = self._parse_voicemail(voicemailHtml) decoratedVoicemails = self._decorate_voicemail(parsedVoicemail) @@ -394,8 +391,8 @@ class GVDialer(object): try: smsPage = self._browser.download(self._smsURL) except urllib2.URLError, e: - logging.exception(str(e)) - raise NetworkError("%s is not accesible" % self._smsURL) + _moduleLogger.exception(str(e)) + raise RuntimeError("%s is not accesible" % self._smsURL) smsHtml = self._grab_html(smsPage) parsedSms = self._parse_sms(smsHtml) decoratedSms = self._decorate_sms(parsedSms) @@ -436,7 +433,7 @@ class GVDialer(object): if anGroup is not None: self._accountNum = anGroup.group(1) else: - logging.debug("Could not extract account number from GoogleVoice") + _moduleLogger.debug("Could not extract account number from GoogleVoice") self._callbackNumbers = {} for match in self._callbackRe.finditer(page): @@ -472,8 +469,8 @@ class GVDialer(object): try: flatXml = self._browser.download(url) except urllib2.URLError, e: - logging.exception(str(e)) - raise NetworkError("%s is not accesible" % url) + _moduleLogger.exception(str(e)) + raise RuntimeError("%s is not accesible" % url) allRecentHtml = self._grab_html(flatXml) allRecentData = self._parse_voicemail(allRecentHtml) diff --git a/src/handle.py b/src/handle.py index 69b782e..e2c7ae3 100644 --- a/src/handle.py +++ b/src/handle.py @@ -4,6 +4,9 @@ import weakref import telepathy +_moduleLogger = logging.getLogger("handle") + + class MetaMemoize(type): """ Allows a class to cache off instances for reuse @@ -13,7 +16,7 @@ class MetaMemoize(type): obj, newlyCreated = cls.__new__(cls, connection, *args) if newlyCreated: obj.__init__(connection, connection.get_handle_id(), *args) - logging.info("New Handle %r" % obj) + _moduleLogger.info("New Handle %r" % obj) return obj diff --git a/src/simple_presence.py b/src/simple_presence.py index 4219e84..b309e14 100644 --- a/src/simple_presence.py +++ b/src/simple_presence.py @@ -3,6 +3,9 @@ import logging import telepathy +_moduleLogger = logging.getLogger("simple_presence") + + class TheOneRingPresence(object): ONLINE = 'available' BUSY = 'dnd' @@ -56,7 +59,7 @@ class SimplePresenceMixin(telepathy.server.ConnectionInterfaceSimplePresence): self.gvoice_backend.mark_dnd(False) else: raise telepathy.errors.InvalidArgument - logging.info("Setting Presence to '%s'" % status) + _moduleLogger.info("Setting Presence to '%s'" % status) def _get_statuses(self): -- 1.7.9.5