Author: remi
Date: 2009-04-24 19:16:03 +0200 (Fri, 24 Apr 2009)
New Revision: 4592

Modified:
   
softwares_suite_v3/kysoh/tuxware/server/trunk/resources/01_robot_system/resourceScheduler.py
   
softwares_suite_v3/kysoh/tuxware/server/trunk/resources/03_advanced_api/resourceTaskCreation.py
   softwares_suite_v3/kysoh/tuxware/server/trunk/util/scheduler/Scheduler.py
   softwares_suite_v3/kysoh/tuxware/server/trunk/util/scheduler/Task.py
   
softwares_suite_v3/kysoh/tuxware/server/trunk/util/scheduler/TaskDescription.py
Log:
* improved scheduler functionalities
* updated resources and services

Modified: 
softwares_suite_v3/kysoh/tuxware/server/trunk/resources/01_robot_system/resourceScheduler.py
===================================================================
--- 
softwares_suite_v3/kysoh/tuxware/server/trunk/resources/01_robot_system/resourceScheduler.py
        2009-04-24 13:24:03 UTC (rev 4591)
+++ 
softwares_suite_v3/kysoh/tuxware/server/trunk/resources/01_robot_system/resourceScheduler.py
        2009-04-24 17:16:03 UTC (rev 4592)
@@ -100,7 +100,7 @@
             splitedStr = weekMaskString.split(",")
             if len(splitedStr) == 7:
                 for i, value in enumerate(splitedStr):
-                    if value == "1":
+                    if value == "true":
                         result[i] = True
                     else:
                         result[i] = False
@@ -108,6 +108,28 @@
             pass
         return result
 
+    def dateStringToList(self, dateString):
+        result = [0, 0, 0]
+        try:
+            splitedStr = dateString.split("/")
+            if len(splitedStr) == 3:
+                for i, value in enumerate(splitedStr):
+                    result[i] = int(value)
+        except:
+            pass
+        return result
+
+    def timeStringToList(self, timeString):
+        result = [0, 0, 0]
+        try:
+            splitedStr = timeString.split(":")
+            if len(splitedStr) == 3:
+                for i, value in enumerate(splitedStr):
+                    result[i] = int(value)
+        except:
+            pass
+        return result
+
     # 
--------------------------------------------------------------------------
     # Public methods
     # 
--------------------------------------------------------------------------
@@ -121,98 +143,89 @@
         """
         return self.__scheduler
 
-    def createTask_RunEveryX(self, name, weekMask, hour, minute, second,
+    def createTask_RunEveryX(self, name, weekMask, hoursBegin, hoursEnd, delay,
         command, arguments, data):
         """Create a task which start every x delay.
         - hour, minute, second define the time delay between 2 executions.
         - Typically for a pooling task.
         @param name: Task name.
         @param weekMask: Week mask. [True, True, True, True, True, True, True]
-        @param hour: <0..23>
-        @param minute: <0..59>
-        @param second: <0..59>
+        @param hoursBegin: Hours begin. [Hour, Minute, Second]
+        @param hoursEnd: Hours end. [Hour, Minute, Second]
+        @param delay: Delay. [Hour, Minute, Second]
         @param command: Command to execute.
         @param arguments: Arguments of the command.
         @param data: User data.
         @return: The task id and the task name or None None.
         """
-        task = Task(SCH_LOOP_REL, weekMask, hour, minute, second, -1, -1, -1,
-            command, arguments, data)
+        task = Task(SCH_LOOP_REL, weekMask, [0, 0, 0], hoursBegin, hoursEnd,
+            delay, command, arguments, data)
         return self.__scheduler.insertTask(task, name)
 
-    def createTask_RunEveryXFromFullHour(self, name, weekMask, hour, minute, 
second,
-        command, arguments, data):
+    def createTask_RunEveryXFromFullHour(self, name, weekMask, hoursBegin,
+        hoursEnd, delay, command, arguments, data):
         """Create a task which start every x delay synchronized with hh:00:00.
         - Typically for an alarm task. (Clock gadget start at hour:00, 15, 30, 
45)
         - The first execution will be at hour begin + delay time.
         @param name: Task name.
         @param weekMask: Week mask. [True, True, True, True, True, True, True]
