[tuxdroid-svn] r4625 - in software_suite_v3/smart-core/smart-api/python/tags: . before-plugin-gadg
Status: Beta
Brought to you by:
ks156
Author: remi Date: 2009-05-05 09:53:02 +0200 (Tue, 05 May 2009) New Revision: 4625 Added: software_suite_v3/smart-core/smart-api/python/tags/before-plugin-gadget-refactoring/ software_suite_v3/smart-core/smart-api/python/tags/before-plugin-gadget-refactoring/tuxisalive/api/TuxAPI.py software_suite_v3/smart-core/smart-api/python/tags/before-plugin-gadget-refactoring/tuxisalive/api/attitunes/Attitune.py software_suite_v3/smart-core/smart-api/python/tags/before-plugin-gadget-refactoring/tuxisalive/api/attitunes/AttitunesContainer.py software_suite_v3/smart-core/smart-api/python/tags/before-plugin-gadget-refactoring/tuxisalive/api/base/ApiBaseChild.py software_suite_v3/smart-core/smart-api/python/tags/before-plugin-gadget-refactoring/tuxisalive/api/base/ApiBaseChildResource.py software_suite_v3/smart-core/smart-api/python/tags/before-plugin-gadget-refactoring/tuxisalive/api/base/lib/Helper.py software_suite_v3/smart-core/smart-api/python/tags/before-plugin-gadget-refactoring/tuxisalive/api/gadgets/Gadget.py software_suite_v3/smart-core/smart-api/python/tags/before-plugin-gadget-refactoring/tuxisalive/api/gadgets/GadgetDescription.py software_suite_v3/smart-core/smart-api/python/tags/before-plugin-gadget-refactoring/tuxisalive/api/gadgets/GadgetParameter.py software_suite_v3/smart-core/smart-api/python/tags/before-plugin-gadget-refactoring/tuxisalive/api/gadgets/GadgetsContainer.py software_suite_v3/smart-core/smart-api/python/tags/before-plugin-gadget-refactoring/tuxisalive/api/scheduler/Task.py software_suite_v3/smart-core/smart-api/python/tags/before-plugin-gadget-refactoring/tuxisalive/api/scheduler/TaskDescription.py software_suite_v3/smart-core/smart-api/python/tags/before-plugin-gadget-refactoring/tuxisalive/api/scheduler/TasksContainer.py software_suite_v3/smart-core/smart-api/python/tags/before-plugin-gadget-refactoring/tuxisalive/api/tuxdroid/AttituneManager.py software_suite_v3/smart-core/smart-api/python/tags/before-plugin-gadget-refactoring/tuxisalive/api/tuxdroid/Framework.py software_suite_v3/smart-core/smart-api/python/tags/before-plugin-gadget-refactoring/tuxisalive/api/tuxdroid/Scheduler.py software_suite_v3/smart-core/smart-api/python/tags/before-plugin-gadget-refactoring/tuxisalive/api/tuxdroid/TTS.py software_suite_v3/smart-core/smart-api/python/tags/before-plugin-gadget-refactoring/tuxisalive/api/tuxdroid/const/ConstFramework.py Removed: software_suite_v3/smart-core/smart-api/python/tags/before-plugin-gadget-refactoring/tuxisalive/api/TuxAPI.py software_suite_v3/smart-core/smart-api/python/tags/before-plugin-gadget-refactoring/tuxisalive/api/attitunes/Attitune.py software_suite_v3/smart-core/smart-api/python/tags/before-plugin-gadget-refactoring/tuxisalive/api/attitunes/AttitunesContainer.py software_suite_v3/smart-core/smart-api/python/tags/before-plugin-gadget-refactoring/tuxisalive/api/base/ApiBaseChild.py software_suite_v3/smart-core/smart-api/python/tags/before-plugin-gadget-refactoring/tuxisalive/api/base/ApiBaseChildResource.py software_suite_v3/smart-core/smart-api/python/tags/before-plugin-gadget-refactoring/tuxisalive/api/base/lib/Helper.py software_suite_v3/smart-core/smart-api/python/tags/before-plugin-gadget-refactoring/tuxisalive/api/gadgets/Gadget.py software_suite_v3/smart-core/smart-api/python/tags/before-plugin-gadget-refactoring/tuxisalive/api/gadgets/GadgetDescription.py software_suite_v3/smart-core/smart-api/python/tags/before-plugin-gadget-refactoring/tuxisalive/api/gadgets/GadgetParameter.py software_suite_v3/smart-core/smart-api/python/tags/before-plugin-gadget-refactoring/tuxisalive/api/gadgets/GadgetsContainer.py software_suite_v3/smart-core/smart-api/python/tags/before-plugin-gadget-refactoring/tuxisalive/api/scheduler/Task.py software_suite_v3/smart-core/smart-api/python/tags/before-plugin-gadget-refactoring/tuxisalive/api/scheduler/TaskDescription.py software_suite_v3/smart-core/smart-api/python/tags/before-plugin-gadget-refactoring/tuxisalive/api/scheduler/TasksContainer.py software_suite_v3/smart-core/smart-api/python/tags/before-plugin-gadget-refactoring/tuxisalive/api/tuxdroid/AttituneManager.py software_suite_v3/smart-core/smart-api/python/tags/before-plugin-gadget-refactoring/tuxisalive/api/tuxdroid/Framework.py software_suite_v3/smart-core/smart-api/python/tags/before-plugin-gadget-refactoring/tuxisalive/api/tuxdroid/Scheduler.py software_suite_v3/smart-core/smart-api/python/tags/before-plugin-gadget-refactoring/tuxisalive/api/tuxdroid/TTS.py software_suite_v3/smart-core/smart-api/python/tags/before-plugin-gadget-refactoring/tuxisalive/api/tuxdroid/const/ConstFramework.py Log: * tagged the python api project in the state before the plugin/gadget new philosophy Copied: software_suite_v3/smart-core/smart-api/python/tags/before-plugin-gadget-refactoring (from rev 4469, softwares_suite_v3/kysoh/tuxware/api/python/trunk) Deleted: software_suite_v3/smart-core/smart-api/python/tags/before-plugin-gadget-refactoring/tuxisalive/api/TuxAPI.py =================================================================== --- softwares_suite_v3/kysoh/tuxware/api/python/trunk/tuxisalive/api/TuxAPI.py 2009-04-10 12:51:53 UTC (rev 4469) +++ software_suite_v3/smart-core/smart-api/python/tags/before-plugin-gadget-refactoring/tuxisalive/api/TuxAPI.py 2009-05-05 07:53:02 UTC (rev 4625) @@ -1,165 +0,0 @@ -# -*- coding: latin1 -*- - -import version -__author__ = version.author -__date__ = version.date -__version__ = version.version -__licence__ = version.licence -del version - -# 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 - -from base.lib.Helper import Helper -from base.ApiBase import * -from tuxdroid.const.ConstTuxDriver import * -from tuxdroid.const.ConstTuxOsl import * -from tuxdroid.const.ConstFramework import * -from tuxdroid.const.ConstAttitunes import * -from tuxdroid.const.ConstScheduler import * -from tuxdroid.MouthEyes import MouthEyes -from tuxdroid.TTS import TTS -from tuxdroid.Wav import Wav -from tuxdroid.Attitune import Attitune -from tuxdroid.RawCommand import RawCommand -from tuxdroid.DongleRadio import DongleRadio -from tuxdroid.SoundFlash import SoundFlash -from tuxdroid.Led import Led -from tuxdroid.Button import Button -from tuxdroid.Flippers import Flippers -from tuxdroid.Spinning import Spinning -from tuxdroid.Framework import Framework -from tuxdroid.Light import Light -from tuxdroid.Battery import Battery -from tuxdroid.Charger import Charger -from tuxdroid.AttituneManager import AttituneManager -from tuxdroid.Scheduler import Scheduler -from tuxdroid.User import User - -# ------------------------------------------------------------------------------ -# Tux Droid API. -# ------------------------------------------------------------------------------ -class TuxAPI(ApiBase): - """Main module class to control Tuxdroid. - """ - # -------------------------------------------------------------------------- - # Constructor of the class. - # -------------------------------------------------------------------------- - def __init__(self, host = '127.0.0.1', port = 270): - """Constructor of the class. - @param host: host of the server. - @param port: port of the server. - """ - ApiBase.__init__(self, host, port) - # Register base status/events of the server - for statusName in SW_NAME_DRIVER: - self.getEventsHandler().insert(statusName) - for statusName in SW_NAME_OSL: - self.getEventsHandler().insert(statusName) - for statusName in SW_NAME_FRAMEWORK: - self.getEventsHandler().insert(statusName) - # Create the mouth object - self.mouth = MouthEyes(self, self.server, ST_NAME_MOUTH_POSITION, - ST_NAME_MOUTH_RM, "mouth") - # Create the eyes object - self.eyes = MouthEyes(self, self.server, ST_NAME_EYES_POSITION, - ST_NAME_EYES_RM, "eyes") - # Create the tts object - self.tts = TTS(self, self.server) - # Create the wav object - self.wav = Wav(self, self.server) - # Create the attitune object - self.attitune = Attitune(self, self.server) - # Create the raw command object - self.raw = RawCommand(self, self.server) - # Create the dongle object - self.dongle = DongleRadio(self, self.server, ST_NAME_DONGLE_PLUG) - # Create the radio object - self.radio = DongleRadio(self, self.server, ST_NAME_RADIO_STATE) - # Create the sound flash object - self.soundFlash = SoundFlash(self, self.server) - # Create led objects - self.led = Led(self, self.server) - # Create the button objects - self.button = Button(self, self.server) - # Create the flippers object - self.flippers = Flippers(self, self.server) - # Create the spinning object - self.spinning = Spinning(self, self.server) - # Create the light object - self.light = Light(self, self.server) - # Create the battery object - self.battery = Battery(self, self.server) - # Create the charger object - self.charger = Charger(self, self.server) - # Create the framework object - self.framework = Framework(self, self.server) - # Create the attitune manager object - self.attitunes = AttituneManager(self, self.server) - # Create the scheduler object - self.scheduler = Scheduler(self, self.server) - # Create the user object - self.user = User(self, self.server) - # Bind some methods - self.__bindSomeMethods() - # Initialize the helper - Helper.__init__(self) - - def __bindSomeMethods(self): - """Bind some methods in order to make more usefull some - functionalities. - """ - # Gadget framework bindings - self.showGadgets = self.framework.getGadgetsContainer().showGadgets - self.getGadget = self.framework.getGadgetsContainer().getGadget - # Attitune manager bindings - self.showAttitunes = self.attitunes.getAttitunesContainer().showAttitunes - self.getAttitune = self.attitunes.getAttitunesContainer().getAttitune - # Scheduler bindings - self.showTasks = self.scheduler.getTasksContainer().showTasks - self.getTask = self.scheduler.getTasksContainer().getTask - - # -------------------------------------------------------------------------- - # Get the version of this API. - # -------------------------------------------------------------------------- - def getVersion(self): - """Get the version of this api. - @return: A string. - """ - return "tuxisalive.api-%s" % __version__ - - # -------------------------------------------------------------------------- - # Get the Tux Droid system versions. - # -------------------------------------------------------------------------- - def getVersions(self): - """Get the Tux Droid system versions. - @return: a dictionary. - """ - verDict = {} - verDict["tuxapi"] = __version__ - verDict["tuxdroidserver"] = self.server.getVersion() - ver = self.server._requestOne(ST_NAME_DRIVER_SYMB_VER) - if ver == None: - verDict["tuxdriver"] = "Unknow" - else: - verDict["tuxdriver"] = ver[ver.find("_") + 1:] - ver = self.server._requestOne(ST_NAME_OSL_SYMB_VER) - if ver == None: - verDict["tuxosl"] = "Unknow" - else: - verDict["tuxosl"] = ver[ver.find("_") + 1:] - return verDict - - # -------------------------------------------------------------------------- - # Show the Tux Droid system versions. - # -------------------------------------------------------------------------- - def showVersions(self): - """Show the Tux Droid system versions. - """ - verDict = self.getVersions() - result = [] - for key in verDict.keys(): - result.append("%s : %s" % (key, verDict[key])) - self._showStringList("Tux Droid System :", result) Copied: software_suite_v3/smart-core/smart-api/python/tags/before-plugin-gadget-refactoring/tuxisalive/api/TuxAPI.py (from rev 4558, softwares_suite_v3/kysoh/tuxware/api/python/trunk/tuxisalive/api/TuxAPI.py) =================================================================== --- software_suite_v3/smart-core/smart-api/python/tags/before-plugin-gadget-refactoring/tuxisalive/api/TuxAPI.py (rev 0) +++ software_suite_v3/smart-core/smart-api/python/tags/before-plugin-gadget-refactoring/tuxisalive/api/TuxAPI.py 2009-05-05 07:53:02 UTC (rev 4625) @@ -0,0 +1,175 @@ +# -*- coding: latin1 -*- + +import version +__author__ = version.author +__date__ = version.date +__version__ = version.version +__licence__ = version.licence +del version + +# 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 + +from base.lib.Helper import Helper +from base.ApiBase import * +from tuxdroid.const.ConstTuxDriver import * +from tuxdroid.const.ConstTuxOsl import * +from tuxdroid.const.ConstFramework import * +from tuxdroid.const.ConstAttitunes import * +from tuxdroid.const.ConstScheduler import * +from tuxdroid.MouthEyes import MouthEyes +from tuxdroid.TTS import TTS +from tuxdroid.Wav import Wav +from tuxdroid.Attitune import Attitune +from tuxdroid.RawCommand import RawCommand +from tuxdroid.DongleRadio import DongleRadio +from tuxdroid.SoundFlash import SoundFlash +from tuxdroid.Led import Led +from tuxdroid.Button import Button +from tuxdroid.Flippers import Flippers +from tuxdroid.Spinning import Spinning +from tuxdroid.Framework import Framework +from tuxdroid.Light import Light +from tuxdroid.Battery import Battery +from tuxdroid.Charger import Charger +from tuxdroid.AttituneManager import AttituneManager +from tuxdroid.Scheduler import Scheduler +from tuxdroid.User import User + +# ------------------------------------------------------------------------------ +# Tux Droid API. +# ------------------------------------------------------------------------------ +class TuxAPI(ApiBase): + """Main module class to control Tuxdroid. + """ + # -------------------------------------------------------------------------- + # Constructor of the class. + # -------------------------------------------------------------------------- + def __init__(self, host = '127.0.0.1', port = 270): + """Constructor of the class. + @param host: host of the server. + @param port: port of the server. + """ + ApiBase.__init__(self, host, port) + # Register base status/events of the server + for statusName in SW_NAME_DRIVER: + self.getEventsHandler().insert(statusName) + for statusName in SW_NAME_OSL: + self.getEventsHandler().insert(statusName) + for statusName in SW_NAME_FRAMEWORK: + self.getEventsHandler().insert(statusName) + # Create the mouth object + self.mouth = MouthEyes(self, self.server, ST_NAME_MOUTH_POSITION, + ST_NAME_MOUTH_RM, "mouth") + # Create the eyes object + self.eyes = MouthEyes(self, self.server, ST_NAME_EYES_POSITION, + ST_NAME_EYES_RM, "eyes") + # Create the tts object + self.tts = TTS(self, self.server) + # Create the wav object + self.wav = Wav(self, self.server) + # Create the attitune object + self.attitune = Attitune(self, self.server) + # Create the raw command object + self.raw = RawCommand(self, self.server) + # Create the dongle object + self.dongle = DongleRadio(self, self.server, ST_NAME_DONGLE_PLUG) + # Create the radio object + self.radio = DongleRadio(self, self.server, ST_NAME_RADIO_STATE) + # Create the sound flash object + self.soundFlash = SoundFlash(self, self.server) + # Create led objects + self.led = Led(self, self.server) + # Create the button objects + self.button = Button(self, self.server) + # Create the flippers object + self.flippers = Flippers(self, self.server) + # Create the spinning object + self.spinning = Spinning(self, self.server) + # Create the light object + self.light = Light(self, self.server) + # Create the battery object + self.battery = Battery(self, self.server) + # Create the charger object + self.charger = Charger(self, self.server) + # Create the framework object + self.framework = Framework(self, self.server) + # Create the attitune manager object + self.attitunes = AttituneManager(self, self.server) + # Create the scheduler object + self.scheduler = Scheduler(self, self.server) + # Create the user object + self.user = User(self, self.server) + # Bind some methods + self.__bindSomeMethods() + # Initialize the helper + Helper.__init__(self) + + def __bindSomeMethods(self): + """Bind some methods in order to make more usefull some + functionalities. + """ + # Gadget framework bindings + self.showGadgets = self.framework.getGadgetsContainer().showGadgets + self.getGadget = self.framework.getGadgetsContainer().getGadget + # Attitune manager bindings + self.showAttitunes = self.attitunes.getAttitunesContainer().showAttitunes + self.getAttitune = self.attitunes.getAttitunesContainer().getAttitune + # Scheduler bindings + self.showTasks = self.scheduler.getTasksContainer().showTasks + self.getTask = self.scheduler.getTasksContainer().getTask + # User method bind + def userWaitLoaded(): + ret = self.framework.waitLoaded(5.0, 0.0) + if not ret: + return False + ret = self.attitunes.waitLoaded(5.0, 0.0) + if not ret: + return False + return self.scheduler.waitLoaded(5.0, 1.0) + self.user.waitLoaded = userWaitLoaded + + # -------------------------------------------------------------------------- + # Get the version of this API. + # -------------------------------------------------------------------------- + def getVersion(self): + """Get the version of this api. + @return: A string. + """ + return "tuxisalive.api-%s" % __version__ + + # -------------------------------------------------------------------------- + # Get the Tux Droid system versions. + # -------------------------------------------------------------------------- + def getVersions(self): + """Get the Tux Droid system versions. + @return: a dictionary. + """ + verDict = {} + verDict["tuxapi"] = __version__ + verDict["tuxdroidserver"] = self.server.getVersion() + ver = self.server._requestOne(ST_NAME_DRIVER_SYMB_VER) + if ver == None: + verDict["tuxdriver"] = "Unknow" + else: + verDict["tuxdriver"] = ver[ver.find("_") + 1:] + ver = self.server._requestOne(ST_NAME_OSL_SYMB_VER) + if ver == None: + verDict["tuxosl"] = "Unknow" + else: + verDict["tuxosl"] = ver[ver.find("_") + 1:] + return verDict + + # -------------------------------------------------------------------------- + # Show the Tux Droid system versions. + # -------------------------------------------------------------------------- + def showVersions(self): + """Show the Tux Droid system versions. + """ + verDict = self.getVersions() + result = [] + for key in verDict.keys(): + result.append("%s : %s" % (key, verDict[key])) + self._showStringList("Tux Droid System :", result) Deleted: software_suite_v3/smart-core/smart-api/python/tags/before-plugin-gadget-refactoring/tuxisalive/api/attitunes/Attitune.py =================================================================== --- softwares_suite_v3/kysoh/tuxware/api/python/trunk/tuxisalive/api/attitunes/Attitune.py 2009-04-10 12:51:53 UTC (rev 4469) +++ software_suite_v3/smart-core/smart-api/python/tags/before-plugin-gadget-refactoring/tuxisalive/api/attitunes/Attitune.py 2009-05-05 07:53:02 UTC (rev 4625) @@ -1,129 +0,0 @@ -# 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 - -import time - -from tuxisalive.api.base.ApiBaseChildResource import ApiBaseChildResource -from tuxisalive.api.scheduler.Task import Task -from tuxisalive.api.tuxdroid.const.ConstAttitunes import * -from AttituneDescription import AttituneDescription - -# ------------------------------------------------------------------------------ -# Attitune -# ------------------------------------------------------------------------------ -class Attitune(ApiBaseChildResource): - - # -------------------------------------------------------------------------- - # Constructor of the class. - # -------------------------------------------------------------------------- - def __init__(self, apiBase, apiBaseServer, parent, infosStructure): - """Constructor of the class. - @param apiBase: ApiBase parent object. - @param apiBaseServer: ApiBaseServer object. - @param parent: Parent Attitunes container. - @param infosStructure: Attitune structure as dictionary. - """ - ApiBaseChildResource.__init__(self, apiBase, apiBaseServer) - self.__parent = parent - self.__description = AttituneDescription(self, infosStructure) - - # -------------------------------------------------------------------------- - # Get the parent attitunes container. - # -------------------------------------------------------------------------- - def getContainer(self): - """Get the parent attitunes container. - @return: The parent attitunes container. - """ - return self.__parent - - # -------------------------------------------------------------------------- - # Get the attitune description object. - # -------------------------------------------------------------------------- - def getDescription(self): - """Get the gadget description object. - @return: The gadget description object. - """ - return self.__description - - # -------------------------------------------------------------------------- - # Show the description in the console. - # -------------------------------------------------------------------------- - def showDescription(self): - """Show the description in the console. - """ - self.__description.show() - - # -------------------------------------------------------------------------- - # Start this attitune. - # -------------------------------------------------------------------------- - def startAsync(self, begin = 0.0): - """Start this attitune. - @param begin: Begin time. - @return: The success of the attitune start. - """ - if not self._checkObjectType('begin', begin, 'float'): - return False - if begin > self.__description.getDuration(): - return False - argsToSend = { - 'name' : self.__description.getName(), - 'begin' : begin, - } - cmd = "attitune_manager/start_attitune_by_name?" - return self._sendCommandBooleanResult(cmd, argsToSend) - - # -------------------------------------------------------------------------- - # Start this attitune. - # -------------------------------------------------------------------------- - def start(self, begin = 0.0): - """Start this attitune. - @param begin: Begin time. - @return: The success of the attitune start. - """ - if not self.startAsync(begin): - return False - time.sleep(0.5) - self._waitFor(ST_NAME_AM_ATTITUNE_STOPPED, self.__description.getName(), - 600.0) - return True - - # -------------------------------------------------------------------------- - # Stop the attitune. - # -------------------------------------------------------------------------- - def stop(self): - """Stop the attitune. - """ - cmd = "attitune_manager/stop_attitune?" - return self._sendCommandBooleanResult(cmd) - - # -------------------------------------------------------------------------- - # Schedule the start command of this attitune. - # -------------------------------------------------------------------------- - def scheduleStart(self, type = "ONCE DELAYED", name = None, - weekMask = [True, True, True, True, True, True, True], date = None, - time = "00:00:10"): - """Schedule the start command of this attitune. - @param type: <EVERY X|EVERY X FROM FULL HOUR|DAILY AT|ONCE AT| - ONCE DELAYED> - Default value is the "ONCE DELAYED". - @param name: Task name. - Default value is attitune name. - @param weekMask: Week mask as list of 7 booleans. - Default is [True, True, True, True, True, True, True] - @param date: Task date as string "YYYY/MM/DD". - Default is None (no date defined) - @param time: Task time as string "HH:MM:SS". - Default is "00:00:10". - @return: The success of the request. - """ - if name == None: - name = self.getDescription().getName() - argsToSend = Task.formatRequestArguments(type, name, weekMask, date, - time) - if argsToSend == None: - return False - argsToSend['attitune_name'] = self.getDescription().getName() - cmd = "task_creation/play_attitune?" - return self._sendCommandBooleanResult(cmd, argsToSend) Copied: software_suite_v3/smart-core/smart-api/python/tags/before-plugin-gadget-refactoring/tuxisalive/api/attitunes/Attitune.py (from rev 4593, softwares_suite_v3/kysoh/tuxware/api/python/trunk/tuxisalive/api/attitunes/Attitune.py) =================================================================== --- software_suite_v3/smart-core/smart-api/python/tags/before-plugin-gadget-refactoring/tuxisalive/api/attitunes/Attitune.py (rev 0) +++ software_suite_v3/smart-core/smart-api/python/tags/before-plugin-gadget-refactoring/tuxisalive/api/attitunes/Attitune.py 2009-05-05 07:53:02 UTC (rev 4625) @@ -0,0 +1,134 @@ +# 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 + +import time + +from tuxisalive.api.base.ApiBaseChildResource import ApiBaseChildResource +from tuxisalive.api.scheduler.Task import Task +from tuxisalive.api.tuxdroid.const.ConstAttitunes import * +from AttituneDescription import AttituneDescription + +# ------------------------------------------------------------------------------ +# Attitune +# ------------------------------------------------------------------------------ +class Attitune(ApiBaseChildResource): + + # -------------------------------------------------------------------------- + # Constructor of the class. + # -------------------------------------------------------------------------- + def __init__(self, apiBase, apiBaseServer, parent, infosStructure): + """Constructor of the class. + @param apiBase: ApiBase parent object. + @param apiBaseServer: ApiBaseServer object. + @param parent: Parent Attitunes container. + @param infosStructure: Attitune structure as dictionary. + """ + ApiBaseChildResource.__init__(self, apiBase, apiBaseServer) + self.__parent = parent + self.__description = AttituneDescription(self, infosStructure) + + # -------------------------------------------------------------------------- + # Get the parent attitunes container. + # -------------------------------------------------------------------------- + def getContainer(self): + """Get the parent attitunes container. + @return: The parent attitunes container. + """ + return self.__parent + + # -------------------------------------------------------------------------- + # Get the attitune description object. + # -------------------------------------------------------------------------- + def getDescription(self): + """Get the gadget description object. + @return: The gadget description object. + """ + return self.__description + + # -------------------------------------------------------------------------- + # Show the description in the console. + # -------------------------------------------------------------------------- + def showDescription(self): + """Show the description in the console. + """ + self.__description.show() + + # -------------------------------------------------------------------------- + # Start this attitune. + # -------------------------------------------------------------------------- + def startAsync(self, begin = 0.0): + """Start this attitune. + @param begin: Begin time. + @return: The success of the attitune start. + """ + if not self._checkObjectType('begin', begin, 'float'): + return False + if begin > self.__description.getDuration(): + return False + argsToSend = { + 'name' : self.__description.getName(), + 'begin' : begin, + } + cmd = "attitune_manager/start_attitune_by_name?" + return self._sendCommandBooleanResult(cmd, argsToSend) + + # -------------------------------------------------------------------------- + # Start this attitune. + # -------------------------------------------------------------------------- + def start(self, begin = 0.0): + """Start this attitune. + @param begin: Begin time. + @return: The success of the attitune start. + """ + if not self.startAsync(begin): + return False + time.sleep(0.5) + self._waitFor(ST_NAME_AM_ATTITUNE_STOPPED, self.__description.getName(), + 600.0) + return True + + # -------------------------------------------------------------------------- + # Stop the attitune. + # -------------------------------------------------------------------------- + def stop(self): + """Stop the attitune. + """ + cmd = "attitune_manager/stop_attitune?" + return self._sendCommandBooleanResult(cmd) + + # -------------------------------------------------------------------------- + # Schedule the start command of this attitune. + # -------------------------------------------------------------------------- + def scheduleStart(self, type = "ONCE DELAYED", name = None, + weekMask = [True, True, True, True, True, True, True], + date = "0000/00/00", hoursBegin = "00:00:00" , hoursEnd = "23:59:59", + delay = "00:01:00"): + """Schedule the start command of this attitune. + @param type: <EVERY X|EVERY X FROM FULL HOUR|DAILY AT|ONCE AT| + ONCE DELAYED> + Default value is the "ONCE DELAYED". + @param name: Task name. + Default value is attitune name. + @param weekMask: Week mask as list of 7 booleans. + Default is [True, True, True, True, True, True, True] + @param date: Task date as string "YYYY/MM/DD". + Default is "0000/00/00" (no date defined) + @param hoursBegin: Task hours begin as string "HH:MM:SS". + Default is "00:00:00". + @param hoursEnd: Task hours end as string "HH:MM:SS". + Default is "23:59:59". + @param delay: Task delay as string "HH:MM:SS". + Default is "00:01:00". + @return: The success of the request. + """ + if name == None: + name = self.getDescription().getName() + argsToSend = Task.formatRequestArguments(type, name, weekMask, date, + hoursBegin, hoursEnd, delay) + if argsToSend == None: + return False + argsToSend['attitune_name'] = self.getDescription().getName() + cmd = "task_creation/play_attitune?" + return self._sendCommandBooleanResult(cmd, argsToSend) Deleted: software_suite_v3/smart-core/smart-api/python/tags/before-plugin-gadget-refactoring/tuxisalive/api/attitunes/AttitunesContainer.py =================================================================== --- softwares_suite_v3/kysoh/tuxware/api/python/trunk/tuxisalive/api/attitunes/AttitunesContainer.py 2009-04-10 12:51:53 UTC (rev 4469) +++ software_suite_v3/smart-core/smart-api/python/tags/before-plugin-gadget-refactoring/tuxisalive/api/attitunes/AttitunesContainer.py 2009-05-05 07:53:02 UTC (rev 4625) @@ -1,144 +0,0 @@ -# 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 - -import threading - -from tuxisalive.api.base.ApiBaseChildResource import ApiBaseChildResource -from Attitune import Attitune - -# ------------------------------------------------------------------------------ -# Attitunes container. -# ------------------------------------------------------------------------------ -class AttitunesContainer(ApiBaseChildResource): - """Attitunes container. - """ - - # -------------------------------------------------------------------------- - # Constructor of the class. - # -------------------------------------------------------------------------- - def __init__(self, apiBase, apiBaseServer, structure): - """Constructor of the class. - @param apiBase: ApiBase parent object. - @param apiBaseServer: ApiBaseServer object. - @param structure: Attitunes container structure as dictionary. - """ - ApiBaseChildResource.__init__(self, apiBase, apiBaseServer) - self.__mutex = threading.Lock() - self.__attitunes = [] - self._update(structure) - - # -------------------------------------------------------------------------- - # Update the container structure. - # -------------------------------------------------------------------------- - def _update(self, structure): - """Update the container structure. - @param structure: The new container structure dictionary. - """ - self.__mutex.acquire() - self.__attitunes = [] - for key in structure.keys(): - if key.lower().find('data') == 0: - self.__attitunes.append(Attitune(self.getParent(), - self.getServer(), self, structure[key])) - self.__mutex.release() - - # -------------------------------------------------------------------------- - # Get the attitune objects list. - # -------------------------------------------------------------------------- - def getAttitunes(self): - """Get the attitune objects list. - @return: A list of Attitune objects. - """ - self.__mutex.acquire() - result = self.__attitunes - self.__mutex.release() - return result - - # -------------------------------------------------------------------------- - # Get the number of attitunes contains in the container. - # -------------------------------------------------------------------------- - def getCount(self): - """Get the number of attitunes contains in the container. - @return: An integer. - """ - self.__mutex.acquire() - result = len(self.__attitunes) - self.__mutex.release() - return result - - # -------------------------------------------------------------------------- - # Show the attitunes name list in the console. - # -------------------------------------------------------------------------- - def showAttitunes(self): - """Show the attitunes name list in the console. - """ - result = [] - self.__mutex.acquire() - for attitune in self.__attitunes: - result.append(attitune.getDescription().getName()) - self.__mutex.release() - self._showStringList("Attitune names :", result) - - # -------------------------------------------------------------------------- - # Get an attitune object by it name or index. - # -------------------------------------------------------------------------- - def getAttitune(self, attitune): - """Get an attitune object by it name or index. - @param attitune: The name or index of the attitune. - @return: An Attitune object or None. - """ - self.__mutex.acquire() - if str(type(attitune)) == "<type 'int'>": - if attitune in range(len(self.__attitunes)): - result = self.__attitunes[attitune] - self.__mutex.release() - return result - else: - for attObject in self.__attitunes: - if attObject.getDescription().getName() == attitune: - result = attObject - self.__mutex.release() - return result - self.__mutex.release() - return None - - # -------------------------------------------------------------------------- - # Stop played attitune. - # -------------------------------------------------------------------------- - def stopAttitune(self): - """Stop played attitune. - @return: The success of the command. - """ - cmd = "attitune_manager/stop_attitune?" - return self._sendCommandBooleanResult(cmd) - - # -------------------------------------------------------------------------- - # Insert an attitune in the container. - # -------------------------------------------------------------------------- - def insertAttitune(self, attituneFileName): - """Insert an attitune in the container. - @param attituneFileName: Attitune file name. Can be a local or a distant - file. - @return: The success of the command. - """ - argsToSend = { - 'path' : attituneFileName, - } - cmd = "attitune_manager/insert_attitune?" - return self._sendCommandBooleanResult(cmd, argsToSend) - - # -------------------------------------------------------------------------- - # Remove an attitune from the container. - # -------------------------------------------------------------------------- - def removeAttitune(self, attituneName): - """Remove an attitune from the container. - @param attituneName: The name of the attitune. - @return: The success of the command. - """ - argsToSend = { - 'name' : attituneName, - } - cmd = "attitune_manager/remove_attitune?" - return self._sendCommandBooleanResult(cmd, argsToSend) Copied: software_suite_v3/smart-core/smart-api/python/tags/before-plugin-gadget-refactoring/tuxisalive/api/attitunes/AttitunesContainer.py (from rev 4557, softwares_suite_v3/kysoh/tuxware/api/python/trunk/tuxisalive/api/attitunes/AttitunesContainer.py) =================================================================== --- software_suite_v3/smart-core/smart-api/python/tags/before-plugin-gadget-refactoring/tuxisalive/api/attitunes/AttitunesContainer.py (rev 0) +++ software_suite_v3/smart-core/smart-api/python/tags/before-plugin-gadget-refactoring/tuxisalive/api/attitunes/AttitunesContainer.py 2009-05-05 07:53:02 UTC (rev 4625) @@ -0,0 +1,149 @@ +# 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 + +import threading + +from tuxisalive.api.base.ApiBaseChildResource import ApiBaseChildResource +from Attitune import Attitune + +# ------------------------------------------------------------------------------ +# Attitunes container. +# ------------------------------------------------------------------------------ +class AttitunesContainer(ApiBaseChildResource): + """Attitunes container. + """ + + # -------------------------------------------------------------------------- + # Constructor of the class. + # -------------------------------------------------------------------------- + def __init__(self, apiBase, apiBaseServer, structure): + """Constructor of the class. + @param apiBase: ApiBase parent object. + @param apiBaseServer: ApiBaseServer object. + @param structure: Attitunes container structure as dictionary. + """ + ApiBaseChildResource.__init__(self, apiBase, apiBaseServer) + self.__mutex = threading.Lock() + self.__attitunes = [] + + # -------------------------------------------------------------------------- + # Update the container structure. + # -------------------------------------------------------------------------- + def _update(self, structure): + """Update the container structure. + @param structure: The new container structure dictionary. + """ + self.__mutex.acquire() + self.__attitunes = [] + keys = structure.keys() + keys.remove("result") + for i, key in enumerate(keys): + keys[i] = "%.3d" % int(key.replace("data", "")) + keys.sort() + for i, key in enumerate(keys): + keys[i] = "data%d" % int(key) + for key in keys: + self.__attitunes.append(Attitune(self.getParent(), + self.getServer(), self, structure[key])) + self.__mutex.release() + + # -------------------------------------------------------------------------- + # Get the attitune objects list. + # -------------------------------------------------------------------------- + def getAttitunes(self): + """Get the attitune objects list. + @return: A list of Attitune objects. + """ + self.__mutex.acquire() + result = self.__attitunes + self.__mutex.release() + return result + + # -------------------------------------------------------------------------- + # Get the number of attitunes contains in the container. + # -------------------------------------------------------------------------- + def getCount(self): + """Get the number of attitunes contains in the container. + @return: An integer. + """ + self.__mutex.acquire() + result = len(self.__attitunes) + self.__mutex.release() + return result + + # -------------------------------------------------------------------------- + # Show the attitunes name list in the console. + # -------------------------------------------------------------------------- + def showAttitunes(self): + """Show the attitunes name list in the console. + """ + result = [] + self.__mutex.acquire() + for attitune in self.__attitunes: + result.append(attitune.getDescription().getName()) + self.__mutex.release() + self._showStringList("Attitune names :", result) + + # -------------------------------------------------------------------------- + # Get an attitune object by it name or index. + # -------------------------------------------------------------------------- + def getAttitune(self, attitune): + """Get an attitune object by it name or index. + @param attitune: The name or index of the attitune. + @return: An Attitune object or None. + """ + self.__mutex.acquire() + if str(type(attitune)) == "<type 'int'>": + if attitune in range(len(self.__attitunes)): + result = self.__attitunes[attitune] + self.__mutex.release() + return result + else: + for attObject in self.__attitunes: + if attObject.getDescription().getName() == attitune: + result = attObject + self.__mutex.release() + return result + self.__mutex.release() + return None + + # -------------------------------------------------------------------------- + # Stop played attitune. + # -------------------------------------------------------------------------- + def stopAttitune(self): + """Stop played attitune. + @return: The success of the command. + """ + cmd = "attitune_manager/stop_attitune?" + return self._sendCommandBooleanResult(cmd) + + # -------------------------------------------------------------------------- + # Insert an attitune in the container. + # -------------------------------------------------------------------------- + def insertAttitune(self, attituneFileName): + """Insert an attitune in the container. + @param attituneFileName: Attitune file name. Can be a local or a distant + file. + @return: The success of the command. + """ + argsToSend = { + 'path' : attituneFileName, + } + cmd = "attitune_manager/insert_attitune?" + return self._sendCommandBooleanResult(cmd, argsToSend) + + # -------------------------------------------------------------------------- + # Remove an attitune from the container. + # -------------------------------------------------------------------------- + def removeAttitune(self, attituneName): + """Remove an attitune from the container. + @param attituneName: The name of the attitune. + @return: The success of the command. + """ + argsToSend = { + 'name' : attituneName, + } + cmd = "attitune_manager/remove_attitune?" + return self._sendCommandBooleanResult(cmd, argsToSend) Deleted: software_suite_v3/smart-core/smart-api/python/tags/before-plugin-gadget-refactoring/tuxisalive/api/base/ApiBaseChild.py =================================================================== --- softwares_suite_v3/kysoh/tuxware/api/python/trunk/tuxisalive/api/base/ApiBaseChild.py 2009-04-10 12:51:53 UTC (rev 4469) +++ software_suite_v3/smart-core/smart-api/python/tags/before-plugin-gadget-refactoring/tuxisalive/api/base/ApiBaseChild.py 2009-05-05 07:53:02 UTC (rev 4625) @@ -1,179 +0,0 @@ -# -*- coding: latin1 -*- - -# 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 - -from lib.Helper import Helper - -# ------------------------------------------------------------------------------ -# Base class to add functionalities in the API. -# ------------------------------------------------------------------------------ -class ApiBaseChild(Helper): - """Base class to add functionalities in the API. - """ - - # -------------------------------------------------------------------------- - # Constructor of the class. - # -------------------------------------------------------------------------- - def __init__(self, apiBase): - """Constructor of the class. - @param apiBase: ApiBase parent object. - """ - Helper.__init__(self) - self.__apiBase = apiBase - self.__eventsHandler = self.__apiBase.getEventsHandler() - self.__encoding = "latin-1" - self.__methodsList = [] - oElementsList = dir(self) - self.__methodsList.append("__init__") - for element in oElementsList: - if element.find("__") == -1: - if str(type(getattr(self, element)))== "<type 'instancemethod'>": - self.__methodsList.append(element) - - # -------------------------------------------------------------------------- - # Get the parent ApiBase object. - # -------------------------------------------------------------------------- - def getParent(self): - """Get the parent ApiBase object. - @return: A ApiBase object. - """ - return self.__apiBase - - # -------------------------------------------------------------------------- - # Get the global events handler. - # -------------------------------------------------------------------------- - def getEventsHandler(self): - """Get the global events handler. - @return: The events handler. - """ - return self.__eventsHandler - - # -------------------------------------------------------------------------- - # Set the source encoding. - # -------------------------------------------------------------------------- - def setEncoding(self, encoding = "latin-1"): - """Set the source encoding. Texts need to be encoded in "utf-8" before - to sending it to the HTTP server. - @param encoding: source encoding - example : "latin-1", "utf-8", "cp1252", ... - """ - self.__encoding = encoding - - # -------------------------------------------------------------------------- - # Set the current console encoding. - # -------------------------------------------------------------------------- - def isConsole(self): - """Set the current console encoding. - (Only if the api run in an interactive python context) - """ - import sys - self.__encoding = sys.stdin.encoding - - # -------------------------------------------------------------------------- - # Fixe a text with the correct encoding. - # -------------------------------------------------------------------------- - def _reencodeText(self, text, removeReturns = False): - """Fixe a text with the correct encoding. - @param text: Text to fixe. - @param removeReturns: True or False. Replace the returns chars by ". " - @return: The fixed text. - """ - # Try to encode the string - try: - text = text.decode(self.__encoding) - text = text.encode("utf-8", 'replace') - except: - pass - # Remove ending lines - if removeReturns: - text = text.replace("\n", ". ") - return text - - # -------------------------------------------------------------------------- - # Wait for a specific value of a status. - # -------------------------------------------------------------------------- - def _waitFor(self, statusName, statusValue, timeout = 99999.0): - """Wait for a specific value of a status. - @param statusName: Status name. - @param statusValue: Status value. - @param timeout: Maximal delay to wait. - """ - return self.__eventsHandler.waitCondition(statusName, (statusValue, - None), timeout) - - # -------------------------------------------------------------------------- - # Check the type of an object. - # -------------------------------------------------------------------------- - def _checkObjectType(self, name, value, requestedType): - """Check the type of an object. - @param name: Name of the object. - @param value: Current value of the object. - @param requestedType: Requested type. - """ - # Get the type of the value to check - vType = str(type(value)) - vType = vType[vType.find("'") + 1:vType.rfind("'")] - # Check the type of the value - if vType != requestedType: - print "Invalid type for [%s] : Need <type'%s'>" % (name, - requestedType) - return False - return True - - # -------------------------------------------------------------------------- - # Register a callback to an event. - # -------------------------------------------------------------------------- - def _registerEvent(self, eventName, eventValue, funct, idx = None): - """Register a callback to an event. - @param eventName: Event name. - @param eventValue: Event value. (can be None) - @param funct: pointer to the function. - @param idx: index from a previous register. - @return: the new index of the callback in the handler. - """ - nIdx = self.__eventsHandler.register(eventName, funct, (eventValue, - None), idx) - return nIdx - - # -------------------------------------------------------------------------- - # Unregister a callback from an event. - # -------------------------------------------------------------------------- - def _unregisterEvent(self, eventName, idx): - """Unregister a callback from an event. - Not available for CLIENT_LEVEL_ANONYME level. - @param eventName: Event name. - @param idx: index from a previous register. - """ - self.__eventsHandler.unregister(eventName, idx) - - # -------------------------------------------------------------------------- - # Insert a new event/status name in the events handler. - # -------------------------------------------------------------------------- - def _insertNewEvent(self, eventName): - """Insert a new event/status name in the events handler. - @param eventName: Event name. - """ - self.__eventsHandler.insert(eventName) - - # -------------------------------------------------------------------------- - # Get the last knowed value of a status/event. - # -------------------------------------------------------------------------- - def _requestOne(self, statusName): - """Get the last knowed value of a status/event. - @param statusName: Name of the status.event. - @return: The value. - """ - if not self._checkObjectType('statusName', statusName, "str"): - return None - eventHandler = self.__eventsHandler.getEventHandler(statusName) - if eventHandler == None: - return None - statusStruct = eventHandler.getLastState() - if statusStruct == None: - return None - if len(statusStruct) == 0: - return None - return statusStruct[0] Copied: software_suite_v3/smart-core/smart-api/python/tags/before-plugin-gadget-refactoring/tuxisalive/api/base/ApiBaseChild.py (from rev 4495, softwares_suite_v3/kysoh/tuxware/api/python/trunk/tuxisalive/api/base/ApiBaseChild.py) =================================================================== --- software_suite_v3/smart-core/smart-api/python/tags/before-plugin-gadget-refactoring/tuxisalive/api/base/ApiBaseChild.py (rev 0) +++ software_suite_v3/smart-core/smart-api/python/tags/before-plugin-gadget-refactoring/tuxisalive/api/base/ApiBaseChild.py 2009-05-05 07:53:02 UTC (rev 4625) @@ -0,0 +1,180 @@ +# -*- coding: latin1 -*- + +# 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 + +from lib.Helper import Helper + +# ------------------------------------------------------------------------------ +# Base class to add functionalities in the API. +# ------------------------------------------------------------------------------ +class ApiBaseChild(Helper): + """Base class to add functionalities in the API. + """ + + __ENCODING = "latin-1" + + # -------------------------------------------------------------------------- + # Constructor of the class. + # -------------------------------------------------------------------------- + def __init__(self, apiBase): + """Constructor of the class. + @param apiBase: ApiBase parent object. + """ + Helper.__init__(self) + self.__apiBase = apiBase + self.__eventsHandler = self.__apiBase.getEventsHandler() + self.__methodsList = [] + oElementsList = dir(self) + self.__methodsList.append("__init__") + for element in oElementsList: + if element.find("__") == -1: + if str(type(getattr(self, element)))== "<type 'instancemethod'>": + self.__methodsList.append(element) + + # -------------------------------------------------------------------------- + # Get the parent ApiBase object. + # -------------------------------------------------------------------------- + def getParent(self): + """Get the parent ApiBase object. + @return: A ApiBase object. + """ + return self.__apiBase + + # -------------------------------------------------------------------------- + # Get the global events handler. + # -------------------------------------------------------------------------- + def getEventsHandler(self): + """Get the global events handler. + @return: The events handler. + """ + return self.__eventsHandler + + # -------------------------------------------------------------------------- + # Set the source encoding. + # -------------------------------------------------------------------------- + def setEncoding(self, encoding = "latin-1"): + """Set the source encoding. Texts need to be encoded in "utf-8" before + to sending it to the HTTP server. + @param encoding: source encoding + example : "latin-1", "utf-8", "cp1252", ... + """ + ApiBaseChild.__ENCODING = encoding + + # -------------------------------------------------------------------------- + # Set the current console encoding. + # -------------------------------------------------------------------------- + def isConsole(self): + """Set the current console encoding. + (Only if the api run in an interactive python context) + """ + import sys + ApiBaseChild.__ENCODING = sys.stdin.encoding + + # -------------------------------------------------------------------------- + # Fixe a text with the correct encoding. + # -------------------------------------------------------------------------- + def _reencodeText(self, text, removeReturns = False): + """Fixe a text with the correct encoding. + @param text: Text to fixe. + @param removeReturns: True or False. Replace the returns chars by ". " + @return: The fixed text. + """ + # Try to encode the string + try: + text = text.decode(ApiBaseChild.__ENCODING) + text = text.encode("utf-8", 'replace') + except: + pass + # Remove ending lines + if removeReturns: + text = text.replace("\n", ". ") + return text + + # -------------------------------------------------------------------------- + # Wait for a specific value of a status. + # -------------------------------------------------------------------------- + def _waitFor(self, statusName, statusValue, timeout = 99999.0): + """Wait for a specific value of a status. + @param statusName: Status name. + @param statusValue: Status value. + @param timeout: Maximal delay to wait. + """ + return self.__eventsHandler.waitCondition(statusName, (statusValue, + None), timeout) + + # -------------------------------------------------------------------------- + # Check the type of an object. + # -------------------------------------------------------------------------- + def _checkObjectType(self, name, value, requestedType): + """Check the type of an object. + @param name: Name of the object. + @param value: Current value of the object. + @param requestedType: Requested type. + """ + # Get the type of the value to check + vType = str(type(value)) + vType = vType[vType.find("'") + 1:vType.rfind("'")] + # Check ... [truncated message content] |