Author: remi
Date: 2008-09-17 13:35:45 +0200 (Wed, 17 Sep 2008)
New Revision: 1869

Modified:
   
software_suite_v2/tuxware/pytuxisalive/trunk/src/tuxisalive/api/TuxAPIStatus.py
Log:
* added "tux.status.send" function

Modified: 
software_suite_v2/tuxware/pytuxisalive/trunk/src/tuxisalive/api/TuxAPIStatus.py
===================================================================
--- 
software_suite_v2/tuxware/pytuxisalive/trunk/src/tuxisalive/api/TuxAPIStatus.py 
    2008-09-17 11:34:37 UTC (rev 1868)
+++ 
software_suite_v2/tuxware/pytuxisalive/trunk/src/tuxisalive/api/TuxAPIStatus.py 
    2008-09-17 11:35:45 UTC (rev 1869)
@@ -11,6 +11,7 @@
 #    R�mi Jocaille <[EMAIL PROTECTED]>
 #    Distributed under the terms of the GNU General Public License
 #    http://www.gnu.org/copyleft/gpl.html
+import urllib
 
 from TuxAPIMisc import checkValue
 from TuxAPIExceptionCL import TuxAPIExceptionCL
@@ -50,6 +51,48 @@
                 return varResult["value"], varResult["delay"]
         return None, None
     
+    def send(self, statusName, statusValues, encoding = "latin-1"):
+        """Send a status.
+        
+        @param statusName: name of the status.
+        @param statusValues: values of the status as list.
+        @param encoding: encoding format of the source.
+            ( By example, the encoding must be set with sys.stdin.encoding if
+              the status is sent from Tuxshell. The encoding must be set to 
+              "utf-8" if the status is sent from a python script coded in 
utf-8)
+        @return: the success of the command.
+        """
+        if not checkValue(statusName, "str"):
+            return False
+        if not checkValue(statusValues, "list"):
+            return False
+        if len(statusValues) == 0:
+            return False
+        for statusValue in statusValues:
+            if not checkValue(statusValue, "str"):
+                return False
+        valuesStr = ""
+        for statusValue in statusValues:
+            valuesStr += "%s|" % statusValue
+        valuesStr = valuesStr[:-1]
+        try:
+            u = unicode(valuesStr, encoding)
+            valuesStr = u.encode("latin-1", 'replace')
+        except:
+            pass
+        try:
+            u = statusName.decode(encoding)
+            statusName = u.encode("latin-1", 'replace')
+        except:
+            pass
+        pcmd = urllib.urlencode({'name' : statusName, 'value' : valuesStr,})
+        cmd = "status/send?%s" % pcmd
+        if self.__parent != None:
+            # Request
+            if self.__parent.server.request(cmd, {}, {}):
+                return True
+        return False
+    
     def wait(self, statusName, condition = None, timeout = 999999999.0):
         """Wait a specific state of a status.
         Not available for CLIENT_LEVEL_ANONYME level.


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Tux-droid-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tux-droid-svn

Reply via email to