-        @param hour: <0..23>
-        @param minute: <0..59>
-        @param second: <0..59>
+        @param hoursBegin: Hours begin. [Hour, Minute, Second]
+        @param hoursEnd: Hours end. [Hour, Minute, Second]
+        @param delay: Delay. [Hour, Minute, Second]
         @param command: Command to execute.
         @param arguments: Arguments of the command.
         @param data: User data.
         @return: The task id and the task name or None None.
         """
-        task = Task(SCH_LOOP_ABS, weekMask, hour, minute, second, -1, -1, -1,
-            command, arguments, data)
+        task = Task(SCH_LOOP_ABS, weekMask, [0, 0, 0], hoursBegin, hoursEnd,
+            delay, command, arguments, data)
         return self.__scheduler.insertTask(task, name)
 
-    def createTask_RunDailyAtTime(self, name, weekMask, hour, minute, second,
-        command, arguments, data):
+    def createTask_RunDailyAtTime(self, name, weekMask, hoursBegin, command,
+        arguments, data):
         """Create a daily task which run at fixed time.
         @param name: Task name.
         @param weekMask: Week mask. [True, True, True, True, True, True, True]
-        @param hour: <0..23>
-        @param minute: <0..59>
-        @param second: <0..59>
+        @param hoursBegin: Hours begin. [Hour, Minute, Second]
         @param command: Command to execute.
         @param arguments: Arguments of the command.
         @param data: User data.
         @return: The task id and the task name or None None.
         """
-        task = Task(SCH_ONCE_ABS, weekMask, hour, minute, second, -1, -1, -1,
-            command, arguments, data)
+        task = Task(SCH_ONCE_ABS, weekMask, [0, 0, 0], hoursBegin, [0, 0, 0],
+            [0, 0, 0], command, arguments, data)
         return self.__scheduler.insertTask(task, name)
 
-    def createTask_RunOnceAtDateTime(self, name, year, month, day, hour, 
minute,
-        second, command, arguments, data):
+    def createTask_RunOnceAtDateTime(self, name, date, hoursBegin, command,
+        arguments, data):
         """Create a task which run once time at a specific date time.
         @param name: Task name.
-        @param year: Year.
-        @param month: <1..12>
-        @param day: <1..31>
-        @param hour: <0..23>
-        @param minute: <0..59>
-        @param second: <0..59>
+        @param date: Date. [Year, Month, Day]
+        @param hoursBegin: Hours begin. [Hour, Minute, Second]
         @param command: Command to execute.
         @param arguments: Arguments of the command.
         @param data: User data.
         @return: The task id and the task name or None None.
         """
         task = Task(SCH_ONCE_ABS, [True, True, True, True, True, True, True],
-            hour, minute, second, year, month, day, command, arguments, data)
+            date, hoursBegin, [0, 0, 0], [0, 0, 0], command, arguments, data)
         return self.__scheduler.insertTask(task, name)
 
-    def createTask_RunOnceDelayed(self, name, hour, minute, second, command,
-        arguments, data):
+    def createTask_RunOnceDelayed(self, name, delay, command, arguments, data):
         """Create a task which run once time after a delay.
         @param name: Task name.
-        @param hour: <0..23>
-        @param minute: <0..59>
-        @param second: <0..59>
+        @param delay: Delay. [Hour, Minute, Second]
         @param command: Command to execute.
         @param arguments: Arguments of the command.
         @param data: User data.
         @return: The task id and the task name or None None.
         """
         task = Task(SCH_ONCE_REL, [True, True, True, True, True, True, True],
-            hour, minute, second, -1, -1, -1, command, arguments, data)
+            [0, 0, 0], [0, 0, 0], [0, 0, 0], delay, command, arguments, data)
         return self.__scheduler.insertTask(task, name)
 
-    def createTask(self, command, arguments, taskType, taskName, weekMask, 
hour,
-        minute, second, year, month, day, data):
+    def createTask(self, command, arguments, taskType, taskName, weekMask, 
date,
+        hoursBegin, hoursEnd, delay, data):
         """Create a task to start a gadget.
         @param command: Command to execute.
         @param arguments: Arguments of the command.
@@ -220,30 +233,28 @@
                           ONCE DELAYED>
         @param taskName: Task name.
         @param weekMask: Week mask. [True, True, True, True, True, True, True]
