mousetrap r8 - in trunk: . src/mouseTrap
- From: flaper svn gnome org
- To: svn-commits-list gnome org
- Subject: mousetrap r8 - in trunk: . src/mouseTrap
- Date: Fri, 5 Sep 2008 21:31:53 +0000 (UTC)
Author: flaper
Date: Fri Sep 5 21:31:53 2008
New Revision: 8
URL: http://svn.gnome.org/viewvc/mousetrap?rev=8&view=rev
Log:
New Debug Implementation, Ticket #13 Closed
Modified:
trunk/ChangeLog
trunk/src/mouseTrap/cam.py
trunk/src/mouseTrap/debug.py
trunk/src/mouseTrap/events.py
trunk/src/mouseTrap/mTDbus.py
trunk/src/mouseTrap/mainGui.py
trunk/src/mouseTrap/mouseTrap.py
trunk/src/mouseTrap/mouseTrapPref.py
trunk/src/mouseTrap/mousetrap.in
trunk/src/mouseTrap/ocvfw.py
trunk/src/mouseTrap/prefGui.py
trunk/src/mouseTrap/scripts.py
Modified: trunk/src/mouseTrap/cam.py
==============================================================================
--- trunk/src/mouseTrap/cam.py (original)
+++ trunk/src/mouseTrap/cam.py Fri Sep 5 21:31:53 2008
@@ -129,7 +129,7 @@
gobject.timeout_add(100, self._checkImg)
except:
- debug.log( debug.MODULES, _( "Highest" ) )
+ debug.exception( "mouseTrap.cam", _( "The Camera Module load failed." ) )
def _checkImg( self ):
@@ -141,6 +141,7 @@
"""
self.cmQueryCapture( flip = self.settings.flipImage )
+
# create a self.gray version of the self.img
cv.cvCvtColor (self.img, self.grey, cv.CV_BGR2GRAY)
@@ -165,7 +166,6 @@
# handle events
c = self.cmWaitKey(10)
- #highgui.cvDestroyAllWindows()
return self.run
Modified: trunk/src/mouseTrap/debug.py
==============================================================================
--- trunk/src/mouseTrap/debug.py (original)
+++ trunk/src/mouseTrap/debug.py Fri Sep 5 21:31:53 2008
@@ -28,62 +28,130 @@
__license__ = "GPLv2"
import sys
+import logging
import traceback
+import mouseTrap
import environment as env
-##
-# This debug level is used to know when a feature fails,
-# normaly that feature doesn't make mouseTrap crash.
-ACTIONS = 600
-
-##
-# This debug level is used to know when a module fails while
-# loading.
-MODULES = 400
-
-##
-# This debug level is used to know when mouseTrap crashes while starting.
-LOAD = 200
-
-##
-# It will show all debugging errors.
-ALL = 0
-
-##
-# This is just for tracing out all the executed code.
-EXTREME = 100*100
-
-##
-# The starter debugLevel. Should be defined in the settings file.
-debugLevel = ALL
-def log( level, priority, Trace = None ):
+def checkModule( module ):
"""
- Write the logs in debug file and print them in the terminal.
-
+ Get's a new logger for modules.
+
+ Arguments:
+ - module: The module requesting a logger.
+ """
+
+ if module == "mousetrap":
+ level = logging.DEBUG
+ else:
+ level = mouseTrap.settings.debugLevel
+
+ formatter = logging.Formatter("%(levelname)s: %(name)s -> %(message)s")
+
+ cli = logging.StreamHandler()
+ cli.setLevel( level )
+ cli.setFormatter(formatter)
+
+ file = logging.FileHandler( env.debugFile )
+ file.setLevel( level )
+ file.setFormatter(formatter)
+
+ modules[module] = logging.getLogger( module )
+ modules[module].setLevel( level )
+ modules[module].addHandler(cli)
+ modules[module].addHandler(file)
+
+
+def debug( module, message ):
+ """
+ Print DEBUG level log messages.
+
+ Arguments:
+ - module: The module sending the message
+ - message: The message
+ """
+
+ if module not in modules:
+ checkModule(module)
+
+ modules[module].debug(message)
+
+
+def info( module, message ):
+ """
+ Print INFO level log messages.
+
+ Arguments:
+ - module: The module sending the message
+ - message: The message
+ """
+
+ if module not in modules:
+ checkModule(module)
+
+ modules[module].info(message)
+
+
+def warning( module, message ):
+ """
+ Print WARNING level log messages.
+
Arguments:
- - level: The debug level
- - priority: The log priority.
- - Trace: if True: The Trace will replace the log.
+ - module: The module sending the message
+ - message: The message
"""
+ if module not in modules:
+ checkModule(module)
+
+ modules[module].warning(message)
+
+
+def error( module, message ):
+ """
+ Print ERROR level log messages.
+
+ Arguments:
+ - module: The module sending the message
+ - message: The message
+ """
+
+ if module not in modules:
+ checkModule(module)
+
+ modules[module].error(message)
+
- debugFile = open(env.debugFile, "a")
+def critical( module, message ):
+ """
+ Print CRITICAL level log messages.
+
+ Arguments:
+ - module: The module sending the message
+ - message: The message
+ """
+
+ if module not in modules:
+ checkModule(module)
+
+ modules[module].critical(message)
+
+
+def exception( module, message ):
+ """
+ Print EXCEPTION level log messages.
+
+ Arguments:
+ - module: The module sending the message
+ - message: The message
+ """
- log = ''.join(traceback.format_exception(*sys.exc_info()))
+ if module not in modules:
+ checkModule(module)
- if Trace: log = Trace
-
- priority = '='*30 + '\nPriority:' + priority + '\n' + '='*30 + '\n'
-
- if level >= debugLevel:
- debugFile.write(priority)
- debugFile.writelines([log, "\n"])
- print priority
- print log
+ modules[module].exception(message)
- debugFile.close()
-
# The following code has been borrowed from the following URL:
#
# http://www.dalkescientific.com/writings/diary/archive/ \
@@ -122,5 +190,5 @@
log(ALL, "Trace", "TRACE %s:%s: %s" % (name, lineno, line.rstrip()))
return traceit
-if debugLevel == EXTREME:
- sys.settrace(traceit)
+#if debugLevel == EXTREME:
+# sys.settrace(traceit)
Modified: trunk/src/mouseTrap/events.py
==============================================================================
--- trunk/src/mouseTrap/events.py (original)
+++ trunk/src/mouseTrap/events.py Fri Sep 5 21:31:53 2008
@@ -115,7 +115,7 @@
try:
gobject.timeout_add( 10, _checkMapperEvents )
except:
- debug.log( debug.MODULES, _( "Highest" ) )
+ debug.exception( "mouseTrap.events", _( "The events module load failed" ) )
def _checkMapperEvents():
Modified: trunk/src/mouseTrap/mTDbus.py
==============================================================================
--- trunk/src/mouseTrap/mTDbus.py (original)
+++ trunk/src/mouseTrap/mTDbus.py Fri Sep 5 21:31:53 2008
@@ -79,7 +79,7 @@
try:
dbusserver = mTDbusServer()
except:
- debug.log( debug.LOAD, _( "Warning" ) )
+ debug.exception( "mouseTrap.mTDbus", _( "The dbus server load failed" ) )
def shutdown():
Modified: trunk/src/mouseTrap/mainGui.py
==============================================================================
--- trunk/src/mouseTrap/mainGui.py (original)
+++ trunk/src/mouseTrap/mainGui.py Fri Sep 5 21:31:53 2008
@@ -259,7 +259,7 @@
except ImportError:
dialogs.errorDialog(
"mouseTrap needs <b>gnome</b> module to show the help. Please install gnome-python and try again.", None )
- debug.log( debug.ACTIONS, _( "Highest" ) )
+ debug.exception( "mousetrap.mainGui", _( "The help load failed" ) )
def close( self, *args ):
"""
Modified: trunk/src/mouseTrap/mouseTrap.py
==============================================================================
--- trunk/src/mouseTrap/mouseTrap.py (original)
+++ trunk/src/mouseTrap/mouseTrap.py Fri Sep 5 21:31:53 2008
@@ -65,7 +65,6 @@
sys.argv[0] = "mouseTrap"
-
## Global MainLoop
loop = gobject.MainLoop()
@@ -146,7 +145,7 @@
if settings.showMainGui:
modules["gui"] = gui.showMainGui( )
except:
- debug.log( debug.LOAD, _( "Highest" ) )
+ debug.exception( "mosuetrap", _( "Main Gui load failed" ) )
def startCam( ):
"""
@@ -165,7 +164,7 @@
if settings.startCam:
modules["cam"].start()
except:
- debug.log( debug.LOAD, _( "Highest" ) )
+ debug.exception( "mousetrap", _( "Camera Module load failed" ) )
def startEventsHandler():
global modules
@@ -178,7 +177,7 @@
if settings.startCam:
modules["events"].startMapperListener( modules["gui"].mapper )
except:
- debug.log( debug.LOAD, _( "Highest" ) )
+ debug.exception( "mosuetrap", _( "Events Handler Load Failed" ) )
def startDBus( ):
"""
@@ -194,7 +193,7 @@
[''])
dbus.start()
except:
- debug.log( debug.LOAD, _( "Highest" ) )
+ debug.exception( "mousetrap", _( "DBus Service Load Failed" ) )
def loadSettings( ):
"""
@@ -216,7 +215,7 @@
os.chdir(env.configPath)
settings = __import__( "userSettings" )
except:
- debug.log( debug.LOAD, _( "Highest" ) )
+ debug.exception( "mousetrap", _( "Mousetrap Settings load failed." ) )
sys.exit(0)
else:
try:
@@ -226,7 +225,7 @@
if getattr( modules[mod], "restart" ):
modules[mod].restart()
except:
- debug.log( debug.LOAD, _( "Highest" ) )
+ debug.exception( "mousetrap", _("Mousetrap Settings reload failed") )
def calcPoint():
@@ -337,7 +336,7 @@
print "KeyboardInterrupt"
quit(0)
except:
- debug.log( debug.LOAD, _( "Highest" ) )
+ debug.exception( "mousetrap", "Mousetrap failed starting the loops" )
def usage( ):
Modified: trunk/src/mouseTrap/mouseTrapPref.py
==============================================================================
--- trunk/src/mouseTrap/mouseTrapPref.py (original)
+++ trunk/src/mouseTrap/mouseTrapPref.py Fri Sep 5 21:31:53 2008
@@ -112,7 +112,7 @@
prefFile.write("inputDevIndex = 0\n")
prefFile.write("\n#debugLevel\n")
- prefFile.write("debugLevel = 1000\n")
+ prefFile.write("debugLevel = 10\n")
prefFile.write("\n#defClick\n")
prefFile.write("defClick = 'b1c'\n")
Modified: trunk/src/mouseTrap/mousetrap.in
==============================================================================
--- trunk/src/mouseTrap/mousetrap.in (original)
+++ trunk/src/mouseTrap/mousetrap.in Fri Sep 5 21:31:53 2008
@@ -186,6 +186,7 @@
mouseTrap &
mouseTrap_pid=$!
wait $mouseTrap_pid
+ echo pasa
RUN=$? # quit on a normal exit status from mouseTrap
Modified: trunk/src/mouseTrap/ocvfw.py
==============================================================================
--- trunk/src/mouseTrap/ocvfw.py (original)
+++ trunk/src/mouseTrap/ocvfw.py Fri Sep 5 21:31:53 2008
@@ -100,7 +100,7 @@
points = cv.cvHaarDetectObjects( self.smallImg, cascade, self.storage,
1.2, 2, method, cv.cvSize(20,20) )
else:
- debug.log( debug.ACTIONS, _( "Required" ) )
+ debug.exception( "mouseTrap.ocvfw", _("The Haar Classifier Cascade load failed") )
if points:
matches = [ [ cv.cvPoint( int(r.x*self.imageScale), int(r.y*self.imageScale)), \
@@ -130,7 +130,7 @@
points = cv.cvHaarDetectObjects( imageROI, cascade, self.storage,
1.2, 2, method, cv.cvSize(20,20) )
else:
- debug.log( debug.ACTIONS, _( "Required" ) )
+ debug.exception( "mouseTrap.ocvfw", _( "The Haar Classifier Cascade load Failed (ROI)" ) )
if points:
matches = [ [ cv.cvPoint( int(r.x+origSize[0]), int(r.y+origSize[1])), \
Modified: trunk/src/mouseTrap/prefGui.py
==============================================================================
--- trunk/src/mouseTrap/prefGui.py (original)
+++ trunk/src/mouseTrap/prefGui.py Fri Sep 5 21:31:53 2008
@@ -314,7 +314,7 @@
levellabel.show()
levelHbox.pack_start( levellabel, False, False )
- adj = gtk.Adjustment( self.settings.debugLevel, 0, 1000, 200, 1, 0)
+ adj = gtk.Adjustment( self.settings.debugLevel, 10, 50, 10, 1, 0)
levelSpin = gtk.SpinButton( adj, 0.0, 0 )
levelSpin.set_wrap( True )
levelHbox.pack_start( levelSpin, False, False )
Modified: trunk/src/mouseTrap/scripts.py
==============================================================================
--- trunk/src/mouseTrap/scripts.py (original)
+++ trunk/src/mouseTrap/scripts.py Fri Sep 5 21:31:53 2008
@@ -59,7 +59,7 @@
modes[prof.setName] = prof.Profile
env.mouseModes.update( prof.modes )
except:
- debug.log( debug.MODULES, _( "Highest" ) )
+ debug.exception( "mouseTrap.scripts", _( "The Profile load failed" ) )
def loadProfile( gui ):
"""
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]