Author: remi Date: 2009-04-07 00:38:08 +0200 (Tue, 07 Apr 2009) New Revision: 4371
Modified: software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/scheduler/Task.py Log: * added a static method to format the arguments to send to the "create task" server services Modified: software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/scheduler/Task.py =================================================================== --- software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/scheduler/Task.py 2009-04-06 22:37:01 UTC (rev 4370) +++ software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/scheduler/Task.py 2009-04-06 22:38:08 UTC (rev 4371) @@ -4,7 +4,7 @@ # http://www.gnu.org/copyleft/gpl.html from tuxisalive.api.base.ApiBaseChildResource import ApiBaseChildResource - +from const.ConstTask import * from TaskDescription import * # ------------------------------------------------------------------------------ @@ -77,3 +77,95 @@ } cmd = "scheduler/remove_task?" return self._sendCommandBooleanResult(cmd, argsToSend) + + # -------------------------------------------------------------------------- + # Format the arguments to pass to a "create task" requests. + # -------------------------------------------------------------------------- + def formatRequestArguments(tType = "ONCE DELAYED", name = None, + weekMask = [True, True, True, True, True, True, True], date = None, + time = "00:00:10"): + """Format the arguments to pass to a "create task" requests. + @param tType: <EVERY X|EVERY X FROM FULL HOUR|DAILY AT|ONCE AT| + ONCE DELAYED> + Default value is "ONCE DELAYED". + @param name: Task name. + Default value is "Unamed task". + @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: A dictionary or None. + """ + # Check the validity of the task type + if tType not in TASK_TYPE_NAMES: + print "Invalid task type : (%s) -> <EVERY X|EVERY X FROM FULL HOUR|DAILY AT|ONCE AT|ONCE DELAYED>" % tType + return None + if name == None: + taskName = "Unamed task" + # Check and format the week mask string + weekMaskString = "" + if len(weekMask) != 7: + print "Invalid week mask : (%s) -> [True, True, True, True, True, True, True]" % str(weekMask) + return None + for b in weekMask: + if type(b) != type(True): + print "Invalid week mask element : (%s) -> Boolean" % str(b) + return None + if len(weekMaskString) > 0: + weekMaskString += "," + if b: + weekMaskString += "1" + else: + weekMaskString += "0" + weekMaskString = '"%s"' % weekMaskString + # Check and format the task date + if date == None: + year = -1 + month = -1 + day = -1 + else: + if type(date) != type(""): + print "Invalid task date format : (%s) -> YYYY/MM/DD" % str(date) + return None + splDate = date.split("/") + if len(splDate) != 3: + print "Invalid task date format : (%s) -> YYYY/MM/DD" % date + return None + try: + year = int(splDate[0]) + month = int(splDate[1]) + day = int(splDate[2]) + except: + print "Invalid task date format : (%s) -> YYYY/MM/DD" % date + return None + # Check and format the task time + if type(time) != type(""): + print "Invalid task time format : (%s) -> HH:MM:SS" % str(time) + splTime = time.split(":") + if len(splTime) != 3: + print "Invalid task time format : (%s) -> HH:MM:SS" % time + return None + try: + hour = int(splTime[0]) + minute = int(splTime[1]) + second = int(splTime[2]) + except: + print "Invalid task time format : (%s) -> HH:MM:SS" % time + return None + # Create the result dictionary + result = { + 'task_type' : tType, + 'task_name' : name, + 'week_mask' : weekMaskString, + 'hour' : hour, + 'minute' : minute, + 'second' : second, + 'year' : year, + 'month' : month, + 'day' : day, + } + return result + + formatRequestArguments = staticmethod(formatRequestArguments) ------------------------------------------------------------------------------ This SF.net email is sponsored by: High Quality Requirements in a Collaborative Environment. Download a free trial of Rational Requirements Composer Now! http://p.sf.net/sfu/www-ibm-com _______________________________________________ Tux-droid-svn mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/tux-droid-svn