-        @param hour: <0..23>
-        @param minute: <0..59>
-        @param second: <0..59>
-        @param year: Year.
-        @param month: <1..12>
-        @param day: <1..31>
+        @param date: Date. [Year, Month, Day]
+        @param hoursBegin: Hours begin. [Hour, Minute, Second]
+        @param hoursEnd: Hours end. [Hour, Minute, Second]
+        @param delay: Delay. [Hour, Minute, Second]
         @param data: User data.
         @return: The task id and the task name or None None.
         """
         if taskType == "EVERY X":
-            return self.createTask_RunEveryX(taskName, weekMask, hour, minute,
-                second, command, arguments, data)
+            return self.createTask_RunEveryX(taskName, weekMask, hoursBegin,
+                hoursEnd, delay, command, arguments, data)
         if taskType == "EVERY X FROM FULL HOUR":
             return self.createTask_RunEveryXFromFullHour(taskName, weekMask,
-                hour, minute, second, command, arguments, data)
+                hoursBegin, hoursEnd, delay, command, arguments, data)
         if taskType == "DAILY AT":
-            return self.createTask_RunDailyAtTime(taskName, weekMask, hour,
-                minute, second, command, arguments, data)
+            return self.createTask_RunDailyAtTime(taskName, weekMask,
+                hoursBegin, command, arguments, data)
         if taskType == "ONCE AT":
-            return self.createTask_RunOnceAtDateTime(taskName, year, month, 
day,
-                hour, minute, second, command, arguments, data)
+            return self.createTask_RunOnceAtDateTime(taskName, date, 
hoursBegin,
+                command, arguments, data)
         if taskType == "ONCE DELAYED":
-            return self.createTask_RunOnceDelayed(taskName, hour, minute,
-                second, command, arguments, data)
+            return self.createTask_RunOnceDelayed(taskName, delay,
+                command, arguments, data)
         return None, None
 
     def executeTask(self, taskId):

Modified: 
softwares_suite_v3/kysoh/tuxware/server/trunk/resources/03_advanced_api/resourceTaskCreation.py
===================================================================
--- 
softwares_suite_v3/kysoh/tuxware/server/trunk/resources/03_advanced_api/resourceTaskCreation.py
     2009-04-24 13:24:03 UTC (rev 4591)
+++ 
softwares_suite_v3/kysoh/tuxware/server/trunk/resources/03_advanced_api/resourceTaskCreation.py
     2009-04-24 17:16:03 UTC (rev 4592)
@@ -21,7 +21,7 @@
     # 
--------------------------------------------------------------------------
 
     def createTaskStartGadget(self, gadgetUuid, gadgetCommand, 
gadgetParameters,
-        taskType, taskName, weekMask, hour, minute, second, year, month, day):
+        taskType, taskName, weekMask, date, hoursBegin, hoursEnd, delay):
         """Create a task to start a gadget.
         @param gadgetUuid: Gadget uuid.
         @param gadgetCommand: Gadget command.
@@ -30,12 +30,10 @@
                           ONCE DELAYED>
         @param taskName: Task name.
         @param weekMask: Week mask. [True, True, True, True, True, True, True]
-        @param hour: <0..23>
-        @param minute: <0..59>
-        @param second: <0..59>
-        @param year: Year.
-        @param month: <1..12>
-        @param day: <1..31>
+        @param date: Date. [Year, Month, Day]
+        @param hoursBegin: Hours begin. [Hour, Minute, Second]
+        @param hoursEnd: Hours end. [Hour, Minute, Second]
+        @param delay: Delay. [Hour, Minute, Second]
         """
         command = "resourceGadgetFramework.startGadget"
         arguments = (gadgetUuid, gadgetCommand, gadgetParameters)
@@ -46,22 +44,20 @@
             'parameters' : gadgetParameters,
         }
         return resourceScheduler.createTask(command, arguments, taskType,
-            taskName, weekMask, hour, minute, second, year, month, day, data)
+            taskName, weekMask, date, hoursBegin, hoursEnd, delay, data)
 
     def createTaskStopGadget(self, gadgetUuid, taskType, taskName, weekMask,
-        hour, minute, second, year, month, day):
+        date, hoursBegin, hoursEnd, delay):
         """Create a sheduled task to stop a gadget.
         @param gadgetUuid: Gadget uuid.
         @param taskType: <EVERY X|EVERY X FROM FULL HOUR|DAILY AT|ONCE AT|
                           ONCE DELAYED>
         @param taskName: Task name.
         @param weekMask: Week mask. [True, True, True, True, True, True, True]
-        @param hour: <0..23>
-        @param minute: <0..59>
-        @param second: <0..59>
-        @param year: Year.
-        @param month: <1..12>
-        @param day: <1..31>
+        @param date: Date. [Year, Month, Day]
+        @param hoursBegin: Hours begin. [Hour, Minute, Second]
+        @param hoursEnd: Hours end. [Hour, Minute, Second]
+        @param delay: Delay. [Hour, Minute, Second]
         """
         command = "resourceGadgetFramework.stopGadget"
         arguments = (gadgetUuid,)
@@ -70,22 +66,20 @@
             'uuid' : gadgetUuid,
         }
         return resourceScheduler.createTask(command, arguments, taskType,
-            taskName, weekMask, hour, minute, second, year, month, day, data)
+            taskName, weekMask, date, hoursBegin, hoursEnd, delay, data)
 
     def createTaskPlayAttitune(self, attituneName, taskType, taskName, 
weekMask,
-        hour, minute, second, year, month, day):
-        """Create a task to start a gadget.
+        date, hoursBegin, hoursEnd, delay):
+        """Create a task to start an attitune.
         @param attituneName: Attitune name.
         @param taskType: <EVERY X|EVERY X FROM FULL HOUR|DAILY AT|ONCE AT|
                           ONCE DELAYED>
         @param taskName: Task name.
         @param weekMask: Week mask. [True, True, True, True, True, True, True]
-        @param hour: <0..23>
-        @param minute: <0..59>
-        @param second: <0..59>
-        @param year: Year.
-        @param month: <1..12>
-        @param day: <1..31>
+        @param date: Date. [Year, Month, Day]
+        @param hoursBegin: Hours begin. [Hour, Minute, Second]
+        @param hoursEnd: Hours end. [Hour, Minute, Second]
+        @param delay: Delay. [Hour, Minute, Second]
         """
         command = "resourceAttituneManager.playAttitune"
         arguments = (attituneName, 0.0)
