Author: remi
Date: 2009-04-12 22:14:25 +0200 (Sun, 12 Apr 2009)
New Revision: 4495
Modified:
softwares_suite_v3/kysoh/tuxware/api/python/trunk/tuxisalive/api/base/ApiBaseChild.py
softwares_suite_v3/kysoh/tuxware/api/python/trunk/tuxisalive/api/base/ApiBaseChildResource.py
softwares_suite_v3/kysoh/tuxware/api/python/trunk/tuxisalive/api/base/lib/Helper.py
softwares_suite_v3/kysoh/tuxware/api/python/trunk/tuxisalive/api/gadgets/Gadget.py
softwares_suite_v3/kysoh/tuxware/api/python/trunk/tuxisalive/api/gadgets/GadgetDescription.py
softwares_suite_v3/kysoh/tuxware/api/python/trunk/tuxisalive/api/tuxdroid/Framework.py
softwares_suite_v3/kysoh/tuxware/api/python/trunk/tuxisalive/api/tuxdroid/const/ConstFramework.py
Log:
* implemented the configurations of gadgets
* fixed some encoding problems
Modified:
softwares_suite_v3/kysoh/tuxware/api/python/trunk/tuxisalive/api/base/ApiBaseChild.py
===================================================================
---
softwares_suite_v3/kysoh/tuxware/api/python/trunk/tuxisalive/api/base/ApiBaseChild.py
2009-04-12 20:13:39 UTC (rev 4494)
+++
softwares_suite_v3/kysoh/tuxware/api/python/trunk/tuxisalive/api/base/ApiBaseChild.py
2009-04-12 20:14:25 UTC (rev 4495)
@@ -14,6 +14,8 @@
"""Base class to add functionalities in the API.
"""
+ __ENCODING = "latin-1"
+
#
--------------------------------------------------------------------------
# Constructor of the class.
#
--------------------------------------------------------------------------
@@ -24,7 +26,6 @@
Helper.__init__(self)
self.__apiBase = apiBase
self.__eventsHandler = self.__apiBase.getEventsHandler()
- self.__encoding = "latin-1"
self.__methodsList = []
oElementsList = dir(self)
self.__methodsList.append("__init__")
@@ -60,7 +61,7 @@
@param encoding: source encoding
example : "latin-1", "utf-8", "cp1252", ...
"""
- self.__encoding = encoding
+ ApiBaseChild.__ENCODING = encoding
#
--------------------------------------------------------------------------
# Set the current console encoding.
@@ -70,7 +71,7 @@
(Only if the api run in an interactive python context)
"""
import sys
- self.__encoding = sys.stdin.encoding
+ ApiBaseChild.__ENCODING = sys.stdin.encoding
#
--------------------------------------------------------------------------
# Fixe a text with the correct encoding.
@@ -83,7 +84,7 @@
"""
# Try to encode the string
try:
- text = text.decode(self.__encoding)
+ text = text.decode(ApiBaseChild.__ENCODING)
text = text.encode("utf-8", 'replace')
except:
pass
Modified:
softwares_suite_v3/kysoh/tuxware/api/python/trunk/tuxisalive/api/base/ApiBaseChildResource.py
===================================================================
---
softwares_suite_v3/kysoh/tuxware/api/python/trunk/tuxisalive/api/base/ApiBaseChildResource.py
2009-04-12 20:13:39 UTC (rev 4494)
+++
softwares_suite_v3/kysoh/tuxware/api/python/trunk/tuxisalive/api/base/ApiBaseChildResource.py
2009-04-12 20:14:25 UTC (rev 4495)
@@ -46,6 +46,8 @@
"""
result = ""
if len(parameters.keys()) > 0:
+ for key in parameters.keys():
+ parameters[key] = self._reencodeText(parameters[key])
result = urllib.urlencode(parameters)
return result
Modified:
softwares_suite_v3/kysoh/tuxware/api/python/trunk/tuxisalive/api/base/lib/Helper.py
===================================================================
---
softwares_suite_v3/kysoh/tuxware/api/python/trunk/tuxisalive/api/base/lib/Helper.py
2009-04-12 20:13:39 UTC (rev 4494)
+++
softwares_suite_v3/kysoh/tuxware/api/python/trunk/tuxisalive/api/base/lib/Helper.py
2009-04-12 20:14:25 UTC (rev 4495)
@@ -5,6 +5,8 @@
# Distributed under the terms of the GNU General Public License
# http://www.gnu.org/copyleft/gpl.html
+import sys
+
#
------------------------------------------------------------------------------
# Helper class.
#
------------------------------------------------------------------------------
@@ -49,6 +51,12 @@
print header
print "".join("=" * len(header))
for i, st in enumerate(list):
+ # Try to encode the string
+ try:
+ st = st.decode("utf-8")
+ st = st.encode(sys.stdin.encoding, 'replace')
+ except:
+ pass
print " %.2d : %s" % (i, st)
print ""
Modified:
softwares_suite_v3/kysoh/tuxware/api/python/trunk/tuxisalive/api/gadgets/Gadget.py
===================================================================
---
softwares_suite_v3/kysoh/tuxware/api/python/trunk/tuxisalive/api/gadgets/Gadget.py
2009-04-12 20:13:39 UTC (rev 4494)
+++
softwares_suite_v3/kysoh/tuxware/api/python/trunk/tuxisalive/api/gadgets/Gadget.py
2009-04-12 20:14:25 UTC (rev 4495)
@@ -28,6 +28,10 @@
ApiBaseChildResource.__init__(self, apiBase, apiBaseServer)
self.__parent = parent
self.__description = GadgetDescription(self,
infosStructure['description'])
+ if infosStructure['is_configuration'] == "true":
+ self.__isConfiguration = True
+ else:
+ self.__isConfiguration = False
self.__parameters = []
for key in infosStructure['parameters'].keys():
self.__parameters.append(GadgetParameter(self,
@@ -149,6 +153,15 @@
return result
#
--------------------------------------------------------------------------
+ # Get if the Gadget object is a configuration or an original gadget.
+ #
--------------------------------------------------------------------------
+ def isConfiguration(self):
+ """Get if the Gadget object is a configuration or an original gadget.
+ @return: True or False.
+ """
+ return self.__isConfiguration
+
+ #
--------------------------------------------------------------------------
# Start this gadget.
#
--------------------------------------------------------------------------
def startAsync(self, command = None, parameters = {}):
@@ -294,3 +307,81 @@
argsToSend['gadget_uuid'] = self.__description.getUuid()
cmd = "task_creation/stop_gadget?"
return self._sendCommandBooleanResult(cmd, argsToSend)
+
+ #
--------------------------------------------------------------------------
+ # Create a configured gadget from this gadget.
+ #
--------------------------------------------------------------------------
+ def createConfiguration(self, name = None, parameters = {}):
+ """Create a configured gadget from this gadget.
+ @param name: Name of the configuration.
+ if name is None, the gadget name is set.
+ @param parameters: Parameters of the gadget as dictionary.
+ if no parameter is defined the default ones are set.
+ if a parameter is wrong or missing the default one is set.
+ @return: The success of the configuration creation.
+ """
+ if name == None:
+ name = self.getDescription().getTranslatedName()
+ if not self._checkObjectType('name', name, 'str'):
+ return False
+ if not self._checkObjectType('parameters', parameters, 'dict'):
+ return False
+ args = ""
+ for key in parameters.keys():
+ args += "%s=%s|" % (key, parameters[key])
+ if len(args) > 0:
+ args = args[:-1]
+ argsToSend = {
+ 'uuid' : self.__description.getUuid(),
+ 'name' : name,
+ 'parameters' : args,
+ }
+ cmd = "gadget_framework/create_configuration?"
+ return self._sendCommandBooleanResult(cmd, argsToSend)
+
+ #
--------------------------------------------------------------------------
+ # Update the name of the configured gadget.
+ #
--------------------------------------------------------------------------
+ def updateName(self, name):
+ """Update the name of the configured gadget.
+ @param name: Gadget name.
+ @return: The success of the command.
+ * This method only work with a configured gadget.
+ """
+ if not self.isConfiguration():
+ return False
+ if not self._checkObjectType('name', name, 'str'):
+ return False
+ argsToSend = {
+ 'uuid' : self.__description.getUuid(),
+ 'name' : name,
+ }
+ cmd = "gadget_framework/update_configuration_name?"
+ return self._sendCommandBooleanResult(cmd, argsToSend)
+
+ #
--------------------------------------------------------------------------
+ # Update the parameters of the configured gadget.
+ #
--------------------------------------------------------------------------
+ def updateParameters(self, parameters = {}):
+ """Update the parameters of the configured gadget.
+ @param parameters: Parameters of the gadget as dictionary.
+ if no parameter is defined the default ones are set.
+ if a parameter is wrong or missing the default one is set.
+ @return: The success of the command.
+ * This method only work with a configured gadget.
+ """
+ if not self.isConfiguration():
+ return False
+ if not self._checkObjectType('parameters', parameters, 'dict'):
+ return False
+ args = ""
+ for key in parameters.keys():
+ args += "%s=%s|" % (key, parameters[key])
+ if len(args) > 0:
+ args = args[:-1]
+ argsToSend = {
+ 'uuid' : self.__description.getUuid(),
+ 'parameters' : args,
+ }
+ cmd = "gadget_framework/update_configuration_parameters?"
+ return self._sendCommandBooleanResult(cmd, argsToSend)
Modified:
softwares_suite_v3/kysoh/tuxware/api/python/trunk/tuxisalive/api/gadgets/GadgetDescription.py
===================================================================
---
softwares_suite_v3/kysoh/tuxware/api/python/trunk/tuxisalive/api/gadgets/GadgetDescription.py
2009-04-12 20:13:39 UTC (rev 4494)
+++
softwares_suite_v3/kysoh/tuxware/api/python/trunk/tuxisalive/api/gadgets/GadgetDescription.py
2009-04-12 20:14:25 UTC (rev 4495)
@@ -134,6 +134,10 @@
descList.append("%s = %s" % ('Translated name',
self.getTranslatedName()))
descList.append("%s = %s" % ('TTS name', self.getTtsName()))
descList.append("%s = %s" % ('Uuid', self.getUuid()))
+ if self.getParent().isConfiguration():
+ descList.append("%s = %s" % ('Is configuration', "True"))
+ else:
+ descList.append("%s = %s" % ('Is configuration', "False"))
descList.append("%s = %s" % ('Description', self.getDescription()))
descList.append("%s = %s" % ('Author', self.getAuthor()))
descList.append("%s = %s" % ('Version', self.getVersion()))
Modified:
softwares_suite_v3/kysoh/tuxware/api/python/trunk/tuxisalive/api/tuxdroid/Framework.py
===================================================================
---
softwares_suite_v3/kysoh/tuxware/api/python/trunk/tuxisalive/api/tuxdroid/Framework.py
2009-04-12 20:13:39 UTC (rev 4494)
+++
softwares_suite_v3/kysoh/tuxware/api/python/trunk/tuxisalive/api/tuxdroid/Framework.py
2009-04-12 20:14:25 UTC (rev 4495)
@@ -33,6 +33,8 @@
self.__gadgetsContainer = GadgetsContainer(apiBase, apiBaseServer, {})
self._registerEvent(ST_NAME_FW_CONTAINER_DEPLOYED, None,
self.__updateGadgetsContainer)
+ self._registerEvent(ST_NAME_FW_CONFIGURATIONS_LOADED, None,
+ self.__updateGadgetsContainer)
#
--------------------------------------------------------------------------
# Get the gadgets container.
Modified:
softwares_suite_v3/kysoh/tuxware/api/python/trunk/tuxisalive/api/tuxdroid/const/ConstFramework.py
===================================================================
---
softwares_suite_v3/kysoh/tuxware/api/python/trunk/tuxisalive/api/tuxdroid/const/ConstFramework.py
2009-04-12 20:13:39 UTC (rev 4494)
+++
softwares_suite_v3/kysoh/tuxware/api/python/trunk/tuxisalive/api/tuxdroid/const/ConstFramework.py
2009-04-12 20:14:25 UTC (rev 4495)
@@ -10,9 +10,13 @@
ST_NAME_FW_CONTAINER_DEPLOYED = "framework_container_deployed"
ST_NAME_FW_GADGET_STARTING = "framework_gadget_starting"
ST_NAME_FW_GADGET_STOPPED = "framework_gadget_stopped"
+ST_NAME_FW_CONFIGURATIONS_LOADED = "framework_configurations_loaded"
+ST_NAME_FW_CONFIGURATIONS_UNLOADED = "framework_configurations_unloaded"
SW_NAME_FRAMEWORK = [
ST_NAME_FW_RUN,
ST_NAME_FW_CONTAINER_DEPLOYED,
ST_NAME_FW_GADGET_STARTING,
ST_NAME_FW_GADGET_STOPPED,
+ ST_NAME_FW_CONFIGURATIONS_LOADED,
+ ST_NAME_FW_CONFIGURATIONS_UNLOADED,
]
------------------------------------------------------------------------------
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