Author: remi
Date: 2009-03-23 22:33:19 +0100 (Mon, 23 Mar 2009)
New Revision: 4196
Added:
software_suite_v2/software/gadgets/tuxdroid-gadget-system/trunk/tuxdroid-gadget-system/executables/GadgetHelper.py
Modified:
software_suite_v2/software/gadgets/tuxdroid-gadget-system/trunk/tuxdroid-gadget-system/executables/tuxdroid-gadget-system.py
software_suite_v2/software/gadgets/tuxdroid-gadget-system/trunk/tuxdroid-gadget-system/resources/gadget.pot
Log:
* added GadgetHelper class.
* this gadget now uses the GadgetHelper.throwMessage function in order to send
messages with a correct format to framework.
* fixed a bug in the pot file.
Added:
software_suite_v2/software/gadgets/tuxdroid-gadget-system/trunk/tuxdroid-gadget-system/executables/GadgetHelper.py
===================================================================
---
software_suite_v2/software/gadgets/tuxdroid-gadget-system/trunk/tuxdroid-gadget-system/executables/GadgetHelper.py
(rev 0)
+++
software_suite_v2/software/gadgets/tuxdroid-gadget-system/trunk/tuxdroid-gadget-system/executables/GadgetHelper.py
2009-03-23 21:33:19 UTC (rev 4196)
@@ -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-system/trunk/tuxdroid-gadget-system/executables/GadgetHelper.py
___________________________________________________________________
Name: svn:keywords
+ Id
Modified:
software_suite_v2/software/gadgets/tuxdroid-gadget-system/trunk/tuxdroid-gadget-system/executables/tuxdroid-gadget-system.py
===================================================================
---
software_suite_v2/software/gadgets/tuxdroid-gadget-system/trunk/tuxdroid-gadget-system/executables/tuxdroid-gadget-system.py
2009-03-23 21:30:21 UTC (rev 4195)
+++
software_suite_v2/software/gadgets/tuxdroid-gadget-system/trunk/tuxdroid-gadget-system/executables/tuxdroid-gadget-system.py
2009-03-23 21:33:19 UTC (rev 4196)
@@ -28,6 +28,8 @@
import subprocess
import string
from time import sleep
+
+from GadgetHelper import GadgetHelper
class pcMonitor(object):
@@ -80,9 +82,9 @@
if self.tgp_useCpuThreshold:
#check threshold.
if (float(cpu) > float(self.tgp_cpuThreshold)):
- print("message \"c p u meltdown\"")
+ GadgetHelper.throwMessage("c p u meltdown")
else:
- print("message \"Your c p u load is " + str(cpu) + " percent\"")
+ GadgetHelper.throwMessage("Your c p u load is {0} percent", cpu)
#Getting memory use.
@@ -94,9 +96,9 @@
if self.tgp_useMemThreshold:
if (float(memory) > float(self.tgp_memThreshold)):
- print("message \"memory is up\"")
+ GadgetHelper.throwMessage("memory is up")
else:
- print("message \"Your used memory is " + str(memory) + "
percent\"")
+ GadgetHelper.throwMessage("Your used memory is {0} percent",
memory)
Modified:
software_suite_v2/software/gadgets/tuxdroid-gadget-system/trunk/tuxdroid-gadget-system/resources/gadget.pot
===================================================================
---
software_suite_v2/software/gadgets/tuxdroid-gadget-system/trunk/tuxdroid-gadget-system/resources/gadget.pot
2009-03-23 21:30:21 UTC (rev 4195)
+++
software_suite_v2/software/gadgets/tuxdroid-gadget-system/trunk/tuxdroid-gadget-system/resources/gadget.pot
2009-03-23 21:33:19 UTC (rev 4196)
@@ -10,7 +10,7 @@
msgid "Your c p u load is {0} percent"
msgstr ""
-msgid "Your used memory is {0] percent"
+msgid "Your used memory is {0} percent"
msgstr ""
msgid "Enable CPU threshold message"
------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
_______________________________________________
Tux-droid-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tux-droid-svn