@@ -94,7 +88,7 @@
             'attituneName' : attituneName,
         }
         return resourceScheduler.createTask(command, arguments, taskType,
-            taskName, weekMask, hour, minute, second, year, month, day, data)
+            taskName, weekMask, date, hoursBegin, hoursEnd, delay, data)
 
 # Create an instance of the resource
 resourceTaskCreation = TDSResourceTaskCreation("resourceTaskCreation")
@@ -114,12 +108,10 @@
             'task_type' : '<EVERY X|EVERY X FROM FULL HOUR|DAILY AT|ONCE 
AT|ONCE DELAYED>',
             'task_name' : 'string',
             'week_mask' : 'string',
-            'hour' : 'uint8',
-            'minute' : 'uint8',
-            'second' : 'uint8',
-            'year' : 'int',
-            'month' : 'int8',
-            'day' : 'int8',
+            'date' : 'string',
+            'hoursBegin' : 'string',
+            'hoursEnd' : 'string',
+            'delay' : 'string',
         }
         self.minimalUserLevel = TDS_CLIENT_LEVEL_ANONYMOUS
         self.exclusiveExecution = False
@@ -141,15 +133,13 @@
         taskType = parameters['task_type']
         taskName = parameters['task_name']
         weekMask = 
resourceScheduler.weekMaskStringToList(parameters['week_mask'])
-        hour = parameters['hour']
-        minute = parameters['minute']
-        second = parameters['second']
-        year = parameters['year']
-        month = parameters['month']
-        day = parameters['day']
+        date = resourceScheduler.dateStringToList(parameters['date'])
+        hoursBegin = 
resourceScheduler.timeStringToList(parameters['hoursBegin'])
+        hoursEnd = resourceScheduler.timeStringToList(parameters['hoursEnd'])
+        delay = resourceScheduler.timeStringToList(parameters['delay'])
         id, name = resourceTaskCreation.createTaskStartGadget(gadgetUuid,
-            gadgetCommand, gadgetParameters, taskType, taskName, weekMask, 
hour,
-            minute, second, year, month, day)
+            gadgetCommand, gadgetParameters, taskType, taskName, weekMask, 
date,
+            hoursBegin, hoursEnd, delay)
         if id != None:
             contentStruct['root']['data'] = {
                 'id' : id,
@@ -173,12 +163,10 @@
             'task_type' : '<EVERY X|EVERY X FROM FULL HOUR|DAILY AT|ONCE 
AT|ONCE DELAYED>',
             'task_name' : 'string',
             'week_mask' : 'string',
-            'hour' : 'uint8',
-            'minute' : 'uint8',
-            'second' : 'uint8',
-            'year' : 'int',
-            'month' : 'int8',
-            'day' : 'int8',
+            'date' : 'string',
+            'hoursBegin' : 'string',
+            'hoursEnd' : 'string',
+            'delay' : 'string',
         }
         self.minimalUserLevel = TDS_CLIENT_LEVEL_ANONYMOUS
         self.exclusiveExecution = False
@@ -193,15 +181,12 @@
         taskType = parameters['task_type']
         taskName = parameters['task_name']
         weekMask = 
resourceScheduler.weekMaskStringToList(parameters['week_mask'])
-        hour = parameters['hour']
-        minute = parameters['minute']
-        second = parameters['second']
-        year = parameters['year']
-        month = parameters['month']
-        day = parameters['day']
+        date = resourceScheduler.dateStringToList(parameters['date'])
+        hoursBegin = 
resourceScheduler.timeStringToList(parameters['hoursBegin'])
+        hoursEnd = resourceScheduler.timeStringToList(parameters['hoursEnd'])
+        delay = resourceScheduler.timeStringToList(parameters['delay'])
         id, name = resourceTaskCreation.createTaskStopGadget(gadgetUuid,
-            taskType, taskName, weekMask, hour, minute, second, year, month,
-            day)
+            taskType, taskName, weekMask, date, hoursBegin, hoursEnd, delay)
         if id != None:
             contentStruct['root']['data'] = {
                 'id' : id,
@@ -225,12 +210,10 @@
             'task_type' : '<EVERY X|EVERY X FROM FULL HOUR|DAILY AT|ONCE 
AT|ONCE DELAYED>',
             'task_name' : 'string',
             'week_mask' : 'string',
-            'hour' : 'uint8',
-            'minute' : 'uint8',
-            'second' : 'uint8',
-            'year' : 'int',
-            'month' : 'int8',
-            'day' : 'int8',
+            'date' : 'string',
+            'hoursBegin' : 'string',
+            'hoursEnd' : 'string',
+            'delay' : 'string',
         }
         self.minimalUserLevel = TDS_CLIENT_LEVEL_ANONYMOUS
         self.exclusiveExecution = False
