Author: jerome
Date: 2009-04-15 11:12:23 +0200 (Wed, 15 Apr 2009)
New Revision: 4509
Added:
software_suite_v2/software/gadgets/tuxdroid-gadget-maxlight/trunk/executables/GadgetHelper.py
Modified:
software_suite_v2/software/gadgets/tuxdroid-gadget-maxlight/trunk/executables/tuxdroid-gadget-maxlight.py
Log:
*Added GadgetHelper
Added:
software_suite_v2/software/gadgets/tuxdroid-gadget-maxlight/trunk/executables/GadgetHelper.py
===================================================================
---
software_suite_v2/software/gadgets/tuxdroid-gadget-maxlight/trunk/executables/GadgetHelper.py
(rev 0)
+++
software_suite_v2/software/gadgets/tuxdroid-gadget-maxlight/trunk/executables/GadgetHelper.py
2009-04-15 09:12:23 UTC (rev 4509)
@@ -0,0 +1,94 @@
+# Copyright (C) 2009 C2ME Sa
+# Remi Jocaille <[email protected]>
+# Distributed under the terms of the GNU General Public License
+# http://www.gnu.org/copyleft/gpl.html
+
+import sys
+import traceback
+import platform
+
+#
------------------------------------------------------------------------------
+# This class is the minimal helper for builder python gadgets.
+# It's an alternative to the SimpleGadget helper.
+#
------------------------------------------------------------------------------
+class GadgetHelper(object):
+ """This class is the minimal helper for builder python gadgets.
+ It's an alternative to the SimpleGadget helper.
+ """
+
+ #
--------------------------------------------------------------------------
+ # Get if the platform is Windows or not.
+ #
--------------------------------------------------------------------------
+ def isWindows():
+ """Get if the platform is Windows or not.
+ @return: A boolean.
+ """
+ platformName = platform.system().lower()
+ return (platformName == "microsoft") or (platformName == "windows")
+
+ #
--------------------------------------------------------------------------
+ # Throw a generic notification to the framework.
+ #
--------------------------------------------------------------------------
+ def throwNotification(messageId, *args):
+ """Throw a generic notification to the framework.
+ @param messageId: Message Id.
+ @param args: List of objects.
+ """
+ stringBuffer = messageId
+ for arg in args:
+ stringBuffer += " '"
+ stringBuffer += str(arg).replace("'", "\\'")
+ stringBuffer += "'"
+ sys.stdout.write(stringBuffer + "\n")
+ sys.stdout.flush()
+
+ #
--------------------------------------------------------------------------
+ # Throw a message to the framework.
+ #
--------------------------------------------------------------------------
+ def throwMessage(content, *args):
+ """Throw a message to the framework.
+ @param content: Content of the message.
+ @param args: Arguments for the message.
+ """
+ tmp = [content,]
+ for arg in args:
+ tmp.append(arg)
+ GadgetHelper.throwNotification("message", *tmp)
+
+ #
--------------------------------------------------------------------------
+ # Throw a trace message to the framework.
+ #
--------------------------------------------------------------------------
+ def throwTrace(message):
+ """Throw a trace message to the framework.
+ @param message: Throwed message.
+ """
+ GadgetHelper.throwNotification("trace", message)
+
+ #
--------------------------------------------------------------------------
+ # Throw an error message to the framework.
+ #
--------------------------------------------------------------------------
+ def throwError(message, sendTraceback = False):
+ """Throw an error message to the framework.
+ @param message: Thowed message if the gadget don't want to be traced.
+ @param sendTraceback: For to send the traceback. Default False.
+ """
+ def formatException():
+ fList = traceback.format_exception(sys.exc_info()[0],
+ sys.exc_info()[1],
+ sys.exc_info()[2])
+ result = ""
+ for line in fList:
+ result += line
+ return result
+ messagesList = [message,]
+ if sendTraceback:
+ tmpList = formatException().split("\n")
+ for line in tmpList:
+ messagesList.append(line)
+ GadgetHelper.throwNotification("error", *messagesList)
+
+ isWindows = staticmethod(isWindows)
+ throwNotification = staticmethod(throwNotification)
+ throwMessage = staticmethod(throwMessage)
+ throwTrace = staticmethod(throwTrace)
+ throwError = staticmethod(throwError)
Property changes on:
software_suite_v2/software/gadgets/tuxdroid-gadget-maxlight/trunk/executables/GadgetHelper.py
___________________________________________________________________
Name: svn:executable
+ *
Modified:
software_suite_v2/software/gadgets/tuxdroid-gadget-maxlight/trunk/executables/tuxdroid-gadget-maxlight.py
===================================================================
---
software_suite_v2/software/gadgets/tuxdroid-gadget-maxlight/trunk/executables/tuxdroid-gadget-maxlight.py
2009-04-15 08:51:33 UTC (rev 4508)
+++
software_suite_v2/software/gadgets/tuxdroid-gadget-maxlight/trunk/executables/tuxdroid-gadget-maxlight.py
2009-04-15 09:12:23 UTC (rev 4509)
@@ -66,13 +66,7 @@
import gettext
from tuxisalive.api import *
from time import sleep
-
-
-def message(mes):
- '''
- Get message from langage dictionary
- '''
- print "message \"" + mes + "\""
+from GadgetHelper import GadgetHelper
def tuxConnect():
@@ -129,8 +123,7 @@
tux.spinning.off()
break
- message("Light up is here")
- message(str(int(lum)) + "%%")
+ GadgetHelper.throwMessage("Light up is here {0}", str(int(lum)) + "%%")
tgp_language = "en"
@@ -154,7 +147,7 @@
# Test if charger are plugged
if tux.status.requestOne('charger_state')[0] == 'UNPLUGGED':
- message("I begun the research")
+ GadgetHelper.throwMessage("I begun the research")
tux.eyes.open()
tux.flippers.up()
light = search() # search light up
@@ -162,7 +155,7 @@
tux.flippers.down()
else:
- message("Unplug the charger and restart the program")
+ GadgetHelper.throwMessage("Unplug the charger and restart the program")
tux.access.release()
tux.server.disconnect()
------------------------------------------------------------------------------
This SF.net email is sponsored by:
High Quality Requirements in a Collaborative Environment.
Download a free trial of Rational Requirements Composer Now!
http://p.sf.net/sfu/www-ibm-com
_______________________________________________
Tux-droid-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tux-droid-svn