Author: remi
Date: 2008-12-13 21:09:24 +0100 (Sat, 13 Dec 2008)
New Revision: 3091
Modified:
software_suite_v2/tuxware/pytuxisalive/branches/complete_refactoring/src/tuxisalive/lib/driver/TuxDriver.py
Log:
* added a new logger
Modified:
software_suite_v2/tuxware/pytuxisalive/branches/complete_refactoring/src/tuxisalive/lib/driver/TuxDriver.py
===================================================================
---
software_suite_v2/tuxware/pytuxisalive/branches/complete_refactoring/src/tuxisalive/lib/driver/TuxDriver.py
2008-12-13 19:19:55 UTC (rev 3090)
+++
software_suite_v2/tuxware/pytuxisalive/branches/complete_refactoring/src/tuxisalive/lib/driver/TuxDriver.py
2008-12-13 20:09:24 UTC (rev 3091)
@@ -15,6 +15,8 @@
from ctypes import *
import os
+from tuxisalive.lib.logger import *
+
# Error codes list
E_TUXDRV_BEGIN = 256
E_TUXDRV_NOERROR = 0
@@ -150,24 +152,37 @@
"""Constructor.
@param library_path: Path of libtuxdriver library. (Default None)
"""
+ self.__logger = SimpleLogger("libtuxdriver_py")
+ self.__logger.setTarget(LOG_TARGET_FILE)
+ self.__logger.setLevel(LOG_LEVEL_DEBUG)
+ self.__logger.resetLog()
+
self.__logger.logInfo("-----------------------------------------------")
+ self.__logger.logInfo("libtuxdriver wrapper v%s" % __version__)
+ self.__logger.logInfo("Author : %s" % __author__)
+ self.__logger.logInfo("Licence : %s" % __licence__)
+
self.__logger.logInfo("-----------------------------------------------")
if library_path == None:
mPath, mFile = os.path.split(__file__)
if os.name == 'nt':
library_path = os.path.join(mPath, "libtuxdriver.dll")
else:
library_path = os.path.join(mPath, "libtuxdriver.so")
+ self.__logger.logInfo("Libtuxdriver path : (%s)" % library_path)
self.__callback_container = []
self.tux_driver_lib = None
if os.path.isfile(library_path):
try:
self.tux_driver_lib = CDLL(library_path)
+ self.__logger.logInfo("The shared library was found.")
except:
self.tux_driver_lib = None
- txt = "Path (%s) not found ! " % library_path
- print txt + "Tuxdriver is not handled in your application."
+ txt = "Error on handling the library in your application."
+ self.__logger.logError(txt)
else:
- txt = "Path (%s) not found ! " % library_path
- print txt + "Tuxdriver is not handled in your application."
+ txt = "Path (%s) not found !" % library_path
+ self.__logger.logError(txt)
+ txt = "The shared library was not handled in your application."
+ self.__logger.logError(txt)
#
--------------------------------------------------------------------------
# Register a callback function to the "status" event.
@@ -250,7 +265,9 @@
if self.tux_driver_lib == None:
return
+ self.__logger.logInfo("Start the library.")
self.tux_driver_lib.TuxDrv_Start()
+ self.__logger.logInfo("The library has been stopped.")
#
--------------------------------------------------------------------------
# Stop libtuxdriver.
@@ -261,6 +278,7 @@
if self.tux_driver_lib == None:
return
+ self.__logger.logInfo("Stop the library.")
self.tux_driver_lib.TuxDrv_Stop()
#
--------------------------------------------------------------------------
@@ -278,6 +296,11 @@
ret = self.tux_driver_lib.TuxDrv_PerformCommand(c_double(delay),
c_char_p(command))
+ self.__logger.logDebug("Perform the cmd : cmd(%s) delay (%f)" % \
+ (command, delay))
+ self.__logger.logDebug("Returned : code(%s) expl(%s)" % (str(ret),
+ self.StrError(ret)))
+
return ret
#
--------------------------------------------------------------------------
@@ -293,6 +316,10 @@
ret = self.tux_driver_lib.TuxDrv_PerformMacroFile(c_char_p(file_path))
+ self.__logger.logDebug("Perform a macro : path(%s)" % file_path)
+ self.__logger.logDebug("Returned : code(%s) expl(%s)" % (str(ret),
+ self.StrError(ret)))
+
return ret
#
--------------------------------------------------------------------------
@@ -308,6 +335,12 @@
ret = self.tux_driver_lib.TuxDrv_PerformMacroText(c_char_p(macro))
+ self.__logger.logDebug("Perform a macro text : -->")
+ for line in macro.split('\n'):
+ self.__logger.logDebug("%s" % line)
+ self.__logger.logDebug("Returned : code(%s) expl(%s)" % (str(ret),
+ self.StrError(ret)))
+
return ret
#
--------------------------------------------------------------------------
@@ -321,6 +354,8 @@
self.tux_driver_lib.TuxDrv_ClearCommandStack()
+ self.__logger.logDebug("Clear the commands stack")
+
return
#
--------------------------------------------------------------------------
@@ -336,6 +371,12 @@
ret = self.tux_driver_lib.TuxDrv_SoundReflash(c_char_p(tracks))
+ self.__logger.logDebug("Sound refash : -->")
+ for line in tracks.split("\n"):
+ self.__logger.logDebug(line)
+ self.__logger.logDebug("Returned : code(%s) expl(%s)" % (str(ret),
+ self.StrError(ret)))
+
return ret
#
--------------------------------------------------------------------------
@@ -353,6 +394,11 @@
idcp = pointer(idc)
ret = self.tux_driver_lib.TuxDrv_GetStatusId(c_char_p(name), idcp)
+ self.__logger.logDebug("Get status id : (%s) -> (%d)" % (name,
+ idc.value))
+ self.__logger.logDebug("Returned : code(%s) expl(%s)" % (str(ret),
+ self.StrError(ret)))
+
if ret != E_TUXDRV_NOERROR:
idc.value = -1
@@ -374,6 +420,11 @@
c_char_p(result))
result = result.replace(" ", "")
+ self.__logger.logDebug("Get status name : (%d) -> (%s)" % (id,
+ result))
+ self.__logger.logDebug("Returned : code(%s) expl(%s)" % (str(ret),
+ self.StrError(ret)))
+
if ret == E_TUXDRV_NOERROR:
return result
else:
@@ -391,6 +442,7 @@
return
self.tux_driver_lib.TuxDrv_SetLogLevel(c_uint8(level))
+ self.__logger.setLevel(level)
#
--------------------------------------------------------------------------
# Set the target of the internal logger of the libtuxdriver library.
@@ -420,6 +472,11 @@
c_char_p(result))
result = result.replace(" ", "")
+ self.__logger.logDebug("Get status state : (%d) -> (%s)" % (id,
+ result))
+ self.__logger.logDebug("Returned : code(%s) expl(%s)" % (str(ret),
+ self.StrError(ret)))
+
if ret == E_TUXDRV_NOERROR:
return result
else:
@@ -441,6 +498,11 @@
c_char_p(result))
result = result.replace(" ", "")
+ self.__logger.logDebug("Get status value : (%d) -> (%s)" % (id,
+ result))
+ self.__logger.logDebug("Returned : code(%s) expl(%s)" % (str(ret),
+ self.StrError(ret)))
+
if ret == E_TUXDRV_NOERROR:
return result
else:
@@ -460,6 +522,12 @@
self.tux_driver_lib.TuxDrv_GetAllStatusState(c_char_p(result))
result = result.replace(" ", "")
+ self.__logger.logDebug("Get all statuses state : -->")
+ for line in result.split("\n"):
+ self.__logger.logDebug(line)
+ self.__logger.logDebug("Returned : code(%s) expl(%s)" % (str(ret),
+ self.StrError(ret)))
+
return result
#
--------------------------------------------------------------------------
@@ -490,6 +558,8 @@
self.tux_driver_lib.TuxDrv_ResetPositions()
+ self.__logger.logDebug("Reset the motor positions.")
+
return
#
--------------------------------------------------------------------------
@@ -503,6 +573,8 @@
self.tux_driver_lib.TuxDrv_ResetDongle()
+ self.__logger.logDebug("Reset the dongle.")
+
return
#
--------------------------------------------------------------------------
@@ -524,7 +596,8 @@
return result
status_s = self.TokenizeStatus(status)
- if len(status_s) == 0:
+ if len(status_s) != 4:
+ self.__logger.logError("Error in status structure : (%s)" % status)
return result
result['name'] = status_s[0]
------------------------------------------------------------------------------
SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada.
The future of the web can't happen without you. Join us at MIX09 to help
pave the way to the Next Web now. Learn more and register at
http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/
_______________________________________________
Tux-droid-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tux-droid-svn