@@ -245,15 +228,12 @@
         taskType = parameters['task_type']
         taskName = parameters['task_name']
         weekMask = 
resourceScheduler.weekMaskStringToList(parameters['week_mask'])
-        hour = parameters['hour']
-        minute = parameters['minute']
-        second = parameters['second']
-        year = parameters['year']
-        month = parameters['month']
-        day = parameters['day']
+        date = resourceScheduler.dateStringToList(parameters['date'])
+        hoursBegin = 
resourceScheduler.timeStringToList(parameters['hoursBegin'])
+        hoursEnd = resourceScheduler.timeStringToList(parameters['hoursEnd'])
+        delay = resourceScheduler.timeStringToList(parameters['delay'])
         id, name = resourceTaskCreation.createTaskPlayAttitune(attituneName,
-            taskType, taskName, weekMask, hour, minute, second, year, month,
-            day)
+            taskType, taskName, weekMask, date, hoursBegin, hoursEnd, delay)
         if id != None:
             contentStruct['root']['data'] = {
                 'id' : id,

Modified: 
softwares_suite_v3/kysoh/tuxware/server/trunk/util/scheduler/Scheduler.py
===================================================================
--- softwares_suite_v3/kysoh/tuxware/server/trunk/util/scheduler/Scheduler.py   
2009-04-24 13:24:03 UTC (rev 4591)
+++ softwares_suite_v3/kysoh/tuxware/server/trunk/util/scheduler/Scheduler.py   
2009-04-24 17:16:03 UTC (rev 4592)
@@ -110,6 +110,8 @@
                     pass
         # Store task configurations
         for taskInfo in self.__tasksToExecuteStack:
+            if not taskInfo[TASK_OBJECT].isStorable():
+                continue
             isFound = False
             for file in files:
                 if taskInfo[TASK_OBJECT].getDescription().getId() == file:

Modified: softwares_suite_v3/kysoh/tuxware/server/trunk/util/scheduler/Task.py
===================================================================
--- softwares_suite_v3/kysoh/tuxware/server/trunk/util/scheduler/Task.py        
2009-04-24 13:24:03 UTC (rev 4591)
+++ softwares_suite_v3/kysoh/tuxware/server/trunk/util/scheduler/Task.py        
2009-04-24 17:16:03 UTC (rev 4592)
@@ -19,71 +19,78 @@
     # 
--------------------------------------------------------------------------
     # Constructor of the class.
     # 
--------------------------------------------------------------------------
-    def __init__(self, ruleType, weekMask, hour, minute, second, year, month,
-        day, command, arguments, data):
+    def __init__(self, ruleType, weekMask, date, hoursBegin, hoursEnd, delay,
+        command, arguments, data, storable = True):
         """Constructor of the class.
         @param ruleType: <SCH_LOOP_ABS|SCH_LOOP_REL|SCH_ONCE_ABS|SCH_ONCE_REL>
         @param weekMask: Week mask. [True, True, True, True, True, True, True]
-        @param hour: <hh>
-        @param minute: <mm>
-        @param second: <ss>
-        @param year: <yyyy> or -1
-        @param month: <mm> or -1
-        @param day: <dd> or -1
+        @param date: Date string as format [YYYY, MM, DD].
+        @param hoursBegin: Hours begin as format [HH, MM, SS]
+        @param hoursEnd: Hours end as format [HH, MM, SS]
+        @param delay: Delay as format [HH, MM, SS]
         @param command: Command to execute as string.
         @param arguments: Arguments of the command as tuple.
         @param data: User data.
+        @param storable: Task is storable or not.
         """
         dictionary = {
             'type' : ruleType,
             'weekMask' : weekMask,
-            'year' : year,
-            'month' : month,
-            'day' : day,
-            'hour' : hour,
-            'minute' : minute,
-            'second' : second,
+            'date' : date,
+            'hoursBegin' : hoursBegin,
+            'hoursEnd' : hoursEnd,
+            'delay' : delay,
             'command' : command,
             'arguments' : arguments,
         }
         self.__data = data
+        self.__storable = storable
         self.__description = TaskDescription(self, dictionary)
         now = datetime.datetime.now()
         self.__monthAtStart = now.month
         self.__monthMask = self.__createMonthMask(self.__monthAtStart)
         if ruleType == SCH_LOOP_ABS:
-            if hour == 0:
-                if minute == 0:
+            if delay[0] == 0:
+                if delay[1] == 0:
                     m = 0
                 else:
-                    m = int(now.minute / minute) * minute
+                    m = int(now.minute / delay[1]) * delay[1]
                 self.__startTime = datetime.datetime(now.year, now.month,
-                    now.day, now.hour - hour, m, second)
-                self.__incrementTime = datetime.timedelta(minutes = minute)
+                    now.day, now.hour - delay[0], m, delay[2])
+                self.__incrementTime = datetime.timedelta(minutes = delay[1])
             else:
                 self.__startTime = datetime.datetime(now.year, now.month,
-                    now.day, now.hour - hour, minute, second)
-                self.__incrementTime = datetime.timedelta(hours = hour)
+                    now.day, now.hour - delay[0], delay[1], delay[2])
+                self.__incrementTime = datetime.timedelta(hours = delay[0])
         elif ruleType == SCH_LOOP_REL:
             self.__startTime = datetime.datetime.now()
