[hamster-applet] moved from printing to logging
- From: Toms Baugis <tbaugis src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [hamster-applet] moved from printing to logging
- Date: Wed, 28 Oct 2009 20:05:01 +0000 (UTC)
commit 875f8ca0df2736a97b33eb08a3d2b37de7b5b151
Author: Toms Bauģis <toms baugis gmail com>
Date: Wed Oct 28 19:57:04 2009 +0000
moved from printing to logging
hamster/applet.py | 4 +-
hamster/charting.py | 3 +-
hamster/configuration.py | 1 -
hamster/db.py | 25 ++++++++---------
hamster/dispatcher.py | 4 +-
hamster/eds.py | 3 +-
hamster/hamster-applet.py | 66 +++++++++++++++++++++++++-------------------
hamster/idle.py | 7 ++---
hamster/preferences.py | 8 +++---
hamster/stuff.py | 4 +-
10 files changed, 66 insertions(+), 59 deletions(-)
---
diff --git a/hamster/applet.py b/hamster/applet.py
index 5c4d195..6e7e538 100755
--- a/hamster/applet.py
+++ b/hamster/applet.py
@@ -19,7 +19,7 @@
# You should have received a copy of the GNU General Public License
# along with Project Hamster. If not, see <http://www.gnu.org/licenses/>.
-
+import logging
import datetime as dt
import os.path
@@ -248,7 +248,7 @@ class HamsterApplet(object):
runtime.dispatcher.add_handler('active_changed', self.on_idle_changed)
except dbus.DBusException, e:
- print "can't init dbus: %s" % e
+ logging.error("Can't init dbus: %s" % e)
# Load today's data, activities and set label
self.last_activity = None
diff --git a/hamster/charting.py b/hamster/charting.py
index e07dae5..a4a8459 100644
--- a/hamster/charting.py
+++ b/hamster/charting.py
@@ -42,6 +42,7 @@ from sys import maxint
import datetime as dt
import time
import graphics
+import logging
# Tango colors
light = [(252, 233, 79), (252, 175, 62), (233, 185, 110),
@@ -269,7 +270,7 @@ class Chart(graphics.Area):
retarget(self.integrators, self.data)
def draw(self):
- print "OMG OMG, not implemented!!!"
+ logging.error("OMG OMG, not implemented!!!")
class BarChart(Chart):
diff --git a/hamster/configuration.py b/hamster/configuration.py
index 7342e8c..d990a6f 100644
--- a/hamster/configuration.py
+++ b/hamster/configuration.py
@@ -38,7 +38,6 @@ class RuntimeStore(Singleton):
data_dir = ""
dispatcher = None
storage = None
- trace_sql = False
def __init__(self):
gettext.install("hamster-applet", unicode = True)
diff --git a/hamster/db.py b/hamster/db.py
index 9f45076..0bed313 100644
--- a/hamster/db.py
+++ b/hamster/db.py
@@ -20,15 +20,16 @@
"""separate file for database operations"""
+import logging
try:
import sqlite3 as sqlite
except ImportError:
try:
- print "Using sqlite2"
+ logging.warn("Using sqlite2")
from pysqlite2 import dbapi2 as sqlite
except ImportError:
- print "Error: Neither sqlite3 nor pysqlite2 found"
+ logging.error("Neither sqlite3 nor pysqlite2 found")
raise
import os, time
@@ -60,20 +61,20 @@ class Storage(storage.Storage):
try:
os.makedirs(db_path, 0744)
except Exception, msg:
- print 'Error:could not create user dir (%s): %s' % (db_path, msg)
+ logging.error("could not create user dir (%s): %s" % (db_path, msg))
data_dir = runtime.data_dir
#check if db is here
if not os.path.exists(db_file):
- print "Database not found in %s - installing default from %s!" % (db_file, data_dir)
+ logging.info("Database not found in %s - installing default from %s!" % (db_file, data_dir))
copyfile(os.path.join(data_dir, DB_FILE), db_file)
#change also permissions - sometimes they are 444
try:
os.chmod(db_file, 0664)
except Exception, msg:
- print 'Error:could not change mode on %s!' % (db_file)
+ logging.error("Could not change mode on %s!" % (db_file))
self.__setup.im_func.complete = True
self.run_fixtures()
__setup.complete = False
@@ -329,7 +330,7 @@ class Storage(storage.Storage):
if fact["start_time"] < start_time < fact["end_time"] and \
fact["start_time"] < end_time < fact["end_time"]:
- print "splitting %s" % fact["name"]
+ logging.info("splitting %s" % fact["name"])
self.execute("""UPDATE facts
SET end_time = ?
WHERE id = ?""", (start_time, fact["id"]))
@@ -344,18 +345,18 @@ class Storage(storage.Storage):
elif fact["end_time"] and \
start_time < fact["start_time"] < end_time and \
start_time < fact["end_time"] < end_time:
- print "eliminating %s" % fact["name"]
+ logging.info("eliminating %s" % fact["name"])
self.__remove_fact(fact["id"])
# overlap start
elif start_time < fact["start_time"] < end_time:
- print "Overlapping start of %s" % fact["name"]
+ logging.info("Overlapping start of %s" % fact["name"])
self.execute("UPDATE facts SET start_time=? WHERE id=?",
(end_time, fact["id"]))
# overlap end
elif start_time < fact["end_time"] < end_time:
- print "Overlapping end of %s" % fact["name"]
+ logging.info("Overlapping end of %s" % fact["name"])
self.execute("UPDATE facts SET end_time=? WHERE id=?",
(start_time, fact["id"]))
@@ -683,8 +684,7 @@ class Storage(storage.Storage):
con = self.connection
cur = con.cursor()
- if runtime.trace_sql:
- print query, params
+ logging.debug("%s %s" % (query, params))
if params:
cur.execute(query, params)
@@ -720,8 +720,7 @@ class Storage(storage.Storage):
if isinstance(statement, list):
for i in range(len(statement)):
- if runtime.trace_sql:
- print statement[i], params[i]
+ logging.debug("%s %s" % (statement[i], params[i]))
res = cur.execute(statement[i], params[i])
diff --git a/hamster/dispatcher.py b/hamster/dispatcher.py
index b3eddae..9eaf44f 100644
--- a/hamster/dispatcher.py
+++ b/hamster/dispatcher.py
@@ -16,7 +16,7 @@
# You should have received a copy of the GNU General Public License
# along with Project Hamster. If not, see <http://www.gnu.org/licenses/>.
-
+import logging
class Dispatcher(object):
def __init__(self):
@@ -38,4 +38,4 @@ class Dispatcher(object):
for handler in self.handlers[event]:
handler(event, data)
else:
- print 'Missing handler for event %s' % event
+ logging.info('Missing handler for event %s' % event)
diff --git a/hamster/eds.py b/hamster/eds.py
index 9da0433..1e9a0aa 100644
--- a/hamster/eds.py
+++ b/hamster/eds.py
@@ -18,6 +18,7 @@
# You should have received a copy of the GNU General Public License
# along with Project Hamster. If not, see <http://www.gnu.org/licenses/>.
+import logging
EDS_AVAILABLE = False
try:
@@ -48,5 +49,5 @@ def get_eds_tasks():
tasks.append({'name': task.get_summary(), 'category' : category})
return tasks
except Exception, e: # TODO's are not priority - print warning and go home
- print e
+ logging.warn(e)
return []
diff --git a/hamster/hamster-applet.py b/hamster/hamster-applet.py
index bbe7c5a..9730c92 100755
--- a/hamster/hamster-applet.py
+++ b/hamster/hamster-applet.py
@@ -24,30 +24,8 @@ import getopt, sys
import os.path
import gettext, locale
import gnome
+import logging
-# check from AUTHORS file and if one found - we are running from sources
-name = os.path.join(os.path.dirname(__file__), '..')
-if os.path.exists(os.path.join(name, 'AUTHORS')):
- print 'Running from source folder, modifying PYTHONPATH'
- sys.path.insert(0, os.path.join(name, "hamster", "keybinder", ".libs"))
- sys.path.insert(0, name)
-
-# Now the path is set, import our applet
-from hamster import defs
-from hamster.configuration import runtime
-
-# Setup i18n
-locale_dir = os.path.abspath(os.path.join(defs.DATA_DIR, "locale"))
-
-for module in (gettext, locale):
- module.bindtextdomain('hamster-applet', locale_dir)
- module.textdomain('hamster-applet')
-
- if hasattr(module, 'bind_textdomain_codeset'):
- module.bind_textdomain_codeset('hamster-applet','UTF-8')
-
-
-from hamster.applet import HamsterApplet
def applet_factory(applet, iid):
applet.connect("destroy", on_destroy)
@@ -83,7 +61,7 @@ OPTIONS:
-s, --start [stats|edit|prefs] Which window to launch on startup.
Use "stats" for overview window, "edit" to add new activity
and "prefs" to launch preferences
- -t --trace-sql print out sql statements in terminal
+ -d --debug set log level to debug
""")
if __name__ == "__main__":
@@ -91,20 +69,50 @@ if __name__ == "__main__":
start_window = None
try:
- opts, args = getopt.getopt(sys.argv[1:], "ws:t", ["window", "start=", "trace-sql"])
+ opts, args = getopt.getopt(sys.argv[1:], "ws:d", ["window", "start=", "debug"])
+ if opts:
+ logging.basicConfig(level=logging.INFO) # set lower log level as we run the thing from console
+
for opt, args in opts:
if opt in ("-w", "--window"):
standalone = True
elif opt in ("-s", "--start"):
start_window = args
- elif opt in ("-t", "--trace-sql"):
- runtime.trace_sql = True
-
+ elif opt in ("-d", "--debug"):
+ logging.getLogger().setLevel(logging.DEBUG)
except getopt.GetoptError:
usage()
- print "Starting nevertheless, because applet dies otherwise (TODO)"
+ log.info("Starting nevertheless, because applet dies otherwise (TODO)")
+
+
+
+ # check from AUTHORS file and if one found - we are running from sources
+ name = os.path.join(os.path.dirname(__file__), '..')
+ if os.path.exists(os.path.join(name, 'AUTHORS')):
+ logging.info("Running from source folder, modifying PYTHONPATH")
+ sys.path.insert(0, os.path.join(name, "hamster", "keybinder", ".libs"))
+ sys.path.insert(0, name)
+
+ # Now the path is set, import our applet
+ from hamster import defs
+ from hamster.configuration import runtime
+
+ # Setup i18n
+ locale_dir = os.path.abspath(os.path.join(defs.DATA_DIR, "locale"))
+
+ for module in (gettext, locale):
+ module.bindtextdomain('hamster-applet', locale_dir)
+ module.textdomain('hamster-applet')
+
+ if hasattr(module, 'bind_textdomain_codeset'):
+ module.bind_textdomain_codeset('hamster-applet','UTF-8')
+
+
+ from hamster.applet import HamsterApplet
+
+
gtk.window_set_default_icon_name("hamster-applet")
diff --git a/hamster/idle.py b/hamster/idle.py
index cc8a4d0..1b2e409 100644
--- a/hamster/idle.py
+++ b/hamster/idle.py
@@ -17,6 +17,7 @@
# You should have received a copy of the GNU General Public License
# along with Project Hamster. If not, see <http://www.gnu.org/licenses/>.
+import logging
import dbus
from dbus.lowlevel import Message
import gconf
@@ -78,8 +79,7 @@ class DbusIdleListener(object):
member = message.get_member()
if member in ("SessionIdleChanged", "ActiveChanged"):
- if __debug__:
- print "%s ->" % member, message.get_args_list()
+ logging.debug("%s -> %s" % (member, message.get_args_list()))
idle_state = message.get_args_list()[0]
if idle_state:
@@ -119,8 +119,7 @@ class DbusIdleListener(object):
elif member == "Lock":
# in case of lock, lock signal will be sent first, followed by
# ActiveChanged and SessionIdle signals
- if __debug__:
- print "Screen Lock Requested"
+ logging.debug("Screen Lock Requested")
self.screen_locked = True
return True
diff --git a/hamster/preferences.py b/hamster/preferences.py
index 4326799..2c3f489 100755
--- a/hamster/preferences.py
+++ b/hamster/preferences.py
@@ -17,7 +17,7 @@
# You should have received a copy of the GNU General Public License
# along with Project Hamster. If not, see <http://www.gnu.org/licenses/>.
-
+import logging
import pygtk
pygtk.require('2.0')
@@ -254,13 +254,13 @@ class PreferencesEditor:
iter = model.get_iter(path)
if (position == gtk.TREE_VIEW_DROP_BEFORE
or position == gtk.TREE_VIEW_DROP_INTO_OR_BEFORE):
- print "insert '%s' before '%s'" % (data, model[iter][3])
+ logging.debug("insert '%s' before '%s'" % (data, model[iter][3]))
runtime.storage.move_activity(int(data), model[iter][3], insert_after = False)
else:
- print "insert '%s' after '%s'" % (data, model[iter][3])
+ logging.debug("insert '%s' after '%s'" % (data, model[iter][3]))
runtime.storage.move_activity(int(data), model[iter][3], insert_after = True)
else:
- print "append '%s'" % data
+ logging.debug("append '%s'" % data)
if context.action == gtk.gdk.ACTION_MOVE:
context.finish(True, True, etime)
diff --git a/hamster/stuff.py b/hamster/stuff.py
index 96e9002..fbd60bf 100644
--- a/hamster/stuff.py
+++ b/hamster/stuff.py
@@ -21,6 +21,7 @@
# some widgets that repeat all over the place
# cells, columns, trees and other
+import logging
import gtk
import pango
from pango import ELLIPSIZE_END
@@ -71,8 +72,7 @@ def locale_first_weekday():
beginning = week_start + week_offset
first_weekday = int(beginning.strftime("%w"))
except:
- print "WARNING - Failed to get first weekday from locale"
- pass
+ logging.warn("WARNING - Failed to get first weekday from locale")
return first_weekday
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]