[gnome-applets] invest-applet: Added more descriptive debug messages.
- From: Enrico Minack <eminack src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gnome-applets] invest-applet: Added more descriptive debug messages.
- Date: Sat, 5 Sep 2009 09:50:02 +0000 (UTC)
commit 9471e04ee0cc8571103fa3e07fc562555f3bd4f8
Author: Enrico Minack <enrico-minack gmx de>
Date: Sat Sep 5 11:46:34 2009 +0200
invest-applet: Added more descriptive debug messages.
invest-applet/invest/__init__.py | 15 ++++++++++++---
invest-applet/invest/chart.py | 6 +++---
invest-applet/invest/invest-applet.py | 11 ++++++-----
invest-applet/invest/preferences.py | 5 +++--
invest-applet/invest/quotes.py | 9 +++++----
invest-applet/invest/widgets.py | 4 ++--
6 files changed, 31 insertions(+), 19 deletions(-)
---
diff --git a/invest-applet/invest/__init__.py b/invest-applet/invest/__init__.py
index 9d3eccd..3d61aa6 100644
--- a/invest-applet/invest/__init__.py
+++ b/invest-applet/invest/__init__.py
@@ -1,6 +1,7 @@
import os, sys
from os.path import join, exists, isdir, isfile, dirname, abspath, expanduser
from types import ListType
+import datetime
import gtk, gtk.gdk, gconf, gobject
import cPickle
@@ -10,6 +11,15 @@ from defs import *
DEBUGGING = False
+# central debugging and error method
+def debug(msg):
+ if DEBUGGING:
+ print "%s: %s" % (datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f"), msg)
+
+def error(msg):
+ print "%s: ERROR: %s" % (datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f"), msg)
+
+
# Allow to use uninstalled invest ---------------------------------------------
UNINSTALLED_INVEST = False
def _check(path):
@@ -29,15 +39,13 @@ else:
SHARED_DATA_DIR = join(DATA_DIR, "gnome-applets", "invest-applet")
BUILDER_DATA_DIR = BUILDERDIR
ART_DATA_DIR = SHARED_DATA_DIR
-if DEBUGGING:
- print "Data Dir: %s" % SHARED_DATA_DIR
USER_INVEST_DIR = expanduser("~/.gnome2/invest-applet")
if not exists(USER_INVEST_DIR):
try:
os.makedirs(USER_INVEST_DIR, 0744)
except Exception , msg:
- print 'Error:could not create user dir (%s): %s' % (USER_INVEST_DIR, msg)
+ error('Could not create user dir (%s): %s' % (USER_INVEST_DIR, msg))
# ------------------------------------------------------------------------------
# Set the cwd to the home directory so spawned processes behave correctly
@@ -89,6 +97,7 @@ try:
if old_stock_format(STOCKS):
STOCKS = update_stock_format(STOCKS);
except Exception, msg:
+ error("Could not load the stocks from %s: %s" % (STOCKS_FILE, msg) )
STOCKS = {}
#STOCKS = {
diff --git a/invest-applet/invest/chart.py b/invest-applet/invest/chart.py
index 7311e03..99d9242 100644
--- a/invest-applet/invest/chart.py
+++ b/invest-applet/invest/chart.py
@@ -49,9 +49,8 @@ class ImageRetriever(Thread, _IdleObject):
def run(self):
self.image = gtk.Image()
try: sock = urllib.urlopen(self.image_url, proxies = invest.PROXY)
- except:
- if invest.DEBUGGING:
- print "Error while opening %s" % self.image_url
+ except Exception, msg:
+ invest.debug("Error while opening %s: %s" % (self.image_url, msg))
else:
loader = gtk.gdk.PixbufLoader()
loader.connect("closed", lambda loader: self.image.set_from_pixbuf(loader.get_pixbuf()))
@@ -108,6 +107,7 @@ class FinancialChart:
pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(join(invest.ART_DATA_DIR, "invest_neutral.svg"), 96,96)
self.ui.get_object("plot").set_from_pixbuf(pixbuf)
except Exception, msg:
+ invest.debug("Could not load 'invest-neutral.svg' file: %s" % msg)
pass
# Defaut comboboxes values
diff --git a/invest-applet/invest/invest-applet.py b/invest-applet/invest/invest-applet.py
index 3991214..eeba9dd 100755
--- a/invest-applet/invest/invest-applet.py
+++ b/invest-applet/invest/invest-applet.py
@@ -30,11 +30,8 @@ locale.textdomain(invest.defs.GETTEXT_PACKAGE)
from gettext import gettext as _
-debugging = False
-
def applet_factory(applet, iid):
- if invest.DEBUGGING:
- print 'Starting invest instance:', applet, iid
+ invest.debug('Starting invest instance: %s %s'% ( applet, iid ))
invest.applet.InvestApplet(applet)
return True
@@ -81,7 +78,11 @@ if __name__ == "__main__":
usage()
elif o in ("-d", "--debug"):
invest.DEBUGGING = True
- print "Debugging enabled"
+ invest.debug("Debugging enabled")
+ # these messages cannot be turned by invest.DEBUGGING at their originating location,
+ # because that variable was set here to be True
+ invest.debug("Data Dir: %s" % invest.SHARED_DATA_DIR)
+ invest.debug("Detected PROXY: %s" % invest.PROXY)
elif o in ("-w", "--window"):
standalone = True
diff --git a/invest-applet/invest/preferences.py b/invest-applet/invest/preferences.py
index 94ed23a..65d83dc 100644
--- a/invest-applet/invest/preferences.py
+++ b/invest-applet/invest/preferences.py
@@ -71,6 +71,7 @@ class PrefsDialog:
pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(join(invest.ART_DATA_DIR, "invest-16.png"), -1,-1)
self.dialog.set_icon(pixbuf)
except Exception, msg:
+ invest.debug("Could not load 'invest-16.png' file: %s" % msg)
pass
self.sync_ui()
@@ -101,9 +102,9 @@ class PrefsDialog:
self.model.foreach(save_symbol)
try:
cPickle.dump(invest.STOCKS, file(invest.STOCKS_FILE, 'w'))
- if invest.DEBUGGING: print 'Stocks written to file'
+ invest.debug('Stocks written to file')
except Exception, msg:
- if invest.DEBUGGING: print 'Could not save stocks file:', msg
+ invest.error('Could not save stocks file: %s' % msg)
def sync_ui(self):
diff --git a/invest-applet/invest/quotes.py b/invest-applet/invest/quotes.py
index 9bd9ac3..a66a954 100644
--- a/invest-applet/invest/quotes.py
+++ b/invest-applet/invest/quotes.py
@@ -55,9 +55,8 @@ class QuotesRetriever(Thread, _IdleObject):
quotes_file = urlopen(quotes_url, proxies = invest.PROXY)
self.data = quotes_file.readlines ()
quotes_file.close ()
- except:
- if invest.DEBUGGING:
- print "Error while retrieving quotes data (url = %s)" % quotes_url
+ except Exception, msg:
+ invest.debug("Error while retrieving quotes data (url = %s): %s" % (quotes_url, msg))
else:
self.retrieved = True
self.emit("completed")
@@ -207,7 +206,9 @@ class QuoteUpdater(gtk.ListStore):
else:
positions_balance_sign = self.positions_balance/abs(self.positions_balance)
self.change_icon_callback(positions_balance_sign)
- except:
+ except Exception, msg:
+ invest.debug("Failed to populate quotes: %s" % msg)
+ invest.debug(quotes)
self.quotes_valid = False
def set_pb_callback(self, retriever, row):
diff --git a/invest-applet/invest/widgets.py b/invest-applet/invest/widgets.py
index 967294a..ef1017b 100644
--- a/invest-applet/invest/widgets.py
+++ b/invest-applet/invest/widgets.py
@@ -187,8 +187,8 @@ class InvestTrend(gtk.Image):
self.pixbuf.fill(
int(color.red*factor)<<24|int(color.green*factor)<<16|int(color.blue*factor)<<8|opacity)
self.set_from_pixbuf(self.pixbuf)
- except Exception, e:
- print e
+ except Exception, msg:
+ invest.error("Could not set color: %s" % msg)
def on_quotes_update(self, updater):
start_total = 0
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]