-            self.__incrementTime = datetime.timedelta(seconds = second,
-                minutes = minute, hours = hour)
+            self.__incrementTime = datetime.timedelta(seconds = delay[2],
+                minutes = delay[1], hours = delay[0])
         elif ruleType == SCH_ONCE_ABS:
-            if (year != -1) and (month != -1) and (day != -1):
-                self.__startTime = datetime.datetime(year, month,
-                    day, hour, minute, second)
+            if (date[0] != 0) and (date[1] != 0) and (date[2] != 0):
+                self.__startTime = datetime.datetime(date[0], date[1], date[2],
+                    hoursBegin[0], hoursBegin[1], hoursBegin[2])
                 self.__incrementTime = None
             else:
                 self.__startTime = datetime.datetime(now.year, now.month,
-                    now.day, hour, minute, second)
+                    now.day, hoursBegin[0], hoursBegin[1], hoursBegin[2])
                 self.__incrementTime = datetime.timedelta(days = 1)
         elif ruleType == SCH_ONCE_REL:
             self.__startTime = datetime.datetime.now()
-            self.__incrementTime = datetime.timedelta(hours = hour,
-                minutes = minute, seconds = second)
+            self.__incrementTime = datetime.timedelta(hours = delay[0],
+                minutes = delay[1], seconds = delay[2])
         self.__lastExecuteTime = None
 
     # 
--------------------------------------------------------------------------
+    # Get if the task is storable or not.
+    # 
--------------------------------------------------------------------------
+    def isStorable(self):
+        """Get if the task is storable or not.
+        @return: True or False.
+        """
+        return self.__storable
+
+    # 
--------------------------------------------------------------------------
     # Get the description object of the task.
     # 
--------------------------------------------------------------------------
     def getDescription(self):
@@ -99,18 +106,36 @@
         """Get the task informations.
         @return: A dictionary.
         """
+        date = {
+            'year' : self.getDescription().getDate()[0],
+            'month' : self.getDescription().getDate()[1],
+            'day' : self.getDescription().getDate()[2],
+        }
+        hoursBegin = {
+            'hour' : self.getDescription().getHoursBegin()[0],
+            'minute' : self.getDescription().getHoursBegin()[1],
+            'second' : self.getDescription().getHoursBegin()[2],
+        }
+        hoursEnd = {
+            'hour' : self.getDescription().getHoursEnd()[0],
+            'minute' : self.getDescription().getHoursEnd()[1],
+            'second' : self.getDescription().getHoursEnd()[2],
+        }
+        delay = {
+            'hour' : self.getDescription().getDelay()[0],
+            'minute' : self.getDescription().getDelay()[1],
+            'second' : self.getDescription().getDelay()[2],
+        }
         result = {
             'id' : self.getDescription().getId(),
             'name' : self.getDescription().getName(),
             'taskDesc' : self.getDescription().toString(),
             'type' : self.getDescription().getType(),
             'weekMaskString' : self.getDescription().getWeekMaskString(),
-            'year' : self.getDescription().getYear(),
-            'month' : self.getDescription().getMonth(),
-            'day' : self.getDescription().getDay(),
-            'hour' : self.getDescription().getHour(),
-            'minute' : self.getDescription().getMinute(),
-            'second' : self.getDescription().getSecond(),
+            'date' : date,
+            'hoursBegin' : hoursBegin,
+            'hoursEnd' : hoursEnd,
+            'delay' : delay,
             'userData' : self.__data,
         }
         return result
