import urllib2
import cookielib
-import warnings
+import logging
import socket
@return: The raw HTML page data
"""
- warnings.warn("Performing download of %s" % url, UserWarning, 2)
+ logging.warning("Performing download of %s" % url)
if extraheaders is None:
extraheaders = {}
import base64
import ConfigParser
import itertools
-import warnings
+import logging
import gtk
import gtk.glade
self._window.connect("key-press-event", self._on_key_press)
self._window.connect("window-state-event", self._on_window_state_change)
else:
- pass # warnings.warn("No Hildon", UserWarning, 2)
+ logging.warning("No hildonization support")
+
hildonize.set_application_title(self._window, "%s" % constants.__pretty_app_name__)
device = osso.DeviceState(self._osso)
device.set_device_state_callback(self._on_device_state_change, 0)
else:
- pass # warnings.warn("No OSSO", UserWarning, 2)
+ logging.warning("No device state support")
try:
import alarm_handler
with gtk_toolbox.gtk_lock():
self._errorDisplay.push_exception()
alarm_handler = None
+ logging.warning("No notification support")
if hildonize.IS_HILDON:
import led_handler
self._ledHandler = led_handler.LedHandler()
self._connection.connect("connection-event", self._on_connection_change, constants.__app_magic__)
self._connection.request_connection(conic.CONNECT_FLAG_NONE)
else:
- pass # warnings.warn("No Internet Connectivity API ", UserWarning)
+ logging.warning("No connection support")
# Setup costly backends
import gv_backend
serviceId = self._defaultBackendId
loggedIn = True
except StandardError, e:
- warnings.warn('Session refresh failed with the following message "%s"' % e.message, UserWarning, 2)
+ logging.exception('Session refresh failed with the following message "%s"' % e.message)
if not loggedIn:
loggedIn, serviceId = self._login_by_user(numOfAttempts)
"""
loggedIn = self._phoneBackends[self._defaultBackendId].is_authed()
if loggedIn:
- warnings.warn(
- "Logged into %r through cookies" % self._phoneBackends[self._defaultBackendId],
- UserWarning, 2
- )
+ logging.info("Logged into %r through cookies" % self._phoneBackends[self._defaultBackendId])
return loggedIn
def _login_by_settings(self):
loggedIn = self._phoneBackends[self._defaultBackendId].login(username, password)
if loggedIn:
self._credentials = username, password
- warnings.warn(
- "Logged into %r through settings" % self._phoneBackends[self._defaultBackendId],
- UserWarning, 2
- )
+ logging.info("Logged into %r through settings" % self._phoneBackends[self._defaultBackendId])
return loggedIn
def _login_by_user(self, numOfAttempts):
if loggedIn:
serviceId = tmpServiceId
self._credentials = username, password
- warnings.warn(
- "Logged into %r through user request" % self._phoneBackends[serviceId],
- UserWarning, 2
- )
+ logging.info("Logged into %r through user request" % self._phoneBackends[serviceId])
else:
serviceId = self.NULL_BACKEND
if self._alarmHandler is not None:
self._alarmHandler.load_settings(config, "alarm")
except ConfigParser.NoOptionError, e:
- warnings.warn(
+ logging.exception(
"Settings file %s is missing section %s" % (
constants._user_settings_,
e.section,
),
- stacklevel=2
)
except ConfigParser.NoSectionError, e:
- warnings.warn(
+ logging.exception(
"Settings file %s is missing section %s" % (
constants._user_settings_,
e.section,
),
- stacklevel=2
)
for backendId, view in itertools.chain(
try:
view.load_settings(config, sectionName)
except ConfigParser.NoOptionError, e:
- warnings.warn(
+ logging.exception(
"Settings file %s is missing section %s" % (
constants._user_settings_,
e.section,
),
- stacklevel=2
)
except ConfigParser.NoSectionError, e:
- warnings.warn(
+ logging.exception(
"Settings file %s is missing section %s" % (
constants._user_settings_,
e.section,
),
- stacklevel=2
)
def save_settings(self, config):
if __name__ == "__main__":
- if len(sys.argv) > 1:
- try:
- import optparse
- except ImportError:
- optparse = None
-
- if optparse is not None:
- parser = optparse.OptionParser()
- parser.add_option("-t", "--test", action="store_true", dest="test", help="Run tests")
- (commandOptions, commandArgs) = parser.parse_args()
+ if hildonize.IS_HILDON:
+ userLogPath = "%s/dialcentral.log" % constants._data_path_
+ logging.basicConfig(level=logging.DEBUG, filename=userLogPath)
else:
- commandOptions = DummyOptions()
- commandArgs = []
+ logging.basicConfig(level=logging.DEBUG)
+ try:
+ if len(sys.argv) > 1:
+ try:
+ import optparse
+ except ImportError:
+ optparse = None
- if commandOptions.test:
- run_doctest()
- else:
- run_dialpad()
+ if optparse is not None:
+ parser = optparse.OptionParser()
+ parser.add_option("-t", "--test", action="store_true", dest="test", help="Run tests")
+ (commandOptions, commandArgs) = parser.parse_args()
+ else:
+ commandOptions = DummyOptions()
+ commandArgs = []
+
+ if commandOptions.test:
+ run_doctest()
+ else:
+ run_dialpad()
+ finally:
+ logging.shutdown()
import errno
import sys
import time
-import traceback
import functools
import contextlib
-import warnings
+import logging
import threading
import Queue
else:
self.__show_message(message)
- def push_exception_with_lock(self, exception = None, stacklevel=3):
+ def push_exception_with_lock(self):
with gtk_lock():
- self.push_exception(exception, stacklevel=stacklevel)
+ self.push_exception()
- def push_exception(self, exception = None, stacklevel=2):
- if exception is None:
- userMessage = str(sys.exc_value)
- warningMessage = str(traceback.format_exc())
- else:
- userMessage = str(exception)
- warningMessage = str(exception)
+ def push_exception(self):
+ userMessage = str(sys.exc_value)
self.push_message(userMessage)
- warnings.warn(warningMessage, stacklevel=stacklevel)
+ logging.exception(userMessage)
def pop_message(self):
if 0 < len(self.__messages):
self.__show_message(message)
def push_exception(self, exception = None):
- if exception is None:
- warningMessage = traceback.format_exc()
- else:
- warningMessage = exception
- warnings.warn(warningMessage, stacklevel=3)
+ userMessage = str(sys.exc_value)
+ logging.exception(userMessage)
def pop_message(self):
if 0 < len(self.__messages):
del self.__messages[0]
def __show_message(self, message):
- warnings.warn(message, stacklevel=2)
+ logging.debug(message)
class MessageBox(gtk.MessageDialog):
self._calendar.select_month(self._displayDate.month, self._displayDate.year)
self._calendar.select_day(self._displayDate.day)
except StandardError, e:
- warnings.warn(e.message)
+ logging.exception(e.message)
class QuickAddView(object):
import time
import datetime
import itertools
-import warnings
-import traceback
+import logging
from xml.sax import saxutils
from xml.etree import ElementTree
try:
self._grab_account_info()
except StandardError, e:
- warnings.warn(traceback.format_exc())
+ logging.exception(str(e))
return False
self._browser.cookies.save()
try:
loginSuccessOrFailurePage = self._browser.download(self._loginURL, loginPostData)
except urllib2.URLError, e:
- warnings.warn(traceback.format_exc())
+ logging.exception(str(e))
raise RuntimeError("%s is not accesible" % self._loginURL)
return self.is_authed()
}
callSuccessPage = self._browser.download(self._clicktocallURL, clickToCallData, None, otherData)
except urllib2.URLError, e:
- warnings.warn(traceback.format_exc())
+ logging.exception(str(e))
raise RuntimeError("%s is not accesible" % self._clicktocallURL)
if self._gvDialingStrRe.search(callSuccessPage) is None:
}
smsSuccessPage = self._browser.download(self._sendSmsURL, smsData, None, otherData)
except urllib2.URLError, e:
- warnings.warn(traceback.format_exc())
+ logging.exception(str(e))
raise RuntimeError("%s is not accesible" % self._sendSmsURL)
return True
@param callbacknumber should be a proper 10 digit number
"""
self._callbackNumber = callbacknumber
-
- # Currently this isn't working out in GoogleVoice, but thats ok, we pass the callback on dial
- #callbackPostData = urllib.urlencode({
- # '_rnr_se': self._token,
- # 'phone': callbacknumber
- #})
- #try:
- # callbackSetPage = self._browser.download(self._setforwardURL, callbackPostData)
- # self._browser.cookies.save()
- #except urllib2.URLError, e:
- # warnings.warn(traceback.format_exc())
- # raise RuntimeError("%s is not accesible" % self._setforwardURL)
-
return True
def get_callback_number(self):
"""
@returns Current callback number or None
"""
- #for c in self._browser.cookies:
- # if c.name == "gv-ph":
- # return c.value
return self._callbackNumber
def get_recent(self):
try:
contactsPage = self._browser.download(contactsPageUrl)
except urllib2.URLError, e:
- warnings.warn(traceback.format_exc())
+ logging.exception(str(e))
raise RuntimeError("%s is not accesible" % contactsPageUrl)
for contact_match in self._contactsRe.finditer(contactsPage):
contactId = contact_match.group(1)
try:
detailPage = self._browser.download(self._contactDetailURL + '/' + contactId)
except urllib2.URLError, e:
- warnings.warn(traceback.format_exc())
+ logging.exception(str(e))
raise RuntimeError("%s is not accesible" % self._contactDetailURL)
for detail_match in self._contactDetailPhoneRe.finditer(detailPage):
try:
voicemailPage = self._browser.download(self._voicemailURL)
except urllib2.URLError, e:
- warnings.warn(traceback.format_exc())
+ logging.exception(str(e))
raise RuntimeError("%s is not accesible" % self._voicemailURL)
voicemailHtml = self._grab_html(voicemailPage)
parsedVoicemail = self._parse_voicemail(voicemailHtml)
try:
smsPage = self._browser.download(self._smsURL)
except urllib2.URLError, e:
- warnings.warn(traceback.format_exc())
+ logging.exception(str(e))
raise RuntimeError("%s is not accesible" % self._smsURL)
smsHtml = self._grab_html(smsPage)
parsedSms = self._parse_sms(smsHtml)
if anGroup is not None:
self._accountNum = anGroup.group(1)
else:
- warnings.warn("Could not extract account number from GoogleVoice", UserWarning, 2)
+ logging.debug("Could not extract account number from GoogleVoice")
self._callbackNumbers = {}
for match in self._callbackRe.finditer(page):
try:
flatXml = self._browser.download(url)
except urllib2.URLError, e:
- warnings.warn(traceback.format_exc())
+ logging.exception(str(e))
raise RuntimeError("%s is not accesible" % url)
allRecentHtml = self._grab_html(flatXml)
def test_backend(username, password):
- import pprint
backend = GVDialer()
print "Authenticated: ", backend.is_authed()
print "Login?: ", backend.login(username, password)
print "Account: ", backend.get_account_number()
print "Callback: ", backend.get_callback_number()
# print "All Callback: ",
+ #import pprint
# pprint.pprint(backend.get_callback_numbers())
# print "Recent: ",
# pprint.pprint(list(backend.get_recent()))
from __future__ import with_statement
import ConfigParser
-import warnings
+import logging
import gobject
import pango
if not self._backend.is_valid_syntax(number):
self._errorDisplay.push_message("%s is not a valid callback number" % number)
elif number == self._backend.get_callback_number():
- warnings.warn(
+ logging.warning(
"Callback number already is %s" % (
self._backend.get_callback_number(),
),
- UserWarning,
- 2
)
else:
self._backend.set_callback_number(number)
assert make_ugly(number) == make_ugly(self._backend.get_callback_number()), "Callback number should be %s but instead is %s" % (
make_pretty(number), make_pretty(self._backend.get_callback_number())
)
- warnings.warn(
+ logging.info(
"Callback number set to %s" % (
self._backend.get_callback_number(),
),
- UserWarning, 2
)
except StandardError, e:
self._errorDisplay.push_exception()