Author: remi
Date: 2009-04-12 22:13:39 +0200 (Sun, 12 Apr 2009)
New Revision: 4494

Added:
   
softwares_suite_v3/kysoh/tuxware/server/trunk/util/applicationserver/gadget/ConfiguredGadget.py
Modified:
   
softwares_suite_v3/kysoh/tuxware/server/trunk/resources/01_robot_system/resourceGadgetFramework.py
   
softwares_suite_v3/kysoh/tuxware/server/trunk/resources/03_advanced_api/resourceUserConfiguration.py
   
softwares_suite_v3/kysoh/tuxware/server/trunk/util/applicationserver/gadget/Gadget.py
   
softwares_suite_v3/kysoh/tuxware/server/trunk/util/applicationserver/gadget/GadgetDescription.py
   
softwares_suite_v3/kysoh/tuxware/server/trunk/util/applicationserver/gadget/GadgetParameter.py
   
softwares_suite_v3/kysoh/tuxware/server/trunk/util/applicationserver/gadget/GadgetsContainer.py
   
softwares_suite_v3/kysoh/tuxware/server/trunk/util/applicationserver/gadget/WebGadgetTools.py
Log:
* implemented the configurations of gadgets

Modified: 
softwares_suite_v3/kysoh/tuxware/server/trunk/resources/01_robot_system/resourceGadgetFramework.py
===================================================================
--- 
softwares_suite_v3/kysoh/tuxware/server/trunk/resources/01_robot_system/resourceGadgetFramework.py
  2009-04-12 13:42:17 UTC (rev 4493)
+++ 
softwares_suite_v3/kysoh/tuxware/server/trunk/resources/01_robot_system/resourceGadgetFramework.py
  2009-04-12 20:13:39 UTC (rev 4494)
@@ -4,6 +4,7 @@
 
 from util.applicationserver.gadget.GadgetsContainer import GadgetsContainer
 from util.applicationserver.gadget.Gadget import SUPPORTED_LANGUAGES_LIST
+from util.applicationserver.gadget.ConfiguredGadget import *
 from util.applicationserver.gadget.WebGadgetTools import WebGadgetTools
 from util.misc.tuxPaths import TUXDROID_LANGUAGE
 from util.misc.tuxPaths import TUXDROID_DEFAULT_LOCUTOR
@@ -23,6 +24,8 @@
 ST_NAME_FW_GADGET_NOTIFICATION = "framework_gadget_notification"
 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"
 
 # Framework events/statuses list
 SW_NAME_FRAMEWORK = [
@@ -38,6 +41,8 @@
     ST_NAME_FW_GADGET_NOTIFICATION, # Is not sent to clients
     ST_NAME_FW_GADGET_STARTING, # Is sent to clients
     ST_NAME_FW_GADGET_STOPPED, # Is sent to clients
+    ST_NAME_FW_CONFIGURATIONS_LOADED, # Is sent to clients
+    ST_NAME_FW_CONFIGURATIONS_UNLOADED, # Is sent to clients
 ]
 
 # 
------------------------------------------------------------------------------
@@ -60,6 +65,8 @@
         
self.__gadgetsContainer.setOnGadgetDeployedCallback(self.__onGadgetDeployed)
         
self.__gadgetsContainer.setOnGadgetDeploymentErrorCallback(self.__onGadgetDeploymentError)
         
self.__gadgetsContainer.setOnGadgetUndeployedCallback(self.__onGadgetUndeployed)
+        
self.__gadgetsContainer.setOnConfigurationsLoadedCallback(self.__onConfigurationsLoaded)
+        
self.__gadgetsContainer.setOnConfigurationsUnloadedCallback(self.__onConfigurationsUnloaded)
         # Registering the framework statuses.
         for statusName in SW_NAME_FRAMEWORK:
             eventsHandler.insert(statusName)
@@ -210,6 +217,13 @@
         else:
             self.__publishEvents(True, ST_NAME_FW_GADGET_STOPPED, [uuid, "FW"])
 
+    def __onConfigurationsLoaded(self):
+        self.__publishEvents(True, ST_NAME_FW_CONFIGURATIONS_LOADED, ["True",])
+
+    def __onConfigurationsUnloaded(self):
+        self.__publishEvents(True, ST_NAME_FW_CONFIGURATIONS_UNLOADED,
+            ["True",])
+
     # 
--------------------------------------------------------------------------
     # Private methods
     # 
--------------------------------------------------------------------------
@@ -293,12 +307,68 @@
             return False
         for gadget in self.__gadgetsContainer.getGadgets():
             if gadget.getDescription().getUuid() == gadgetUuid:
-                tgfFile = gadget.getTgfFile()
-                # Remove the tfg file
-                DirectoriesAndFilesTools.RMFile(tgfFile)
+                if gadget.isConfiguration():
+                    self.__gadgetsContainer.removeConfiguration(gadget)
+                else:
+                    tgfFile = gadget.getTgfFile()
+                    # Remove the tfg file
+                    DirectoriesAndFilesTools.RMFile(tgfFile)
+                    
self.__gadgetsContainer.removeConfigurationsByOriginalGadgetUuid(gadgetUuid)
                 return True
         return False
 
+    def createConfiguration(self, gadgetUuid, parameters, name):
+        """Create a configuration of a gadget.
+        @param gadgetUuid: Gadget uuid.
+        @param parameters: Parameters.
+        @param name: Name of the configured gadget.
+        @return: The success.
+        """
+        gadget = self.__gadgetsContainer.getGadgetByUuid(gadgetUuid)
+        if gadget != None:
+            configuredGadget = ConfiguredGadget.createConfiguredGadget(gadget,
+                parameters, name)
+            self.__gadgetsContainer.insertConfiguration(configuredGadget)
+            return True
+        else:
+            return False
+
+    def updateConfigurationName(self, gadgetUuid, name):
+        """Update the name of a configured gadget.
+        @param gadgetUuid: Gadget uuid.
+        @param name: Name of the configured gadget.
+        @return: The success.
+        """
+        gadget = self.__gadgetsContainer.getGadgetByUuid(gadgetUuid)
+        if gadget != None:
+            if not gadget.isConfiguration():
+                return False
+            gadget.updateName(name)
+            self.__gadgetsContainer.storeConfiguration(gadget)
+            self.__publishEvents(True, ST_NAME_FW_CONFIGURATIONS_LOADED,
+                ["True",])
+            return True
+        else:
+            return False
+
+    def updateConfigurationParameters(self, gadgetUuid, parameters):
+        """Update the parameters of a configured gadget.
+        @param gadgetUuid: Gadget uuid.
+        @param parameters: Parameters.
+        @return: The success.
+        """
+        gadget = self.__gadgetsContainer.getGadgetByUuid(gadgetUuid)
+        if gadget != None:
+            if not gadget.isConfiguration():
+                return False
+            gadget.updateParameters(parameters)
+            self.__gadgetsContainer.storeConfiguration(gadget)
+            self.__publishEvents(True, ST_NAME_FW_CONFIGURATIONS_LOADED,
+                ["True",])
+            return True
+        else:
+            return False
+
     def startGadget(self, gadgetUuid, command, parameters):
         """Start a gadget.
         @param gadgetUuid: Gadget uuid.
@@ -333,6 +403,7 @@
     def configure(self):
         self.parametersDict = {
             'gadgets_path' : 'string',
+            'configurations_path' : 'string',
             'language' : 'string',
             'country' : 'string',
             'locutor' : 'string',
@@ -374,6 +445,8 @@
             resourceGadgetFramework.logger.logInfo("Deploy the gadgets 
container.")
             gadgetsContainer.deploy()
             resourceGadgetFramework.logger.logInfo("Gadgets container is 
deployed.")
+            # Load the configurations
+            
gadgetsContainer.loadConfigurations(parameters['configurations_path'])
             resourceGadgetFramework.publishEvents(True, ST_NAME_FW_RUN,
                 ["True",])
         return headersStruct, contentStruct
@@ -740,3 +813,100 @@
 # Register the service into the resource
 resourceGadgetFramework.addService(TDSServiceGadgetFrameworkRemoveGadget)
 
+# 
------------------------------------------------------------------------------
+# Declaration of the service "create_configuration".
+# 
------------------------------------------------------------------------------
+class TDSServiceGadgetFrameworkCreateConfiguration(TDSService):
+
+    def configure(self):
+        self.parametersDict = {
+            'uuid' : 'string',
+            'parameters' : 'string',
+            'name' : 'string',
+        }
+        self.minimalUserLevel = TDS_CLIENT_LEVEL_ANONYMOUS
+        self.exclusiveExecution = False
+        self.name = "create_configuration"
+        self.comment = "Create a configuration of gadget."
+
+    def execute(self, id, parameters):
+        headersStruct = self.getDefaultHeadersStruct()
+        contentStruct = self.getDefaultContentStruct()
+        contentStruct['root']['result'] = getStrError(E_TDREST_SUCCESS)
+        uuid = parameters['uuid']
+        params = {}
+        splParams = parameters['parameters'].split("|")
+        for paramStruct in splParams:
+            param = paramStruct.split("=")
+            if len(param) == 2:
+                params[param[0]] = param[1]
+        name = parameters['name']
+        if not resourceGadgetFramework.createConfiguration(uuid, params,
+            name):
+            contentStruct['root']['result'] = getStrError(E_TDREST_FAILED)
+        return headersStruct, contentStruct
+
+# Register the service into the resource
+resourceGadgetFramework.addService(TDSServiceGadgetFrameworkCreateConfiguration)
+
+# 
------------------------------------------------------------------------------
+# Declaration of the service "update_configuration_name".
+# 
------------------------------------------------------------------------------
+class TDSServiceGadgetFrameworkUpdateConfigurationName(TDSService):
+
+    def configure(self):
+        self.parametersDict = {
+            'uuid' : 'string',
+            'name' : 'string',
+        }
+        self.minimalUserLevel = TDS_CLIENT_LEVEL_ANONYMOUS
+        self.exclusiveExecution = False
+        self.name = "update_configuration_name"
+        self.comment = "Update the name of a configuration."
+
+    def execute(self, id, parameters):
+        headersStruct = self.getDefaultHeadersStruct()
+        contentStruct = self.getDefaultContentStruct()
+        contentStruct['root']['result'] = getStrError(E_TDREST_SUCCESS)
+        uuid = parameters['uuid']
+        name = parameters['name']
+        if not resourceGadgetFramework.updateConfigurationName(uuid, name):
+            contentStruct['root']['result'] = getStrError(E_TDREST_FAILED)
+        return headersStruct, contentStruct
+
+# Register the service into the resource
+resourceGadgetFramework.addService(TDSServiceGadgetFrameworkUpdateConfigurationName)
+
+# 
------------------------------------------------------------------------------
+# Declaration of the service "update_configuration_parameters".
+# 
------------------------------------------------------------------------------
+class TDSServiceGadgetFrameworkUpdateConfigurationParameters(TDSService):
+
+    def configure(self):
+        self.parametersDict = {
+            'uuid' : 'string',
+            'parameters' : 'string',
+        }
+        self.minimalUserLevel = TDS_CLIENT_LEVEL_ANONYMOUS
+        self.exclusiveExecution = False
+        self.name = "update_configuration_parameters"
+        self.comment = "Update the parameters of a configuration."
+
+    def execute(self, id, parameters):
+        headersStruct = self.getDefaultHeadersStruct()
+        contentStruct = self.getDefaultContentStruct()
+        contentStruct['root']['result'] = getStrError(E_TDREST_SUCCESS)
+        uuid = parameters['uuid']
+        params = {}
+        splParams = parameters['parameters'].split("|")
+        for paramStruct in splParams:
+            param = paramStruct.split("=")
+            if len(param) == 2:
+                params[param[0]] = param[1]
+        if not resourceGadgetFramework.updateConfigurationParameters(uuid,
+            params):
+            contentStruct['root']['result'] = getStrError(E_TDREST_FAILED)
+        return headersStruct, contentStruct
+
+# Register the service into the resource
+resourceGadgetFramework.addService(TDSServiceGadgetFrameworkUpdateConfigurationParameters)

Modified: 
softwares_suite_v3/kysoh/tuxware/server/trunk/resources/03_advanced_api/resourceUserConfiguration.py
===================================================================
--- 
softwares_suite_v3/kysoh/tuxware/server/trunk/resources/03_advanced_api/resourceUserConfiguration.py
        2009-04-12 13:42:17 UTC (rev 4493)
+++ 
softwares_suite_v3/kysoh/tuxware/server/trunk/resources/03_advanced_api/resourceUserConfiguration.py
        2009-04-12 20:13:39 UTC (rev 4494)
@@ -51,10 +51,13 @@
             return False
         # User directories
         userGadgetsDir = os.path.join(userDirectory, "MyTuxGadgets")
+        userGadgetsConfigurationsDir = os.path.join(userDirectory,
+            "MyTuxGadgetsConfigurations")
         userAttitunesDir = os.path.join(userDirectory, "MyTuxAttitunes")
         userTasksDir = os.path.join(userDirectory, "MyTuxTasks")
         userLocalesConfigFile = os.path.join(userDirectory, "locales.conf")
         MKDirs(userGadgetsDir)
+        MKDirs(userGadgetsConfigurationsDir)
         MKDirs(userAttitunesDir)
         MKDirs(userTasksDir)
         # Read the locales configuration
@@ -97,6 +100,7 @@
                 'locutor' : userLocalesConfigDict['locutor'],
                 'pitch' : userLocalesConfigDict['pitch'],
                 'gadgets_path' : userGadgetsDir,
+                'configurations_path' : userGadgetsConfigurationsDir,
             }
             resourceGadgetFramework.getService("start").execute(0, parameters)
             # Start the attitune manager

Added: 
softwares_suite_v3/kysoh/tuxware/server/trunk/util/applicationserver/gadget/ConfiguredGadget.py
===================================================================
--- 
softwares_suite_v3/kysoh/tuxware/server/trunk/util/applicationserver/gadget/ConfiguredGadget.py
                             (rev 0)
+++ 
softwares_suite_v3/kysoh/tuxware/server/trunk/util/applicationserver/gadget/ConfiguredGadget.py
     2009-04-12 20:13:39 UTC (rev 4494)
@@ -0,0 +1,252 @@
+#    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 os
+import time
+import random
+
+try:
+    from hashlib import md5
+except:
+    from md5 import md5
+
+from Gadget import Gadget
+
+# 
------------------------------------------------------------------------------
+# ConfiguredGadget class.
+# 
------------------------------------------------------------------------------
+class ConfiguredGadget(Gadget):
+    """ConfiguredGadget class.
+    """
+
+    # 
--------------------------------------------------------------------------
+    # Constructor of the class.
+    # 
--------------------------------------------------------------------------
+    def __init__(self, parent, dictionary, tgfFile, workingPath, 
configuration):
+        """Constructor of the class.
+        @param parent: Parent Gadgets container.
+        @param dictionary: Gadget structure as dictionary.
+        @param tgfFile: TGF file name of the gadget.
+        @param workingPath: Working path of the gadget.
+        @param configuration: Configuration of the gadget.
+        """
+        self.__configuration = configuration
+        # Configure the gadget command
+        configuredCommandName = configuration['command']
+        filteredCommands = {}
+        for key in dictionary['commands'].keys():
+            commandStruct = dictionary['commands'][key]
+            commandName = commandStruct['name']
+            if commandName == configuredCommandName:
+                filteredCommands[key] = dictionary['commands'][key]
+                break
+        dictionary['commands'] = filteredCommands
+        # Create the gadget object
+        Gadget.__init__(self, parent, dictionary, tgfFile, workingPath)
+        # Configure the gadget parameters
+        for parameter in self.getParameters():
+            for key in configuration['parameters'].keys():
+                if key == parameter.getName():
+                    parameter.setDefaultValue(configuration['parameters'][key])
+        # Set the gadget description
+        self.getDescription().setUuid(configuration['description']['uuid'])
+        self.getDescription().setName(configuration['description']['name'])
+        self.getDescription().setTtsName(configuration['description']['name'])
+        # Set the gadget is a configuration
+        self.setIsConfiguration()
+
+    # 
--------------------------------------------------------------------------
+    # Get the original gadget uuid.
+    # 
--------------------------------------------------------------------------
+    def getOriginalUuid(self):
+        """Get the original gadget uuid.
+        @return: The original gadget uuid.
+        """
+        return self.__configuration['originalGadgetUuid']
+
+    # 
--------------------------------------------------------------------------
+    # Get the configuration.
+    # 
--------------------------------------------------------------------------
+    def getConfiguration(self):
+        """Get the configuration.
+        @return: A dictionary.
+        """
+        return self.__configuration
+
+    # 
--------------------------------------------------------------------------
+    # Update the parameter.
+    # 
--------------------------------------------------------------------------
+    def updateParameters(self, parameters):
+        """Update the parameter.
+        @param parameters: Gadget parameters.
+        """
+        self.__configuration['parameters'] = parameters
+        for parameter in self.getParameters():
+            for key in parameters.keys():
+                if key == parameter.getName():
+                    parameter.setDefaultValue(parameters[key])
+
+    # 
--------------------------------------------------------------------------
+    # Update the name.
+    # 
--------------------------------------------------------------------------
+    def updateName(self, name):
+        """Update the name.
+        @param name: Gadget name.
+        """
+        name = ConfiguredGadget.generateSingleName(name, self.getContainer())
+        self.__configuration['description']['name'] = name
+        self.getDescription().setName(name)
+        self.getDescription().setTtsName(name)
+
+    # 
==========================================================================
+    # Static methods
+    # 
==========================================================================
+
+    # 
--------------------------------------------------------------------------
+    # Generate a single id.
+    # 
--------------------------------------------------------------------------
+    def generateSingleUuid():
+        """Generate a single uuid.
+        @return: The single uuid.
+        """
+        baseString = str(time.time() + random.random())
+        md5H = md5()
+        md5H.update(baseString)
+        id = md5H.hexdigest()
+        uuid = id[:8] + '-' + id[8:12] + '-' + id[12:16] + '-' + id[16:20] + \
+            '-'+id[20:]
+        return uuid
+
+    # 
--------------------------------------------------------------------------
+    # Generate a single name.
+    # 
--------------------------------------------------------------------------
+    def generateSingleName(gadgetName, gadgetsContainer):
+        """Generate a single name.
+        @param gadgetName: Requested name.
+        @param gadgetsContainer: GadgetsContainer object.
+        @return: A single name in the gadgets container.
+        """
+        def checkNameExists(nameToCheck):
+            result = False
+            for gadget in gadgetsContainer.getGadgets():
+                if gadget.getDescription().getName() == nameToCheck:
+                    result = True
+                    break
+            return result
+        baseGadgetName = gadgetName
+        if (baseGadgetName.find("(") > 0) and (baseGadgetName.find(")") != -1):
+            baseGadgetName = baseGadgetName[:baseGadgetName.find("(") - 1]
+        if baseGadgetName == "":
+            baseGadgetName = "Default"
+        i = 0
+        while checkNameExists(gadgetName):
+            i += 1
+            gadgetName = "%s (%d)" % (baseGadgetName, i)
+        return gadgetName
+
+    # 
--------------------------------------------------------------------------
+    # Create a configured gadget.
+    # 
--------------------------------------------------------------------------
+    def createConfiguredGadget(gadget, parameters, name):
+        """Create a configured gadget.
+        @param gadget: Gadget parent.
+        @param parameters: Gadget parameters.
+        @param name: Name of the configured gadget.
+        @return: A new ConfiguredGadget object.
+        """
+        parent = gadget.getContainer()
+        dictionary = gadget.getDictionary()
+        tgfFile = gadget.getTgfFile()
+        workingPath = gadget.getWorkingPath()
+        gadgetName = ConfiguredGadget.generateSingleName(name, parent)
+        gadgetUuid = ConfiguredGadget.generateSingleUuid()
+        if gadget.isConfiguration():
+            originalGadgetUuid = gadget.getOriginalUuid()
+        else:
+            originalGadgetUuid = gadget.getDescription().getUuid()
+        configuration = {
+            'description' : {
+                'name' : gadgetName,
+                'uuid' : gadgetUuid,
+            },
+            'parameters' : parameters,
+            'command' : 'run',
+            'originalGadgetUuid' : originalGadgetUuid,
+        }
+        return ConfiguredGadget(parent, dictionary, tgfFile, workingPath,
+            configuration)
+
+    # 
--------------------------------------------------------------------------
+    # Store a configured gadget.
+    # 
--------------------------------------------------------------------------
+    def store(configuredGadget, directory):
+        """Store a configured gadget.
+        @param configuredGadget: Configured gadget to store.
+        @param directory: Destination directory.
+        @return: True or False.
+        """
+        if not os.path.isdir(directory):
+            return False
+        configuration = configuredGadget.getConfiguration()
+        fileName = configuredGadget.getDescription().getUuid() + ".gcf"
+        filePath = os.path.join(directory, fileName)
+        result = False
+        try:
+            f = open(filePath, "w")
+            try:
+                f.write(str(configuration))
+                result = True
+            except:
+                pass
+        finally:
+            f.close()
+        return result
+
+    # 
--------------------------------------------------------------------------
+    # Load a configured gadget.
+    # 
--------------------------------------------------------------------------
+    def load(filePath, gadgetsContainer):
+        """Load a configured gadget.
+        @param filePath: File path of the gadget configuration.
+        @param gadgetsContainer: Gadgets container.
+        @return: The ConfiguredGadget object or None.
+        """
+        if not os.path.isfile(filePath):
+            return None
+        if filePath.lower().rfind(".gcf") != len(filePath) - 4:
+            return None
+        try:
+            f = open(filePath, "rb")
+            try:
+                configuration = eval(f.read())
+            except:
+                f.close()
+                return None
+        finally:
+            f.close()
+        try:
+            # Get the original gadget
+            originalGadgetUuid = configuration['originalGadgetUuid']
+            gadgetFound = False
+            for gadget in gadgetsContainer.getGadgets():
+                if gadget.getDescription().getUuid() == originalGadgetUuid:
+                    gadgetFound = True
+                    break
+            if not gadgetFound:
+                return None
+            parent = gadget.getContainer()
+            dictionary = gadget.getDictionary()
+            tgfFile = gadget.getTgfFile()
+            workingPath = gadget.getWorkingPath()
+        except:
+            return None
+        return ConfiguredGadget(parent, dictionary, tgfFile, workingPath,
+            configuration)
+
+    generateSingleUuid = staticmethod(generateSingleUuid)
+    generateSingleName = staticmethod(generateSingleName)
+    createConfiguredGadget = staticmethod(createConfiguredGadget)
+    store = staticmethod(store)
+    load = staticmethod(load)


Property changes on: 
softwares_suite_v3/kysoh/tuxware/server/trunk/util/applicationserver/gadget/ConfiguredGadget.py
___________________________________________________________________
Name: svn:keywords
   + Id

Modified: 
softwares_suite_v3/kysoh/tuxware/server/trunk/util/applicationserver/gadget/Gadget.py
===================================================================
--- 
softwares_suite_v3/kysoh/tuxware/server/trunk/util/applicationserver/gadget/Gadget.py
       2009-04-12 13:42:17 UTC (rev 4493)
+++ 
softwares_suite_v3/kysoh/tuxware/server/trunk/util/applicationserver/gadget/Gadget.py
       2009-04-12 20:13:39 UTC (rev 4494)
@@ -125,6 +125,7 @@
         }
         self.__gadgetInterpreter = None
         self.__interpreterMutex = threading.Lock()
+        self.__isConfiguration = False
         # Define Gadget Instance Parameters
         self.__gadgetInstanceParameters = {}
         self.__gadgetInstanceCommand = ""
@@ -263,6 +264,24 @@
         self.__interpreterMutex.release()
         return isDaemon
 
+    # 
--------------------------------------------------------------------------
+    # 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
+
+    # 
--------------------------------------------------------------------------
+    # Set if the Gadget object is a configuration or an original gadget.
+    # 
--------------------------------------------------------------------------
+    def setIsConfiguration(self, isConfiguration = True):
+        """Set if the Gadget object is a configuration or an original gadget.
+        @param isConfiguration: True or False.
+        """
+        self.__isConfiguration = isConfiguration
+
     # 
==========================================================================
     # I18N
     # 
==========================================================================

Modified: 
softwares_suite_v3/kysoh/tuxware/server/trunk/util/applicationserver/gadget/GadgetDescription.py
===================================================================
--- 
softwares_suite_v3/kysoh/tuxware/server/trunk/util/applicationserver/gadget/GadgetDescription.py
    2009-04-12 13:42:17 UTC (rev 4493)
+++ 
softwares_suite_v3/kysoh/tuxware/server/trunk/util/applicationserver/gadget/GadgetDescription.py
    2009-04-12 20:13:39 UTC (rev 4494)
@@ -89,6 +89,15 @@
         return self.__name
 
     # 
--------------------------------------------------------------------------
+    # Set the gadget name.
+    # 
--------------------------------------------------------------------------
+    def setName(self, name):
+        """Set the gadget name.
+        @param name: A string.
+        """
+        self.__name = name
+
+    # 
--------------------------------------------------------------------------
     # Get the translated name of the gadget.
     # 
--------------------------------------------------------------------------
     def getTranslatedName(self, language = None):
@@ -113,6 +122,15 @@
             return self.__parent.tr2(language, self.__ttsName)
 
     # 
--------------------------------------------------------------------------
+    # Set the TTS name of the gadget.
+    # 
--------------------------------------------------------------------------
+    def setTtsName(self, name):
+        """Set the TTS name of the gadget.
+        @param name: A string.
+        """
+        self.__ttsName = name
+
+    # 
--------------------------------------------------------------------------
     # Get the uuid of the gadget.
     # 
--------------------------------------------------------------------------
     def getUuid(self):
@@ -122,6 +140,15 @@
         return self.__uuid
 
     # 
--------------------------------------------------------------------------
+    # Set the gadget uuid.
+    # 
--------------------------------------------------------------------------
+    def setUuid(self, gadgetUuid):
+        """Set the gadget uuid.
+        @param gadgetUuid: Gadget uuid.
+        """
+        self.__uuid = gadgetUuid
+
+    # 
--------------------------------------------------------------------------
     # Get the author of the gadget.
     # 
--------------------------------------------------------------------------
     def getAuthor(self):

Modified: 
softwares_suite_v3/kysoh/tuxware/server/trunk/util/applicationserver/gadget/GadgetParameter.py
===================================================================
--- 
softwares_suite_v3/kysoh/tuxware/server/trunk/util/applicationserver/gadget/GadgetParameter.py
      2009-04-12 13:42:17 UTC (rev 4493)
+++ 
softwares_suite_v3/kysoh/tuxware/server/trunk/util/applicationserver/gadget/GadgetParameter.py
      2009-04-12 20:13:39 UTC (rev 4494)
@@ -105,6 +105,15 @@
             return self.__parent.tr2(language, self.__defaultValue)
 
     # 
--------------------------------------------------------------------------
+    # Get the default value.
+    # 
--------------------------------------------------------------------------
+    def setDefaultValue(self, defaultValue):
+        """Set the default value.
+        @param defaultValue: Default value as string.
+        """
+        self.__defaultValue = defaultValue
+
+    # 
--------------------------------------------------------------------------
     # Get the description.
     # 
--------------------------------------------------------------------------
     def getDescription(self, language = None):

Modified: 
softwares_suite_v3/kysoh/tuxware/server/trunk/util/applicationserver/gadget/GadgetsContainer.py
===================================================================
--- 
softwares_suite_v3/kysoh/tuxware/server/trunk/util/applicationserver/gadget/GadgetsContainer.py
     2009-04-12 13:42:17 UTC (rev 4493)
+++ 
softwares_suite_v3/kysoh/tuxware/server/trunk/util/applicationserver/gadget/GadgetsContainer.py
     2009-04-12 20:13:39 UTC (rev 4494)
@@ -13,6 +13,7 @@
 from util.filesystem.AutoDeployer import AutoDeployer
 from util.xml.XmlSerializer import XmlSerializer
 from Gadget import Gadget
+from ConfiguredGadget import ConfiguredGadget
 
 # 
------------------------------------------------------------------------------
 # Gadgets container class.
@@ -41,6 +42,11 @@
         self.__onGadgetDeployedCallback = None
         self.__onGadgetDeploymentErrorCallback = None
         self.__onGadgetUndeployedCallback = None
+        self.__onConfigurationsLoaded = None
+        self.__onConfigurationsUnloaded = None
+        self.__configurationsDirectory = None
+        self.__configurationsLoaded = False
+        self.__configurationsLoadedMutex = threading.Lock()
 
     # 
--------------------------------------------------------------------------
     # Configure the locale values of the gadgets container.
@@ -429,3 +435,199 @@
         for gadget in self.__gadgets:
             gadget.stop()
         self.__mutex.release()
+
+    # 
==========================================================================
+    # CONFIGURATIONS
+    # 
==========================================================================
+
+    # 
--------------------------------------------------------------------------
+    # Load configurations from a directory.
+    # 
--------------------------------------------------------------------------
+    def loadConfigurations(self, directory):
+        """Load configurations from a directory.
+        @param directory: Directory where to search the configurations.
+        """
+        if not os.path.isdir(directory):
+            return
+        self.__configurationsDirectory = directory
+        self.__setConfigurationsLoaded(False)
+        files = os.listdir(directory)
+        for file in files:
+            filePath = os.path.join(directory, file)
+            configuredGadget = ConfiguredGadget.load(filePath, self)
+            if configuredGadget == None:
+                try:
+                    os.remove(filePath)
+                except:
+                    pass
+            else:
+                self.__mutex.acquire()
+                self.__gadgets.append(configuredGadget)
+                self.__mutex.release()
+                if self.__onGadgetDeployedCallback != None:
+                    self.__onGadgetDeployedCallback(configuredGadget,
+                        configuredGadget.getWorkingPath())
+        self.__setConfigurationsLoaded(True)
+
+    # 
--------------------------------------------------------------------------
+    # Store configurations in a directory.
+    # 
--------------------------------------------------------------------------
+    def storeConfigurations(self):
+        """Store configurations in a directory.
+        """
+        if self.__configurationsDirectory == None:
+            return
+        # Get stored configuration fileNames list
+        files = os.listdir(self.__configurationsDirectory)
+        for i, file in enumerate(files):
+            if file.lower().rfind(".gcf") != len(file) - 4:
+                files.remove(file)
+            else:
+                files[i] = file[:-4]
+        self.__mutex.acquire()
+        # Remove orphan configurations
+        for file in files:
+            isFound = False
+            for gadget in self.__gadgets:
+                if gadget.isConfiguration():
+                    if gadget.getDescription().getUuid() == file:
+                        isFound = True
+                        break
+            if not isFound:
+                try:
+                    os.remove(os.path.join(self.__configurationsDirectory,
+                        file + ".gcf"))
+                except:
+                    pass
+        # Store configurations
+        for gadget in self.__gadgets:
+            if gadget.isConfiguration():
+                isFound = False
+                for file in files:
+                    if gadget.getDescription().getUuid() == file:
+                        isFound = True
+                        break
+                if not isFound:
+                    ConfiguredGadget.store(gadget,
+                        self.__configurationsDirectory)
+        self.__mutex.release()
+
+    # 
--------------------------------------------------------------------------
+    # Store a configuration.
+    # 
--------------------------------------------------------------------------
+    def storeConfiguration(self, configuredGadget):
+        """Store a configuration.
+        @param configuredGadget: Configured gadget to store.
+        """
+        if self.__configurationsDirectory == None:
+            return
+        if configuredGadget.isConfiguration():
+            ConfiguredGadget.store(configuredGadget,
+                self.__configurationsDirectory)
+
+    # 
--------------------------------------------------------------------------
+    # Get if the configurations are loaded or not.
+    # 
--------------------------------------------------------------------------
+    def configurationsAreLoaded(self):
+        """Get if the configurations are loaded or not.
+        @return: True or False
+        """
+        self.__configurationsLoadedMutex.acquire()
+        result = self.__configurationsLoaded
+        self.__configurationsLoadedMutex.release()
+        return result
+
+    # 
--------------------------------------------------------------------------
+    # Set if the configurations are loaded or not.
+    # 
--------------------------------------------------------------------------
+    def __setConfigurationsLoaded(self, value):
+        """Set if the configurations are loaded or not.
+        @param value: True or False
+        """
+        self.__configurationsLoadedMutex.acquire()
+        self.__configurationsLoaded = value
+        self.__configurationsLoadedMutex.release()
+        if value:
+            if self.__onConfigurationsLoadedCallback != None:
+                self.__onConfigurationsLoadedCallback()
+        else:
+            if self.__onConfigurationsUnloadedCallback != None:
+                self.__onConfigurationsUnloadedCallback()
+
+    # 
--------------------------------------------------------------------------
+    # Insert a configuration in the gadgets container.
+    # 
--------------------------------------------------------------------------
+    def insertConfiguration(self, configuredGadget):
+        """Insert a configuration in the gadgets container.
+        @param configuredGadget: ConfiguredGadget object.
+        """
+        self.__mutex.acquire()
+        self.__gadgets.append(configuredGadget)
+        self.__mutex.release()
+        self.storeConfigurations()
+        if self.__onGadgetDeployedCallback != None:
+            self.__onGadgetDeployedCallback(configuredGadget,
+                configuredGadget.getWorkingPath())
+        if self.configurationsAreLoaded():
+            if self.__onConfigurationsLoadedCallback != None:
+                self.__onConfigurationsLoadedCallback()
+
+    # 
--------------------------------------------------------------------------
+    # Remove a configurations by original gadget uuid.
+    # 
--------------------------------------------------------------------------
+    def removeConfigurationsByOriginalGadgetUuid(self, gadgetUuid):
+        """Remove a configurations by original gadget uuid.
+        @param gadgetUuid: Gadget uuid.
+        """
+        self.__mutex.acquire()
+        for gadget in self.__gadgets:
+            if gadget.isConfiguration():
+                if gadget.getOriginalUuid() == gadgetUuid:
+                    self.__gadgets.remove(gadget)
+                    if self.__onGadgetUndeployedCallback != None:
+                        self.__onGadgetUndeployedCallback(gadget,
+                            gadget.getWorkingPath())
+        self.__mutex.release()
+        self.storeConfigurations()
+
+    # 
--------------------------------------------------------------------------
+    # Remove a configuration.
+    # 
--------------------------------------------------------------------------
+    def removeConfiguration(self, configuredGadget):
+        """Remove a configured gadget.
+        @param configuredGadget: ConfiguredGadget object to remove.
+        """
+        self.__mutex.acquire()
+        configuredGadget.stop()
+        self.__gadgets.remove(configuredGadget)
+        self.__mutex.release()
+        if self.__onGadgetUndeployedCallback != None:
+            self.__onGadgetUndeployedCallback(configuredGadget,
+                configuredGadget.getWorkingPath())
+        self.storeConfigurations()
+        if self.__onConfigurationsLoadedCallback != None:
+            self.__onConfigurationsLoadedCallback()
+
+    # 
--------------------------------------------------------------------------
+    # Set the on configurations loaded event callback.
+    # 
--------------------------------------------------------------------------
+    def setOnConfigurationsLoadedCallback(self, funct):
+        """Set the on configurations loaded event callback.
+        @param funct: Function pointer.
+        Function prototype:
+        def onConfigurationsLoaded(self):
+            pass
+        """
+        self.__onConfigurationsLoadedCallback = funct
+
+    # 
--------------------------------------------------------------------------
+    # Set the on configurations unloaded event callback.
+    # 
--------------------------------------------------------------------------
+    def setOnConfigurationsUnloadedCallback(self, funct):
+        """Set the on configurations unloaded event callback.
+        @param funct: Function pointer.
+        Function prototype:
+        def onTasksUnloaded(self):
+            pass
+        """
+        self.__onConfigurationsUnloadedCallback = funct

Modified: 
softwares_suite_v3/kysoh/tuxware/server/trunk/util/applicationserver/gadget/WebGadgetTools.py
===================================================================
--- 
softwares_suite_v3/kysoh/tuxware/server/trunk/util/applicationserver/gadget/WebGadgetTools.py
       2009-04-12 13:42:17 UTC (rev 4493)
+++ 
softwares_suite_v3/kysoh/tuxware/server/trunk/util/applicationserver/gadget/WebGadgetTools.py
       2009-04-12 20:13:39 UTC (rev 4494)
@@ -97,6 +97,10 @@
         structure['description']['tgf_file'] = gadget.getTgfFile()
         webGadgetUrl = WebGadgetTools.getWebGadgetUrl(gadget, baseUrl, 
command, parameters)
         structure['description']['web_gadget_url'] = webGadgetUrl
+        if gadget.isConfiguration():
+            structure['is_configuration'] = "true"
+        else:
+            structure['is_configuration'] = "false"
         # Add the parameters
         structure['parameters'] = {}
         gadgetParameters = gadget.getParameters()


------------------------------------------------------------------------------
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

Reply via email to