@@ -197,6 +222,9 @@
     def execute(self, appGlobals):
         """Execute the task.
         """
+        if self.getDescription().getType() in [SCH_LOOP_ABS, SCH_LOOP_REL]:
+            if not self.getDescription()._checkNowIsInHoursRange():
+                return False
         def async():
             try:
                 command = eval(self.__description.getCommand(), appGlobals)
@@ -207,6 +235,7 @@
                 pass
         t = threading.Thread(target = async)
         t.start()
+        return True
 
     # 
--------------------------------------------------------------------------
     # Load a task.
@@ -237,23 +266,37 @@
             splitedStr = dictionary['weekMaskString'].split(",")
             if len(splitedStr) == 7:
                 for i, value in enumerate(splitedStr):
-                    if value == "1":
+                    if value == "true":
                         weekMask[i] = True
                     else:
                         weekMask[i] = False
-            hour = dictionary['hour']
-            minute = dictionary['minute']
-            second = dictionary['second']
-            year = dictionary['year']
-            month = dictionary['month']
-            day = dictionary['day']
+            date = [
+                dictionary['date']['year'],
+                dictionary['date']['month'],
+                dictionary['date']['day'],
+            ]
+            hoursBegin = [
+                dictionary['hoursBegin']['hour'],
+                dictionary['hoursBegin']['minute'],
+                dictionary['hoursBegin']['second'],
+            ]
+            hoursEnd = [
+                dictionary['hoursEnd']['hour'],
+                dictionary['hoursEnd']['minute'],
+                dictionary['hoursEnd']['second'],
+            ]
+            delay = [
+                dictionary['delay']['hour'],
+                dictionary['delay']['minute'],
+                dictionary['delay']['second'],
+            ]
             command = dictionary['command']
             arguments = dictionary['arguments']
             data = dictionary['userData']
         except:
             return None
-        task = Task(ruleType, weekMask, hour, minute, second, year, month, day,
-            command, arguments, data)
+        task = Task(ruleType, weekMask, date, hoursBegin, hoursEnd, delay,
+            command, arguments, data, True)
         task.getDescription().setId(id)
         task.getDescription().setName(name)
         return task

Modified: 
softwares_suite_v3/kysoh/tuxware/server/trunk/util/scheduler/TaskDescription.py
===================================================================
--- 
softwares_suite_v3/kysoh/tuxware/server/trunk/util/scheduler/TaskDescription.py 
    2009-04-24 13:24:03 UTC (rev 4591)
+++ 
softwares_suite_v3/kysoh/tuxware/server/trunk/util/scheduler/TaskDescription.py 
    2009-04-24 17:16:03 UTC (rev 4592)
@@ -3,6 +3,8 @@
 #    Distributed under the terms of the GNU General Public License
 #    http://www.gnu.org/copyleft/gpl.html
 
+import datetime
+
 SCH_LOOP_ABS = 0
 SCH_LOOP_REL = 1
 SCH_ONCE_ABS = 2
@@ -46,6 +48,35 @@
         return self.__parent
 
     # 
--------------------------------------------------------------------------
+    # Check if the current time is in the hours range.
+    # 
--------------------------------------------------------------------------
+    def _checkNowIsInHoursRange(self):
+        """Check if the current time is in the hours range.
+        @return: True or False.
+        """
+        now = datetime.datetime.now()
+        hB = datetime.datetime(now.year, now.month, now.day,
+            self.getHoursBegin()[0],
+            self.getHoursBegin()[1],
+            self.getHoursBegin()[2])
+        hE = datetime.datetime(now.year, now.month, now.day,
+            self.getHoursEnd()[0],
+            self.getHoursEnd()[1],
+            self.getHoursEnd()[2])
+        if (hB <= hE): # case now in [1h .. 2h]
+            if (now >= hB) and (now < hE):
+                return True
+            else:
+                return False
+        else: # case now in [2h .. 1h]
+            m = datetime.datetime(now.year, now.month, now.day, 23, 59, 59)
+            mm = datetime.datetime(now.year, now.month, now.day, 0, 0, 0)
+            if ((now >= hB) and (now <= m)) or ((now >= mm) and (now < hE)):
+                return True
+            else:
+                return False
+
+    # 
--------------------------------------------------------------------------
     # Get the task name.
     # 
--------------------------------------------------------------------------
     def getName(self):
@@ -97,22 +128,28 @@
         """Get the task configuration to string.
         @return: A string
         """
