[tuxdroid-svn] r4586 - softwares_suite_v3/kysoh/tuxware/server/trunk/util/applicationserver/gadget
Status: Beta
Brought to you by:
ks156
|
From: remi <c2m...@c2...> - 2009-04-24 09:55:51
|
Author: remi
Date: 2009-04-24 11:55:31 +0200 (Fri, 24 Apr 2009)
New Revision: 4586
Added:
softwares_suite_v3/kysoh/tuxware/server/trunk/util/applicationserver/gadget/GadgetTask.py
Modified:
softwares_suite_v3/kysoh/tuxware/server/trunk/util/applicationserver/gadget/Gadget.py
Log:
* added GadgetTask class to store "alert" informations from a "gadget -> plugin"
* added alerts "tasks" referencing in the Gadget object.
Modified: softwares_suite_v3/kysoh/tuxware/server/trunk/util/applicationserver/gadget/Gadget.py
===================================================================
--- softwares_suite_v3/kysoh/tuxware/server/trunk/util/applicationserver/gadget/Gadget.py 2009-04-24 09:25:57 UTC (rev 4585)
+++ softwares_suite_v3/kysoh/tuxware/server/trunk/util/applicationserver/gadget/Gadget.py 2009-04-24 09:55:31 UTC (rev 4586)
@@ -17,6 +17,7 @@
from GadgetDescription import GadgetDescription
from GadgetParameter import GadgetParameter
from GadgetToken import GadgetToken
+from GadgetTask import GadgetTask
# Default list of the supported language.
SUPPORTED_LANGUAGES_LIST = ["en", "fr", "nl", "es", "it", "pt", "ar", "da",
@@ -132,6 +133,12 @@
self.__defaultCheckCommandName = "check"
else:
self.__defaultCheckCommandName = self.__defaultRunCommandName
+ # Create tasks
+ self.__tasks = []
+ if dictionary.has_key('defaultScheduling'):
+ for key in dictionary['defaultScheduling'].keys():
+ self.__tasks.append(GadgetTask(self,
+ dictionary['defaultScheduling'][key]))
# Define interpreter
interpreterClass = GadgetInterpreter
if dictionary['interpreter']['kind'] == 'python':
@@ -238,6 +245,40 @@
return result
# --------------------------------------------------------------------------
+ # Get the gadget tasks objects list.
+ # --------------------------------------------------------------------------
+ def getTasks(self):
+ """Get the gadget tasks objects list.
+ @return: The gadget tasks objects list.
+ """
+ return self.__tasks
+
+ # --------------------------------------------------------------------------
+ # Get a task object by it name.
+ # --------------------------------------------------------------------------
+ def getCommand(self, taskName):
+ """Get a task object by it name.
+ @param taskName: The name of the task.
+ @return: The task object as GadgetTask 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):
Added: softwares_suite_v3/kysoh/tuxware/server/trunk/util/applicationserver/gadget/GadgetTask.py
===================================================================
--- softwares_suite_v3/kysoh/tuxware/server/trunk/util/applicationserver/gadget/GadgetTask.py (rev 0)
+++ softwares_suite_v3/kysoh/tuxware/server/trunk/util/applicationserver/gadget/GadgetTask.py 2009-04-24 09:55:31 UTC (rev 4586)
@@ -0,0 +1,372 @@
+# 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
+
+# ------------------------------------------------------------------------------
+# Gadget task.
+# ------------------------------------------------------------------------------
+class GadgetTask(object):
+ """Gadget task.
+ """
+
+ # --------------------------------------------------------------------------
+ # Constructor of the class.
+ # --------------------------------------------------------------------------
+ def __init__(self, parent, dictionary):
+ """Constructor of the class.
+ @param parent: Parent Gadget.
+ @param dictionary: Description as dictionary.
+ """
+ self.__parent = parent
+ self.__dictionary = dictionary
+ self.__name = None
+ self.__description = None
+ self.__command = None
+ self.__type = None
+ self.__activated = None
+ self.__weekMask = None
+ self.__weekMaskType = None
+ self.__weekMaskVisible = None
+ self.__date = None
+ self.__dateVisible = None
+ self.__hoursBegin = None
+ self.__hoursBeginMask = None
+ self.__hoursBeginVisible = None
+ self.__hoursEnd = None
+ self.__hoursEndMask = None
+ self.__hoursEndVisible = None
+ self.__delay = None
+ self.__delayMask = None
+ self.__delayVisible = None
+ self.__update(dictionary)
+
+ # --------------------------------------------------------------------------
+ # Get the parent gadget.
+ # --------------------------------------------------------------------------
+ def getParent(self):
+ """Get the parent gadget.
+ @return: A Gadget 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):
+ """Update the description.
+ """
+ # Save the dictionary
+ self.__dictionary = dictionary
+ # Get the descriptor values
+ # Mandatory values
+ self.__name = dictionary['name']
+ self.__description = dictionary['description']
+ self.__command = dictionary['command'].upper()
+ self.__type = dictionary['type']
+ self.__activated = dictionary['activated']
+ # Optional values
+ self.__weekMask = "true,true,true,true,true,true,true"
+ if dictionary.has_key('weekMask'):
+ self.__weekMask = dictionary['weekMask']
+ self.__weekMaskType = "weekMaskType"
+ if dictionary.has_key('weekMaskType'):
+ self.__weekMaskType = dictionary['weekMaskType'].lower()
+ self.__weekMaskVisible = "false"
+ if dictionary.has_key('weekMaskVisible'):
+ self.__weekMaskVisible = dictionary['weekMaskVisible'].lower()
+ self.__date = "0000/00/00"
+ if dictionary.has_key('date'):
+ self.__date = dictionary['date']
+ self.__dateVisible = "false"
+ if dictionary.has_key('dateVisible'):
+ self.__dateVisible = dictionary['dateVisible'].lower()
+ self.__hoursBegin = "00:00:00"
+ if dictionary.has_key('hoursBegin'):
+ self.__hoursBegin = dictionary['hoursBegin']
+ self.__hoursBeginMask = "false,false,false"
+ if dictionary.has_key('hoursBeginMask'):
+ self.__hoursBeginMask = dictionary['hoursBeginMask'].lower()
+ self.__hoursBeginVisible = "false"
+ if dictionary.has_key('hoursBeginVisible'):
+ self.__hoursBeginVisible = dictionary['hoursBeginVisible'].lower()
+ self.__hoursEnd = "00:00:00"
+ if dictionary.has_key('hoursEnd'):
+ self.__hoursEnd = dictionary['hoursEnd']
+ self.__hoursEndMask = "false,false,false"
+ if dictionary.has_key('hoursEndMask'):
+ self.__hoursEndMask = dictionary['hoursEndMask'].lower()
+ self.__hoursEndVisible = "false"
+ if dictionary.has_key('hoursEndVisible'):
+ self.__hoursEndVisible = dictionary['hoursEndVisible'].lower()
+ self.__delay = "00:01:00"
+ if dictionary.has_key('delay'):
+ self.__delay = dictionary['delay']
+ self.__delayMask = "false,false,false"
+ if dictionary.has_key('delayMask'):
+ self.__delayMask = dictionary['delayMask'].lower()
+ self.__delayVisible = "false"
+ if dictionary.has_key('delayVisible'):
+ self.__delayVisible = dictionary['delayVisible'].lower()
+
+ # --------------------------------------------------------------------------
+ # Get the task name.
+ # --------------------------------------------------------------------------
+ def getName(self):
+ """Get the task name.
+ @return: A string.
+ """
+ return self.__name
+
+ # --------------------------------------------------------------------------
+ # Get the translated name of the task.
+ # --------------------------------------------------------------------------
+ def getTranslatedName(self, language = None):
+ """Get the translated name of the task.
+ @return: A string.
+ """
+ if language == None:
+ return self.__parent.tr(self.__name)
+ else:
+ return self.__parent.tr2(language, self.__name)
+
+ # --------------------------------------------------------------------------
+ # Get the translated description of the gadget.
+ # --------------------------------------------------------------------------
+ def getDescription(self, language = None):
+ """Get the translated description of the gadget.
+ @return: A string.
+ """
+ if language == None:
+ return self.__parent.tr(self.__description)
+ else:
+ return self.__parent.tr2(language, self.__description)
+
+ # --------------------------------------------------------------------------
+ # Get the command.
+ # --------------------------------------------------------------------------
+ def getCommand(self):
+ """Get the command.
+ @return: A string.
+ """
+ return self.__command
+
+ # --------------------------------------------------------------------------
+ # Get the task type.
+ # --------------------------------------------------------------------------
+ def getType(self):
+ """Get the task type.
+ @return: A string.
+ """
+ return self.__type
+
+ # --------------------------------------------------------------------------
+ # Get if the task is activated or not.
+ # --------------------------------------------------------------------------
+ def isActivated(self):
+ """Get if the task is activated or not.
+ @return: A boolean.
+ """
+ if self.__activated.lower() == "true":
+ return True
+ else:
+ return False
+
+ # --------------------------------------------------------------------------
+ # Set if the task is activated or not.
+ # --------------------------------------------------------------------------
+ def setActivated(self, scheduler, isActivated):
+ """Set if the task is activated or not.
+ * Activation will create a task in the scheduler.
+ * Deactivation will create the task from the scheduler.
+ @param scheduler: Scheduler object.
+ @param isActivated: Boolean.
+ """
+ #TODO: Complete this after the scheduler updating.
+ pass
+
+ # --------------------------------------------------------------------------
+ # Get the week mask.
+ # --------------------------------------------------------------------------
+ def getWeekMask(self):
+ """Get if the week mask.
+ @return: A list of 7 booleans.
+ """
+ tmpList = self.__weekMask.split(",")
+ result = []
+ for value in tmpList:
+ if value.lower() == "true":
+ result.append(True)
+ else:
+ result.append(False)
+ if len(result) != 7:
+ result = [True, True, True, True, True, True, True]
+ return result
+
+ # --------------------------------------------------------------------------
+ # Get the week mask type.
+ # --------------------------------------------------------------------------
+ def getWeekMaskType(self):
+ """Get the week mask type.
+ @return: A string <"flat"|"weekpart"|"exclusive">.
+ """
+ return self.__weekMaskType
+
+ # --------------------------------------------------------------------------
+ # Get if the week mask is visible or not.
+ # --------------------------------------------------------------------------
+ def getWeekMaskIsVisible(self):
+ """Get if the week mask is visible or not.
+ @return: A boolean.
+ """
+ if self.__weekMaskVisible.lower() == "true":
+ return True
+ else:
+ return False
+
+ # --------------------------------------------------------------------------
+ # Get the date.
+ # --------------------------------------------------------------------------
+ def getDate(self):
+ """Get the date.
+ @return: A string "YYYY/MM/DD".
+ """
+ return self.__date
+
+ # --------------------------------------------------------------------------
+ # Get if the date is visible or not.
+ # --------------------------------------------------------------------------
+ def getDateIsVisible(self):
+ """Get if the week mask is visible or not.
+ @return: A boolean.
+ """
+ if self.__dateVisible.lower() == "true":
+ return True
+ else:
+ return False
+
+ # --------------------------------------------------------------------------
+ # Get the hours begin.
+ # --------------------------------------------------------------------------
+ def getHoursBegin(self):
+ """Get the hours begin.
+ @return: A string "HH:MM:SS".
+ """
+ return self.__hoursBegin
+
+ # --------------------------------------------------------------------------
+ # Get the hours begin mask.
+ # --------------------------------------------------------------------------
+ def getHoursBeginMask(self):
+ """Get the hours begin mask.
+ @return: A string.
+ """
+ tmpList = self.__hoursBeginMask.split(",")
+ result = []
+ for value in tmpList:
+ if value.lower() == "true":
+ result.append(True)
+ else:
+ result.append(False)
+ if len(result) != 3:
+ result = [True, True, True]
+ return result
+
+ # --------------------------------------------------------------------------
+ # Get if the hours begin is visible or not.
+ # --------------------------------------------------------------------------
+ def getHoursBeginIsVisible(self):
+ """Get if the hours begin is visible or not.
+ @return: A boolean.
+ """
+ if self.__hoursBeginVisible.lower() == "true":
+ return True
+ else:
+ return False
+
+ # --------------------------------------------------------------------------
+ # Get the hours end.
+ # --------------------------------------------------------------------------
+ def getHoursEnd(self):
+ """Get the hours end.
+ @return: A string "HH:MM:SS".
+ """
+ return self.__hoursEnd
+
+ # --------------------------------------------------------------------------
+ # Get the hours end mask.
+ # --------------------------------------------------------------------------
+ def getHoursEndMask(self):
+ """Get the hours end mask.
+ @return: A string.
+ """
+ tmpList = self.__hoursEndMask.split(",")
+ result = []
+ for value in tmpList:
+ if value.lower() == "true":
+ result.append(True)
+ else:
+ result.append(False)
+ if len(result) != 3:
+ result = [True, True, True]
+ return result
+
+ # --------------------------------------------------------------------------
+ # Get if the hours end is visible or not.
+ # --------------------------------------------------------------------------
+ def getHoursEndIsVisible(self):
+ """Get if the hours end is visible or not.
+ @return: A boolean.
+ """
+ if self.__hoursEndVisible.lower() == "true":
+ return True
+ else:
+ return False
+
+ # --------------------------------------------------------------------------
+ # Get the delay.
+ # --------------------------------------------------------------------------
+ def getDelay(self):
+ """Get the delay.
+ @return: A string "HH:MM:SS".
+ """
+ return self.__delay
+
+ # --------------------------------------------------------------------------
+ # Get the delay mask.
+ # --------------------------------------------------------------------------
+ def getDelayMask(self):
+ """Get the delay mask.
+ @return: A string.
+ """
+ tmpList = self.__delayMask.split(",")
+ result = []
+ for value in tmpList:
+ if value.lower() == "true":
+ result.append(True)
+ else:
+ result.append(False)
+ if len(result) != 3:
+ result = [True, True, True]
+ return result
+
+ # --------------------------------------------------------------------------
+ # Get if the delay is visible or not.
+ # --------------------------------------------------------------------------
+ def getDelayIsVisible(self):
+ """Get if the delay is visible or not.
+ @return: A boolean.
+ """
+ if self.__delayVisible.lower() == "true":
+ return True
+ else:
+ return False
Property changes on: softwares_suite_v3/kysoh/tuxware/server/trunk/util/applicationserver/gadget/GadgetTask.py
___________________________________________________________________
Name: svn:keywords
+ Id
|