[tuxdroid-svn] r4604 - in softwares_suite_v3/kysoh/tuxware/server/branches/0.3.0-plugins-gadgets-co
Status: Beta
Brought to you by:
ks156
|
From: remi <c2m...@c2...> - 2009-05-01 08:32:13
|
Author: remi Date: 2009-05-01 10:32:06 +0200 (Fri, 01 May 2009) New Revision: 4604 Added: softwares_suite_v3/kysoh/tuxware/server/branches/0.3.0-plugins-gadgets-confs/util/applicationserver/plugin/ softwares_suite_v3/kysoh/tuxware/server/branches/0.3.0-plugins-gadgets-confs/util/applicationserver/plugin/Plugin.py softwares_suite_v3/kysoh/tuxware/server/branches/0.3.0-plugins-gadgets-confs/util/applicationserver/plugin/PluginCommand.py softwares_suite_v3/kysoh/tuxware/server/branches/0.3.0-plugins-gadgets-confs/util/applicationserver/plugin/PluginDescription.py softwares_suite_v3/kysoh/tuxware/server/branches/0.3.0-plugins-gadgets-confs/util/applicationserver/plugin/PluginParameter.py softwares_suite_v3/kysoh/tuxware/server/branches/0.3.0-plugins-gadgets-confs/util/applicationserver/plugin/PluginTask.py softwares_suite_v3/kysoh/tuxware/server/branches/0.3.0-plugins-gadgets-confs/util/applicationserver/plugin/PluginsContainer.py softwares_suite_v3/kysoh/tuxware/server/branches/0.3.0-plugins-gadgets-confs/util/applicationserver/plugin/__init__.py softwares_suite_v3/kysoh/tuxware/server/branches/0.3.0-plugins-gadgets-confs/util/applicationserver/plugin/interpreters/ softwares_suite_v3/kysoh/tuxware/server/branches/0.3.0-plugins-gadgets-confs/util/applicationserver/plugin/interpreters/PluginInterpreter.py softwares_suite_v3/kysoh/tuxware/server/branches/0.3.0-plugins-gadgets-confs/util/applicationserver/plugin/interpreters/PluginInterpreterJava.py softwares_suite_v3/kysoh/tuxware/server/branches/0.3.0-plugins-gadgets-confs/util/applicationserver/plugin/interpreters/PluginInterpreterPython.py softwares_suite_v3/kysoh/tuxware/server/branches/0.3.0-plugins-gadgets-confs/util/applicationserver/plugin/interpreters/__init__.py softwares_suite_v3/kysoh/tuxware/server/branches/0.3.0-plugins-gadgets-confs/util/applicationserver/plugin/interpreters/javacommonjar/ softwares_suite_v3/kysoh/tuxware/server/branches/0.3.0-plugins-gadgets-confs/util/applicationserver/plugin/interpreters/javacommonjar/karmalab-commons-1.2.jar softwares_suite_v3/kysoh/tuxware/server/branches/0.3.0-plugins-gadgets-confs/util/applicationserver/plugin/interpreters/javacommonjar/tuxdroid-gadget-java-kit-0.0.2.jar softwares_suite_v3/kysoh/tuxware/server/branches/0.3.0-plugins-gadgets-confs/util/applicationserver/plugin/interpreters/javacommonjar/tuxdroid-java-api-0.0.3.jar Log: * added plugin directory and classes Added: softwares_suite_v3/kysoh/tuxware/server/branches/0.3.0-plugins-gadgets-confs/util/applicationserver/plugin/Plugin.py =================================================================== --- softwares_suite_v3/kysoh/tuxware/server/branches/0.3.0-plugins-gadgets-confs/util/applicationserver/plugin/Plugin.py (rev 0) +++ softwares_suite_v3/kysoh/tuxware/server/branches/0.3.0-plugins-gadgets-confs/util/applicationserver/plugin/Plugin.py 2009-05-01 08:32:06 UTC (rev 4604) @@ -0,0 +1,713 @@ +# Copyright (C) 2009 C2ME Sa +# Remi Jocaille <rem...@c2...> +# Distributed under the terms of the GNU General Public License +# http://www.gnu.org/copyleft/gpl.html +# +# This module is highly inspired by a "gadget framework" written by +# "Yoran Brault" <http://artisan.karma-lab.net> + +import os +import threading + +from util.i18n.I18n import I18n +from interpreters.PluginInterpreter import PluginInterpreter +from interpreters.PluginInterpreterPython import PluginInterpreterPython +from interpreters.PluginInterpreterJava import PluginInterpreterJava +from PluginDescription import PluginDescription +from PluginParameter import PluginParameter +from PluginCommand import PluginCommand +from PluginTask import PluginTask + +# Default list of the supported language. +SUPPORTED_LANGUAGES_LIST = ["en", "fr", "nl", "es", "it", "pt", "ar", "da", + "de", "no", "sv",] +# Internal parameters list +INTERNAL_PARAMETERS_LIST = ["traces", "language", "country", "locutor", "pitch"] + +# ------------------------------------------------------------------------------ +# Plugin class. +# ------------------------------------------------------------------------------ +class Plugin(object): + """Plugin class. + """ + + # -------------------------------------------------------------------------- + # Constructor of the class. + # -------------------------------------------------------------------------- + def __init__(self, parent, dictionary, tpgFile, workingPath): + """Constructor of the class. + @param parent: Parent Plugins container. + @param dictionary: Plugin structure as dictionary. + @param tpgFile: TPG file name of the plugin. + @param workingPath: Working path of the plugin. + """ + self.__parent = parent + # Save the dictionary + self.__dictionary = dictionary + # Save the working path + self.__workingPath = workingPath + # Save the tpg file name + self.__tpgFile = tpgFile + # Create i18n table + self.__i18nList = {} + self.__updateI18nList() + # Create descriptor + self.__description = PluginDescription(self, dictionary['description'], + self.__workingPath) + # Create parameters + self.__parameters = [] + if dictionary.has_key('parameters'): + keys = dictionary['parameters'].keys() + keys.sort() + for key in keys: + pluginParameter = PluginParameter(self, + dictionary['parameters'][key]) + paramPlatform = pluginParameter.getPlatform() + if paramPlatform != "all": + if paramPlatform == "windows": + if os.name != "nt": + pluginParameter.setVisible('false') + else: + if os.name == "nt": + pluginParameter.setVisible('false') + self.__parameters.append(pluginParameter) + # Add some other parameters + pluginParameter = PluginParameter(self, { + 'name' : 'traces', + 'type' : 'boolean', + 'defaultValue' : 'true', + 'description' : 'Verbose mode', + 'category' : 'internals', + 'visible' : 'false', + }) + self.__parameters.append(pluginParameter) + pluginParameter = PluginParameter(self, { + 'name' : 'language', + 'type' : 'string', + 'defaultValue' : self.__parent.getLanguage(), + 'description' : 'Language', + 'category' : 'internals', + 'visible' : 'false', + }) + self.__parameters.append(pluginParameter) + pluginParameter = PluginParameter(self, { + 'name' : 'country', + 'type' : 'string', + 'defaultValue' : self.__parent.getCountry(), + 'description' : 'Country', + 'category' : 'internals', + 'visible' : 'false', + }) + self.__parameters.append(pluginParameter) + pluginParameter = PluginParameter(self, { + 'name' : 'locutor', + 'type' : 'string', + 'defaultValue' : self.__parent.getLocutor(), + 'description' : 'Locutor', + 'category' : 'internals', + 'visible' : 'false', + }) + self.__parameters.append(pluginParameter) + pluginParameter = PluginParameter(self, { + 'name' : 'pitch', + 'type' : 'integer', + 'defaultValue' : str(self.__parent.getPitch()), + 'description' : 'Pitch', + 'category' : 'internals', + 'visible' : 'false', + }) + self.__parameters.append(pluginParameter) + # Create commands + self.__commands = [] + for key in dictionary['commands'].keys(): + self.__commands.append(PluginCommand(self, + dictionary['commands'][key])) + # Define default check and run commands + commandNamesList = self.getCommandsName() + if "run" in commandNamesList: + self.__defaultRunCommandName = "run" + else: + self.__defaultRunCommandName = self.__commands[0].getName() + if "check" in commandNamesList: + self.__defaultCheckCommandName = "check" + else: + self.__defaultCheckCommandName = self.__defaultRunCommandName + # Create tasks + self.__tasks = [] + if dictionary.has_key('tasks'): + for key in dictionary['tasks'].keys(): + self.__tasks.append(PluginTask(self, + dictionary['tasks'][key])) + # Define interpreter + interpreterClass = PluginInterpreter + if dictionary['interpreter']['kind'] == 'python': + interpreterClass = PluginInterpreterPython + elif dictionary['interpreter']['kind'] == 'java': + interpreterClass = PluginInterpreterJava + self.__interpreterConf = { + 'class' : interpreterClass, + 'executable' : dictionary['interpreter']['executable'], + } + self.__pluginInterpreter = None + self.__interpreterMutex = threading.Lock() + # Define Plugin Instance Parameters + self.__pluginInstanceParameters = {} + self.__pluginInstanceCommand = "" + self.__pluginInstanceIsDaemon = False + # Callbacks + self.__onPluginNotificationCallback = None + self.__onPluginMessageCallback = None + self.__onPluginErrorCallback = None + self.__onPluginTraceCallback = None + self.__onPluginResultCallback = None + self.__onPluginStartingCallback = None + self.__onPluginStoppedCallback = None + + # -------------------------------------------------------------------------- + # Get the data of the plugin as dictionary. + # -------------------------------------------------------------------------- + def getData(self, language): + """Get the data of the plugin as dictionary. + @return a dictionary. + """ + data = {} + # Description + description = self.getDescription() + data['description'] = {} + data['description']['name'] = description.getName() + data['description']['translated_name'] = description.getTranslatedName(language) + data['description']['tts_name'] = description.getTtsName(language) + data['description']['uuid'] = description.getUuid() + data['description']['version'] = description.getVersion() + data['description']['author'] = description.getAuthor() + data['description']['description'] = description.getDescription(language) + data['description']['platform'] = description.getPlatform() + try: + f = open(description.getHelpFile(language), "rb") + try: + helpContent = f.read() + finally: + f.close() + except: + helpContent = "" + data['description']['help_file'] = helpContent + data['description']['icon_file'] = "/%s/icon.png" % description.getUuid() + data['description']['working_path'] = self.getWorkingPath() + data['description']['tpg_file'] = self.getTpgFile() + data['default_run_command'] = self.getDefaultRunCommandName() + data['default_check_command'] = self.getDefaultCheckCommandName() + # Parameters + data['parameters'] = {} + parameters = self.getParameters() + for i, parameter in enumerate(parameters): + nodeName = "parameter_%.3d" % i + data['parameters'][nodeName] = {} + data['parameters'][nodeName]['name'] = parameter.getName() + data['parameters'][nodeName]['translated_name'] = parameter.getTranslatedName(language) + data['parameters'][nodeName]['description'] = parameter.getDescription(language) + data['parameters'][nodeName]['platform'] = parameter.getPlatform() + data['parameters'][nodeName]['category'] = parameter.getCategory() + data['parameters'][nodeName]['type'] = parameter.getType() + data['parameters'][nodeName]['default_value'] = parameter.getDefaultValue(language) + data['parameters'][nodeName]['enum_values'] = parameter.getEnumValues(language) + data['parameters'][nodeName]['min_value'] = parameter.getMinValue() + data['parameters'][nodeName]['max_value'] = parameter.getMaxValue() + data['parameters'][nodeName]['step_value'] = parameter.getStepValue() + data['parameters'][nodeName]['visible'] = parameter.isVisible() + data['parameters'][nodeName]['filters'] = parameter.getFilters() + # Serialize values of enumerated parameters + for key in data['parameters']: + param = data['parameters'][key] + if param['type'] in ['enum', 'booleans']: + values = param['enum_values'].split(",") + enums = {} + for i, value in enumerate(values): + dName = "enum_%.2d" % i + if value != '': + enums[dName] = value.strip() + param['enum_values'] = enums + # Commands + data['commands'] = {} + commands = self.getCommands() + for i, command in enumerate(commands): + nodeName = "command_%.3d" % i + data['commands'][nodeName] = {} + data['commands'][nodeName]['name'] = command.getName() + data['commands'][nodeName]['translated_name'] = command.getTranslatedName(language) + data['commands'][nodeName]['description'] = command.getDescription(language) + data['commands'][nodeName]['is_daemon'] = command.isDaemon() + # Tasks + data['tasks'] = {} + tasks = self.getTasks() + for i, task in enumerate(tasks): + nodeName = "task_%.3d" % i + data['tasks'][nodeName] = {} + data['tasks'][nodeName]['name'] = task.getName() + data['tasks'][nodeName]['translated_name'] = task.getTranslatedName(language) + data['tasks'][nodeName]['description'] = task.getDescription(language) + data['tasks'][nodeName]['command'] = task.getCommand() + data['tasks'][nodeName]['type'] = task.getType() + data['tasks'][nodeName]['activated'] = task.isActivated() + data['tasks'][nodeName]['week_mask'] = task.getWeekMaskDict() + data['tasks'][nodeName]['week_mask_type'] = task.getWeekMaskType() + data['tasks'][nodeName]['week_mask_visible'] = task.getWeekMaskIsVisible() + data['tasks'][nodeName]['date'] = task.getDateDict() + data['tasks'][nodeName]['date_visible'] = task.getDateIsVisible() + data['tasks'][nodeName]['hours_begin'] = task.getTimeDict(task.getHoursBegin()) + data['tasks'][nodeName]['hours_begin_mask'] = task.getTimeMaskDict(task.getHoursBeginMask()) + data['tasks'][nodeName]['hours_begin_visible'] = task.getHoursBeginIsVisible() + data['tasks'][nodeName]['hours_end'] = task.getTimeDict(task.getHoursEnd()) + data['tasks'][nodeName]['hours_end_mask'] = task.getTimeMaskDict(task.getHoursEndMask()) + data['tasks'][nodeName]['hours_end_visible'] = task.getHoursEndIsVisible() + data['tasks'][nodeName]['delay'] = task.getTimeDict(task.getDelay()) + data['tasks'][nodeName]['delay_mask'] = task.getTimeMaskDict(task.getDelayMask()) + data['tasks'][nodeName]['delay_visible'] = task.getDelayIsVisible() + return data + + # -------------------------------------------------------------------------- + # Get the directory path where this plugin is uncompressed. + # -------------------------------------------------------------------------- + def getWorkingPath(self): + """Get the directory path where this plugin is uncompressed. + @return: A directory path as string. + """ + return self.__workingPath + + # -------------------------------------------------------------------------- + # Get the TPG file of the plugin. + # -------------------------------------------------------------------------- + def getTpgFile(self): + """Get the TPG file of the plugin. + @return: A string. + """ + return self.__tpgFile + + # -------------------------------------------------------------------------- + # Get the dictionary of the plugin. + # -------------------------------------------------------------------------- + def getDictionary(self): + """Get the dictionary of the plugin. + @return: A dictionary. + """ + return self.__dictionary + + # -------------------------------------------------------------------------- + # Get the parent plugins container. + # -------------------------------------------------------------------------- + def getContainer(self): + """Get the parent plugins container. + @return: The parent plugins container. + """ + return self.__parent + + # -------------------------------------------------------------------------- + # Get the plugin description object. + # -------------------------------------------------------------------------- + def getDescription(self): + """Get the plugin description object. + @return: The plugin description object. + """ + return self.__description + + # -------------------------------------------------------------------------- + # Get the plugin commands objects list. + # -------------------------------------------------------------------------- + def getCommands(self): + """Get the plugin command objects list. + @return: The plugin commands objects list. + """ + return self.__commands + + # -------------------------------------------------------------------------- + # Get a command object by it name. + # -------------------------------------------------------------------------- + def getCommand(self, commandName): + """Get a command object by it name. + @param commandName: The name of the command. + @return: The command object as PluginCommand or None. + """ + for command in self.__commands: + if command.getName() == commandName: + return command + return None + + # -------------------------------------------------------------------------- + # Get the commands name list. + # -------------------------------------------------------------------------- + def getCommandsName(self): + """Get the commands name list. + @return: A list of strings. + """ + result = [] + for command in self.__commands: + result.append(command.getName()) + return result + + # -------------------------------------------------------------------------- + # Get the plugin tasks objects list. + # -------------------------------------------------------------------------- + def getTasks(self): + """Get the plugin tasks objects list. + @return: The plugin tasks objects list. + """ + return self.__tasks + + # -------------------------------------------------------------------------- + # Get a task object by it name. + # -------------------------------------------------------------------------- + def getTask(self, taskName): + """Get a task object by it name. + @param taskName: The name of the task. + @return: The task object as PluginTask or None. + """ + for task in self.__tasks: + if task.getName() == taskName: + return task + return None + + # -------------------------------------------------------------------------- + # Get the tasks name list. + # -------------------------------------------------------------------------- + def getTasksName(self): + """Get the tasks name list. + @return: A list of strings. + """ + result = [] + for task in self.__tasks: + result.append(task.getName()) + return result + + # -------------------------------------------------------------------------- + # Get the default check command name. + # -------------------------------------------------------------------------- + def getDefaultCheckCommandName(self): + """Get the default check command name. + @return: A string. + """ + return self.__defaultCheckCommandName + + # -------------------------------------------------------------------------- + # Get the default run command name. + # -------------------------------------------------------------------------- + def getDefaultRunCommandName(self): + """Get the default run command name. + @return: A string. + """ + return self.__defaultRunCommandName + + # -------------------------------------------------------------------------- + # Get the parameter objects list. + # -------------------------------------------------------------------------- + def getParameters(self): + """Get the parameter objects list. + @return: The parameter objects list. + """ + return self.__parameters + + # -------------------------------------------------------------------------- + # Get a parameter object by it name. + # -------------------------------------------------------------------------- + def getParameter(self, parameterName): + """Get a parameter object by it name. + @param parameterName: The name of the parameter. + @return: The parameter object or None. + """ + for parameter in self.__parameters: + if parameter.getName() == parameterName: + return parameter + return None + + # -------------------------------------------------------------------------- + # Get the parameters name list. + # -------------------------------------------------------------------------- + def getParametersName(self): + """Get the parameters name list. + @return: A list of strings. + """ + result = [] + for parameter in self.__parameters: + result.append(parameter.getName()) + return result + + # -------------------------------------------------------------------------- + # Get if the current running instance is in daemon mode or not. + # -------------------------------------------------------------------------- + def instanceIsDaemon(self): + """Get if the current running instance is in daemon mode or not. + @return: True or False. + """ + self.__interpreterMutex.acquire() + isDaemon = self.__pluginInstanceIsDaemon + self.__interpreterMutex.release() + return isDaemon + + # ========================================================================== + # I18N + # ========================================================================== + + # -------------------------------------------------------------------------- + # Update the i18n objects list of the plugin. + # -------------------------------------------------------------------------- + def __updateI18nList(self): + """Update the i18n objects list of the plugin. + """ + self.__i18nList = {} + language = self.__parent.getLanguage() + if language not in SUPPORTED_LANGUAGES_LIST: + SUPPORTED_LANGUAGES_LIST.append(language) + for language in SUPPORTED_LANGUAGES_LIST: + i18n = I18n() + i18n.setPoDirectory(os.path.join(self.__workingPath, "resources")) + i18n.setLocale(language) + i18n.update() + self.__i18nList[language] = i18n + + # -------------------------------------------------------------------------- + # Translate a message with the current language of the plugins container. + # -------------------------------------------------------------------------- + def tr(self, message, *arguments): + """Translate a message with the current language of the plugins + container. + @param message: Message to translate. + @param arguments: Arguments to pass in the message. + @return: The translated message. + """ + result = self.__i18nList[self.__parent.getLanguage()].tr(message, + *arguments) + result = result.replace("\\''", "'") + result = result.replace("\\'", "'") + result = result.replace("''", "'") + return result + + # -------------------------------------------------------------------------- + # Translate a message with a specific language. + # -------------------------------------------------------------------------- + def tr2(self, language, message, *arguments): + """Translate a message with a specific language. + @param language: Language of the traduction. + @param message: Message to translate. + @param arguments: Arguments to pass in the message. + @return: The translated message. + """ + if language in self.__i18nList.keys(): + result = self.__i18nList[language].tr(message, *arguments) + else: + result = self.__i18nList[self.__parent.getLanguage()].tr(message, + *arguments) + result = result.replace("\\''", "'") + result = result.replace("\\'", "'") + result = result.replace("''", "'") + return result + + # ========================================================================== + # Plugin execution + # ========================================================================== + + # -------------------------------------------------------------------------- + # Set the plugin notification event callback. + # -------------------------------------------------------------------------- + def setOnPluginNotificationCallback(self, funct): + """Set the plugin notification event callback. + @param funct: Function pointer. + Function prototype: + def onPluginNotification(plugin, instanceParameters, messageId, *args): + pass + """ + self.__onPluginNotificationCallback = funct + + # -------------------------------------------------------------------------- + # Set the plugin message event callback. + # -------------------------------------------------------------------------- + def setOnPluginMessageCallback(self, funct): + """Set the plugin message event callback. + @param funct: Function pointer. + Function prototype: + def onPluginMessage(plugin, instanceParameters, message): + pass + """ + self.__onPluginMessageCallback = funct + + # -------------------------------------------------------------------------- + # Set the plugin error event callback. + # -------------------------------------------------------------------------- + def setOnPluginErrorCallback(self, funct): + """Set the plugin error event callback. + @param funct: Function pointer. + Function prototype: + def onPluginError(plugin, instanceParameters, *messagesList): + pass + """ + self.__onPluginErrorCallback = funct + + # -------------------------------------------------------------------------- + # Set the plugin trace event callback. + # -------------------------------------------------------------------------- + def setOnPluginTraceCallback(self, funct): + """Set the plugin trace event callback. + @param funct: Function pointer. + Function prototype: + def onPluginTrace(plugin, instanceParameters, *messagesList): + pass + """ + self.__onPluginTraceCallback = funct + + # -------------------------------------------------------------------------- + # Set the plugin result event callback. + # -------------------------------------------------------------------------- + def setOnPluginResultCallback(self, funct): + """Set the plugin result event callback. + @param funct: Function pointer. + Function prototype: + def onPluginResult(plugin, instanceParameters, pluginResult): + pass + """ + self.__onPluginResultCallback = funct + + # -------------------------------------------------------------------------- + # Set the plugin starting event callback. + # -------------------------------------------------------------------------- + def setOnPluginStartingCallback(self, funct): + """Set the plugin starting event callback. + @param funct: Function pointer. + Function prototype: + def onPluginStarting(plugin, instanceParameters): + pass + """ + self.__onPluginStartingCallback = funct + + # -------------------------------------------------------------------------- + # Set the plugin stopped event callback. + # -------------------------------------------------------------------------- + def setOnPluginStoppedCallback(self, funct): + """Set the plugin stopped event callback. + @param funct: Function pointer. + Function prototype: + def onPluginStopped(plugin, instanceParameters): + pass + """ + self.__onPluginStoppedCallback = funct + + # -------------------------------------------------------------------------- + # Event on plugin interpreter started. + # -------------------------------------------------------------------------- + def __onInterpreterStarted(self): + """Event on plugin interpreter started. + """ + if self.__onPluginStartingCallback != None: + self.__onPluginStartingCallback(self, self.__pluginInstanceParameters, + self.__pluginInstanceCommand, self.__pluginInstanceIsDaemon) + + # -------------------------------------------------------------------------- + # Event on plugin interpreter stopped. + # -------------------------------------------------------------------------- + def __onInterpreterStopped(self): + """Event on plugin interpreter stopped. + """ + if self.__onPluginStoppedCallback != None: + self.__onPluginStoppedCallback(self, self.__pluginInstanceParameters, + self.__pluginInstanceCommand, self.__pluginInstanceIsDaemon) + + # -------------------------------------------------------------------------- + # Event on plugin interpreter notification. + # -------------------------------------------------------------------------- + def __onInterpreterNotification(self, messageId, *args): + """Event on plugin interpreter notification. + @param messageId: Message identifiant as string. + @param args: Arguments of the notification. + """ + messageId = messageId.lower() + if messageId == "message": + language = self.__pluginInstanceParameters['language'] + if self.__onPluginMessageCallback != None: + self.__onPluginMessageCallback(self, + self.__pluginInstanceParameters, self.tr2(language, *args)) + elif messageId == "trace": + if self.__onPluginTraceCallback != None: + self.__onPluginTraceCallback(self, + self.__pluginInstanceParameters, *args) + elif messageId == "error": + if self.__onPluginErrorCallback != None: + self.__onPluginErrorCallback(self, + self.__pluginInstanceParameters, *args) + elif messageId == "check_result": + if self.__onPluginResultCallback != None: + if len(args) > 0: + if args[0] == "true": + checkResult = True + else: + checkResult = False + else: + checkResult = False + self.__onPluginResultCallback(self, + self.__pluginInstanceParameters, checkResult) + else: + if self.__onPluginNotificationCallback != None: + self.__onPluginNotificationCallback(self, + self.__pluginInstanceParameters, messageId, *args) + + # -------------------------------------------------------------------------- + # Start this plugin. + # -------------------------------------------------------------------------- + def start(self, command, parameters = {}): + """Start this plugin. + @param command: Command name to start the plugin. + @param parameters: Parameters of the plugin as dictionary. + @return: The success of the plugin starting. + - When the parameters are not defined the plugin is started with the + default ones. + - If a parameter is wrong the default one is set. + - If a parameter is missing the default one is set. + """ + self.__interpreterMutex.acquire() + # Stop the last interpreter + if self.__pluginInterpreter != None: + self.__pluginInterpreter.abort() + # Create the interpreter + self.__pluginInterpreter = self.__interpreterConf['class']() + self.__pluginInterpreter.setOnPluginStartedCallback(self.__onInterpreterStarted) + self.__pluginInterpreter.setOnPluginStoppedCallback(self.__onInterpreterStopped) + self.__pluginInterpreter.setOnNotificationThrowedCallback(self.__onInterpreterNotification) + self.__pluginInterpreter.setWorkingPath(self.getWorkingPath()) + self.__pluginInterpreter.setExecutable(self.__interpreterConf['executable']) + # Fill the parameters + if parameters.has_key('language'): + language = parameters['language'] + else: + language = self.__parent.getLanguage() + pluginParameters = {} + for parameterName in self.getParametersName(): + pluginParameters[parameterName] = self.getParameter(parameterName).getDefaultValue(language) + for parameterName in parameters.keys(): + if pluginParameters.has_key(parameterName): + param = self.getParameter(parameterName) + if param != None: + if param.getType() in ["enum", "booleans"]: + pluginParameters[parameterName] = param.getUntranslatedEnumValue( + parameters[parameterName], language) + continue + pluginParameters[parameterName] = parameters[parameterName] + self.__pluginInterpreter.setParameters(pluginParameters) + self.__pluginInstanceParameters = pluginParameters + # Get the command + pluginCommand = self.getCommand(command) + if pluginCommand == None: + pluginCommand = self.getCommands()[0] + self.__pluginInstanceIsDaemon = pluginCommand.isDaemon() + self.__pluginInstanceCommand = pluginCommand.getName() + # Execute the plugin + self.__pluginInterpreter.run(pluginCommand.getName(), + pluginCommand.isDaemon()) + self.__interpreterMutex.release() + return True + + # -------------------------------------------------------------------------- + # Stop the plugin. + # -------------------------------------------------------------------------- + def stop(self): + """Stop the plugin. + """ + self.__interpreterMutex.acquire() + # Stop the last interpreter + if self.__pluginInterpreter != None: + self.__pluginInterpreter.abort() + self.__interpreterMutex.release() Property changes on: softwares_suite_v3/kysoh/tuxware/server/branches/0.3.0-plugins-gadgets-confs/util/applicationserver/plugin/Plugin.py ___________________________________________________________________ Name: svn:keywords + Id Added: softwares_suite_v3/kysoh/tuxware/server/branches/0.3.0-plugins-gadgets-confs/util/applicationserver/plugin/PluginCommand.py =================================================================== --- softwares_suite_v3/kysoh/tuxware/server/branches/0.3.0-plugins-gadgets-confs/util/applicationserver/plugin/PluginCommand.py (rev 0) +++ softwares_suite_v3/kysoh/tuxware/server/branches/0.3.0-plugins-gadgets-confs/util/applicationserver/plugin/PluginCommand.py 2009-05-01 08:32:06 UTC (rev 4604) @@ -0,0 +1,84 @@ +# Copyright (C) 2009 C2ME Sa +# Remi Jocaille <rem...@c2...> +# Distributed under the terms of the GNU General Public License +# http://www.gnu.org/copyleft/gpl.html +# +# This module is highly inspired by a "gadget framework" written by +# "Yoran Brault" <http://artisan.karma-lab.net> + +# ------------------------------------------------------------------------------ +# Plugin command class. +# ------------------------------------------------------------------------------ +class PluginCommand(object): + """Plugin command class. + """ + + # -------------------------------------------------------------------------- + # Constructor of the class. + # -------------------------------------------------------------------------- + def __init__(self, parent, dictionary): + """Constructor of the class. + @param parent: Parent Plugin object. + @param dictionary: Command as dictionary. + """ + self.__parent = parent + self.__dictionary = dictionary + self.__name = self.__dictionary['name'] + self.__daemon = "false" + if self.__dictionary.has_key('daemon'): + self.__daemon = self.__dictionary['daemon'].lower() + self.__description = self.__dictionary['description'] + + # -------------------------------------------------------------------------- + # Get the parent plugin. + # -------------------------------------------------------------------------- + def getParent(self): + """Get the parent plugin. + @return: The parent plugin. + """ + return self.__parent + + # -------------------------------------------------------------------------- + # Get the name. + # -------------------------------------------------------------------------- + def getName(self): + """Get the name. + @return: A string. + """ + return self.__name + + # -------------------------------------------------------------------------- + # Get if this plugin command work in daemon mode. + # -------------------------------------------------------------------------- + def isDaemon(self): + """Get if this plugin command work in daemon mode. + @return: A boolean. + """ + if self.__daemon == "false": + return False + else: + return True + + # -------------------------------------------------------------------------- + # Get the translated name. + # -------------------------------------------------------------------------- + def getTranslatedName(self, language = None): + """Get the translated name. + @return: A string. + """ + if language == None: + return self.__parent.tr(self.__name) + else: + return self.__parent.tr2(language, self.__name) + + # -------------------------------------------------------------------------- + # Get the description. + # -------------------------------------------------------------------------- + def getDescription(self, language = None): + """Get the description. + @return: A string. + """ + if language == None: + return self.__parent.tr(self.__description) + else: + return self.__parent.tr2(language, self.__description) Property changes on: softwares_suite_v3/kysoh/tuxware/server/branches/0.3.0-plugins-gadgets-confs/util/applicationserver/plugin/PluginCommand.py ___________________________________________________________________ Name: svn:keywords + Id Added: softwares_suite_v3/kysoh/tuxware/server/branches/0.3.0-plugins-gadgets-confs/util/applicationserver/plugin/PluginDescription.py =================================================================== --- softwares_suite_v3/kysoh/tuxware/server/branches/0.3.0-plugins-gadgets-confs/util/applicationserver/plugin/PluginDescription.py (rev 0) +++ softwares_suite_v3/kysoh/tuxware/server/branches/0.3.0-plugins-gadgets-confs/util/applicationserver/plugin/PluginDescription.py 2009-05-01 08:32:06 UTC (rev 4604) @@ -0,0 +1,187 @@ +# Copyright (C) 2009 C2ME Sa +# Remi Jocaille <rem...@c2...> +# Distributed under the terms of the GNU General Public License +# http://www.gnu.org/copyleft/gpl.html +# +# This module is highly inspired by a "gadget framework" written by +# "Yoran Brault" <http://artisan.karma-lab.net> + +import os + +# ------------------------------------------------------------------------------ +# Plugin description class. +# ------------------------------------------------------------------------------ +class PluginDescription(object): + """Plugin description. + """ + + # -------------------------------------------------------------------------- + # Constructor of the class. + # -------------------------------------------------------------------------- + def __init__(self, parent, dictionary, workingPath): + """Constructor of the class. + @param parent: Parent Plugin. + @param dictionary: Description as dictionary. + @param workingPath: Working path of the plugin. + """ + self.__parent = parent + self.__dictionary = dictionary + self.__name = None + self.__uuid = None + self.__author = None + self.__version = None + self.__description = None + self.__iconFile = None + self.__helpFile = None + self.__platform = None + self.__ttsName = None + self.__update(dictionary, workingPath) + + # -------------------------------------------------------------------------- + # Get the parent plugin. + # -------------------------------------------------------------------------- + def getParent(self): + """Get the parent plugin. + @return: A Plugin object. + """ + return self.__parent + + # -------------------------------------------------------------------------- + # Get the dictionary. + # -------------------------------------------------------------------------- + def getDictionary(self): + """Get the dictionary. + @return: A dictionary. + """ + return self.__dictionary + + # -------------------------------------------------------------------------- + # Update the description. + # -------------------------------------------------------------------------- + def __update(self, dictionary, workingPath): + """Update the description. + """ + # Save the dictionary + self.__dictionary = dictionary + # Get the descriptor values + self.__name = dictionary['name'] + self.__author = dictionary['author'] + self.__version = dictionary['version'] + self.__uuid = dictionary['uuid'] + self.__iconFile = os.path.join(workingPath, dictionary['iconFile']) + self.__description = dictionary['description'] + self.__workingPath = workingPath + self.__platform = "all" + if dictionary.has_key('platform'): + self.__platform = dictionary['platform'].lower() + self.__ttsName = self.__name + if dictionary.has_key('ttsName'): + self.__ttsName = dictionary['ttsName'] + + # -------------------------------------------------------------------------- + # Get the plugin name. + # -------------------------------------------------------------------------- + def getName(self): + """Get the plugin name. + @return: A string. + """ + return self.__name + + # -------------------------------------------------------------------------- + # Get the translated name of the plugin. + # -------------------------------------------------------------------------- + def getTranslatedName(self, language = None): + """Get the translated name of the plugin. + @return: A string. + """ + if language == None: + return self.__parent.tr(self.__name) + else: + return self.__parent.tr2(language, self.__name) + + # -------------------------------------------------------------------------- + # Get the TTS name of the plugin. + # -------------------------------------------------------------------------- + def getTtsName(self, language = None): + """Get the TTS name of the plugin. + @return: A string. + """ + if language == None: + return self.__parent.tr(self.__ttsName) + else: + return self.__parent.tr2(language, self.__ttsName) + + # -------------------------------------------------------------------------- + # Get the uuid of the plugin. + # -------------------------------------------------------------------------- + def getUuid(self): + """Get the uuid of the plugin. + @return: A string. + """ + return self.__uuid + + # -------------------------------------------------------------------------- + # Get the author of the plugin. + # -------------------------------------------------------------------------- + def getAuthor(self): + """Get the author of the plugin. + @return: A string. + """ + return self.__author + + # -------------------------------------------------------------------------- + # Get the version of the plugin. + # -------------------------------------------------------------------------- + def getVersion(self): + """Get the version of the plugin. + @return: A string. + """ + return self.__version + + # -------------------------------------------------------------------------- + # Get the translated description of the plugin. + # -------------------------------------------------------------------------- + def getDescription(self, language = None): + """Get the translated description of the plugin. + @return: A string. + """ + if language == None: + return self.__parent.tr(self.__description) + else: + return self.__parent.tr2(language, self.__description) + + # -------------------------------------------------------------------------- + # Get the icon url of the plugin. + # -------------------------------------------------------------------------- + def getIconFile(self): + """Get the icon url of the plugin. + @return: A string. + """ + return self.__iconFile + + # -------------------------------------------------------------------------- + # Get the translated help content of the plugin. + # -------------------------------------------------------------------------- + def getHelpFile(self, language = None): + """Get the translated help content of the plugin. + @return: A string. + """ + if language == None: + return os.path.join(self.__workingPath, "resources", "help.wiki") + else: + helpFile = os.path.join(self.__workingPath, "resources", + "help_%s.wiki" % language) + if not os.path.isfile(helpFile): + return os.path.join(self.__workingPath, "resources", + "help.wiki") + else: + return helpFile + + # -------------------------------------------------------------------------- + # Get the platform of this plugin. + # -------------------------------------------------------------------------- + def getPlatform(self): + """Get the platform of this plugin. + @return: A string. <"all"|"linux"|"windows"> + """ + return self.__platform Property changes on: softwares_suite_v3/kysoh/tuxware/server/branches/0.3.0-plugins-gadgets-confs/util/applicationserver/plugin/PluginDescription.py ___________________________________________________________________ Name: svn:keywords + Id Added: softwares_suite_v3/kysoh/tuxware/server/branches/0.3.0-plugins-gadgets-confs/util/applicationserver/plugin/PluginParameter.py =================================================================== --- softwares_suite_v3/kysoh/tuxware/server/branches/0.3.0-plugins-gadgets-confs/util/applicationserver/plugin/PluginParameter.py (rev 0) +++ softwares_suite_v3/kysoh/tuxware/server/branches/0.3.0-plugins-gadgets-confs/util/applicationserver/plugin/PluginParameter.py 2009-05-01 08:32:06 UTC (rev 4604) @@ -0,0 +1,257 @@ +# Copyright (C) 2009 C2ME Sa +# Remi Jocaille <rem...@c2...> +# Distributed under the terms of the GNU General Public License +# http://www.gnu.org/copyleft/gpl.html +# +# This module is highly inspired by a "gadget framework" written by +# "Yoran Brault" <http://artisan.karma-lab.net> + +# Possible parameter types. +PARAMETER_TYPES_LIST = ['integer', 'string', 'boolean', 'booleans', 'float', + 'enum', 'password', 'file', 'directory', 'increment'] + +# ------------------------------------------------------------------------------ +# Plugin parameter class. +# ------------------------------------------------------------------------------ +class PluginParameter(object): + """Plugin parameter class. + """ + + # -------------------------------------------------------------------------- + # Constructor of the class. + # -------------------------------------------------------------------------- + def __init__(self, parent, dictionary): + """Constructor of the class. + @param parent: Parent Plugin. + @param dictionary: Parameter as dictionary. + """ + self.__parent = parent + self.__dictionary = dictionary + self.__name = None + self.__type = None + self.__enumValues = None + self.__enumValuesList = None + self.__defaultValue = None + self.__description = None + self.__category = None + self.__minValue = None + self.__maxValue = None + self.__platform = None + self.__visible = None + self.__filters = None + self.__stepValue = None + self.__update() + + # -------------------------------------------------------------------------- + # Update the field values with the parameter dictionary. + # -------------------------------------------------------------------------- + def __update(self): + """Update the field values with the parameter dictionary. + """ + self.__name = self.__dictionary['name'] + self.__type = self.__dictionary['type'] + self.__enumValuesList = [] + if self.__type.lower().find("enum") == 0: + self.__type = "enum" + self.__enumValues = self.__dictionary['type'].split("(")[1][:-1] + for value in self.__enumValues.split(","): + self.__enumValuesList.append(value.strip()) + elif self.__type.lower().find("booleans") == 0: + self.__type = "booleans" + self.__enumValues = self.__dictionary['type'].split("(")[1][:-1] + for value in self.__enumValues.split(","): + self.__enumValuesList.append(value.strip()) + else: + self.__enumValues = "" + self.__defaultValue = self.__dictionary['defaultValue'] + self.__description = self.__dictionary['description'] + self.__category = "" + if self.__dictionary.has_key('category'): + self.__category = self.__dictionary['category'] + self.__minValue = "0.0" + if self.__dictionary.has_key('minValue'): + self.__minValue = self.__dictionary['minValue'] + self.__maxValue = "1.0" + if self.__dictionary.has_key('maxValue'): + self.__maxValue = self.__dictionary['maxValue'] + self.__platform = "all" + if self.__dictionary.has_key('platform'): + self.__platform = self.__dictionary['platform'].lower() + self.__visible = "true" + if self.__dictionary.has_key('visible'): + self.__visible = self.__dictionary['visible'].lower() + self.__filters = "" + if self.__dictionary.has_key('filters'): + self.__filters = self.__dictionary['filters'] + self.__stepValue = "1" + if self.__dictionary.has_key('stepValue'): + self.__stepValue = self.__dictionary['stepValue'] + + # -------------------------------------------------------------------------- + # Get the parent plugin. + # -------------------------------------------------------------------------- + def getParent(self): + """Get the parent plugin. + @return: The parent plugin. + """ + return self.__parent + + # -------------------------------------------------------------------------- + # Get the name. + # -------------------------------------------------------------------------- + def getName(self): + """Get the name. + @return: A string. + """ + return self.__name + + # -------------------------------------------------------------------------- + # Get the type. + # -------------------------------------------------------------------------- + def getType(self): + """Get the type. + @return: A string. + """ + return self.__type + + # -------------------------------------------------------------------------- + # Get the default value. + # -------------------------------------------------------------------------- + def getDefaultValue(self, language = None): + """Get the default value. + @return: A string. + """ + if language == None: + return self.__defaultValue + else: + return self.__parent.tr2(language, self.__defaultValue) + + # -------------------------------------------------------------------------- + # Get the description. + # -------------------------------------------------------------------------- + def getDescription(self, language = None): + """Get the description. + @return: A string. + """ + if language == None: + return self.__parent.tr(self.__description) + else: + return self.__parent.tr2(language, self.__description) + + # -------------------------------------------------------------------------- + # Get the translated name. + # -------------------------------------------------------------------------- + def getTranslatedName(self, language = None): + """Get the translated name. + @return: A string. + """ + if language == None: + return self.__parent.tr(self.__name) + else: + return self.__parent.tr2(language, self.__name) + + # -------------------------------------------------------------------------- + # Get the category. + # -------------------------------------------------------------------------- + def getCategory(self): + """Get the category. + @return: A string. + """ + return self.__category + + # -------------------------------------------------------------------------- + # Get the enumerated values. + # -------------------------------------------------------------------------- + def getEnumValues(self, language = None): + """Get the enumerated values. + @return: A string. + """ + if language == None: + return self.__parent.tr(self.__enumValues) + else: + return self.__parent.tr2(language, self.__enumValues) + + # -------------------------------------------------------------------------- + # Get the untranslated value of an enumerated value. + # -------------------------------------------------------------------------- + def getUntranslatedEnumValue(self, translatedValue, language = None): + """Get the untranslated value of an enumerated value. + @return: A string. + """ + translatedValue = translatedValue.strip() + translatedEnumValues = self.getEnumValues(language) + idx = -1 + for i, value in enumerate(translatedEnumValues.split(",")): + if value.strip() == translatedValue: + idx = i + break + if idx != -1: + return self.__enumValuesList[idx] + else: + return self.__enumValuesList[0] + + # -------------------------------------------------------------------------- + # Get the minimal value. + # -------------------------------------------------------------------------- + def getMinValue(self): + """Get the minimal value. + @return: A string. + """ + return self.__minValue + + # -------------------------------------------------------------------------- + # Get the maximal value. + # -------------------------------------------------------------------------- + def getMaxValue(self): + """Get the maximal value. + @return: A string. + """ + return self.__maxValue + + # -------------------------------------------------------------------------- + # Get the platform of this parameter. + # -------------------------------------------------------------------------- + def getPlatform(self): + """Get the platform of this parameter. + @return: A string. <"all"|"linux"|"windows"> + """ + return self.__platform + + # -------------------------------------------------------------------------- + # Get if the parameter is visible or not. + # -------------------------------------------------------------------------- + def isVisible(self): + """Get if the parameter is visible or not. + @return: A string. <"true"|"false"> + """ + if self.__visible.lower() == "true": + return True + else: + return False + + # -------------------------------------------------------------------------- + # Set if the parameter is visible or not. + # -------------------------------------------------------------------------- + def setVisible(self, isVisible): + """Set if the parameter is visible or not. + @param isVisible: A string. <"true"|"false"> + """ + self.__visible = isVisible + + # -------------------------------------------------------------------------- + # Get the file extention filters. (for type="file") + # -------------------------------------------------------------------------- + def getFilters(self): + """Get the file extention filters. (for type="file") + @return: A string. + """ + return self.__filters + + # -------------------------------------------------------------------------- + # Get the step value. + # -------------------------------------------------------------------------- + def getStepValue(self): + """Get the step value. + @return: A string. + """ + return self.__stepValue Property changes on: softwares_suite_v3/kysoh/tuxware/server/branches/0.3.0-plugins-gadgets-confs/util/applicationserver/plugin/PluginParameter.py ___________________________________________________________________ Name: svn:keywords + Id Added: softwares_suite_v3/kysoh/tuxware/server/branches/0.3.0-plugins-gadgets-confs/util/applicationserver/plugin/PluginTask.py =================================================================== --- softwares_suite_v3/kysoh/tuxware/server/branches/0.3.0-plugins-gadgets-confs/util/applicationserver/plugin/PluginTask.py (rev 0) +++ softwares_suite_v3/kysoh/tuxware/server/branches/0.3.0-plugins-gadgets-confs/util/applicationserver/plugin/PluginTask.py 2009-05-01 08:32:06 UTC (rev 4604) @@ -0,0 +1,419 @@ +# Copyright (C)... [truncated message content] |