-        ymd = "%.4d/%.2d/%.2d" % (self.getYear(), self.getMonth(),
-            self.getDay())
-        hms = "%.2d:%.2d:%.2d" % (self.getHour(), self.getMinute(),
-            self.getSecond())
+        ymdDate = "%.4d/%.2d/%.2d" % (self.getDate()[0], self.getDate()[1],
+            self.getDate()[2])
+        hmsHb = "%.2d:%.2d:%.2d" % (self.getHoursBegin()[0],
+            self.getHoursBegin()[1], self.getHoursBegin()[2])
+        hmsHe = "%.2d:%.2d:%.2d" % (self.getHoursEnd()[0],
+            self.getHoursEnd()[1], self.getHoursEnd()[2])
+        hmsDelay = "%.2d:%.2d:%.2d" % (self.getDelay()[0], self.getDelay()[1],
+            self.getDelay()[2])
         if self.getType() == SCH_LOOP_REL:
-            return "[EVERY X] Delay %s" % hms
+            return "[EVERY X] Delay %s Begin %s End %s" % (hmsDelay, hmsHb,
+                hmsHe)
         elif self.getType() == SCH_LOOP_ABS:
-            return "[EVERY X FROM FULL HOUR] Delay %s" % hms
+            return "[EVERY X FROM FULL HOUR] Delay %s Begin %s End %s" % (
+                hmsDelay, hmsHb, hmsHe)
         elif self.getType() == SCH_ONCE_ABS:
-            if (self.getYear() == -1) and (self.getMonth() == -1) and \
-                (self.getDay() == -1):
-                return "[DAILY AT] Time %s" % hms
+            if (self.getDate()[0] == 0) and (self.getDate()[1] == 0) and \
+                (self.getDate()[2] == 0):
+                return "[DAILY AT] Time %s" % hmsHb
             else:
-                return "[ONCE AT] Date %s Time %s" % (ymd, hms)
-        else: # SCH_ONCE_REL
-            return "[ONCE DELAYED] Timeout %s" % hms
+                return "[ONCE AT] Date %s Time %s" % (ymdDate, hmsHb)
+        else:
+            return "[ONCE DELAYED] Timeout %s" % hmsDelay
 
     # 
--------------------------------------------------------------------------
     # Get the week mask.
@@ -135,66 +172,48 @@
             if len(result) > 0:
                 result += ","
             if b:
-                result += "1"
+                result += "true"
             else:
-                result += "0"
+                result += "false"
         return result
 
     # 
--------------------------------------------------------------------------
-    # Get the year value.
+    # Get the date values.
     # 
--------------------------------------------------------------------------
-    def getYear(self):
-        """Get the year value.
-        @return: An integer or -1.
+    def getDate(self):
+        """Get the date values.
+        @return: A list of integer.
         """
-        return self.__dictionary['year']
+        return self.__dictionary['date']
 
     # 
--------------------------------------------------------------------------
-    # Get the month value.
+    # Get the hoursBegin values.
     # 
--------------------------------------------------------------------------
-    def getMonth(self):
-        """Get the month value.
-        @return: An integer or -1.
+    def getHoursBegin(self):
+        """Get the hoursBegin values.
+        @return: A list of integer.
         """
-        return self.__dictionary['month']
+        return self.__dictionary['hoursBegin']
 
     # 
--------------------------------------------------------------------------
-    # Get the day value.
+    # Get the hoursEnd values.
     # 
--------------------------------------------------------------------------
-    def getDay(self):
-        """Get the day value.
-        @return: An integer or -1.
+    def getHoursEnd(self):
+        """Get the hoursEnd values.
+        @return: A list of integer.
         """
-        return self.__dictionary['day']
+        return self.__dictionary['hoursEnd']
 
     # 
--------------------------------------------------------------------------
-    # Get the hour value.
+    # Get the delay values.
     # 
--------------------------------------------------------------------------
-    def getHour(self):
-        """Get the hour value.
-        @return: An integer.
+    def getDelay(self):
+        """Get the delay values.
+        @return: A list of integer.
         """
-        return self.__dictionary['hour']
+        return self.__dictionary['delay']
 
     # 
--------------------------------------------------------------------------
-    # Get the minute value.
-    # 
--------------------------------------------------------------------------
-    def getMinute(self):
-        """Get the minute value.
-        @return: An integer.
-        """
-        return self.__dictionary['minute']
-
-    # 
--------------------------------------------------------------------------
-    # Get the second value.
-    # 
--------------------------------------------------------------------------
-    def getSecond(self):
-        """Get the second value.
-        @return: An integer.
-        """
-        return self.__dictionary['second']
-
-    # 
--------------------------------------------------------------------------
     # Get the command.
     # 
--------------------------------------------------------------------------
     def getCommand(self):


------------------------------------------------------------------------------
Crystal Reports &#45; New Free Runtime and 30 Day Trial
Check out the new simplified licensign option that enables unlimited
royalty&#45;free distribution of the report engine for externally facing 
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
Tux-droid-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tux-droid-svn

Reply via email to